-use diesel::{result::Error, *};
+use crate::structs::SiteView;
+use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
+use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
- aggregates::site_aggregates::SiteAggregates,
- schema::{person, site, site_aggregates},
- source::{
- person::{Person, PersonSafe},
- site::Site,
- },
- traits::ToSafe,
+ aggregates::structs::SiteAggregates,
+ schema::{local_site, local_site_rate_limit, site, site_aggregates},
+ source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::Site},
+ utils::{get_conn, DbPool},
};
-use serde::{Deserialize, Serialize};
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-pub struct SiteView {
- pub site: Site,
- pub creator: PersonSafe,
- pub counts: SiteAggregates,
-}
impl SiteView {
- pub fn read(conn: &PgConnection) -> Result<Self, Error> {
- let (site, creator, counts) = site::table
- .inner_join(person::table)
+ pub async fn read_local(pool: &mut DbPool<'_>) -> Result<Self, Error> {
+ let conn = &mut get_conn(pool).await?;
+ let (mut site, local_site, local_site_rate_limit, counts) = site::table
+ .inner_join(local_site::table)
+ .inner_join(
+ local_site_rate_limit::table.on(local_site::id.eq(local_site_rate_limit::local_site_id)),
+ )
.inner_join(site_aggregates::table)
.select((
site::all_columns,
- Person::safe_columns_tuple(),
+ local_site::all_columns,
+ local_site_rate_limit::all_columns,
site_aggregates::all_columns,
))
- .first::<(Site, PersonSafe, SiteAggregates)>(conn)?;
+ .first::<(Site, LocalSite, LocalSiteRateLimit, SiteAggregates)>(conn)
+ .await?;
+ site.private_key = None;
Ok(SiteView {
site,
- creator,
+ local_site,
+ local_site_rate_limit,
counts,
})
}