2020-12-21 14:28:20 +00:00
|
|
|
use crate::{aggregates::site_aggregates::SiteAggregates, ToSafe};
|
2020-12-02 19:32:47 +00:00
|
|
|
use diesel::{result::Error, *};
|
2020-12-18 18:38:32 +00:00
|
|
|
use lemmy_db_schema::{
|
2020-12-20 01:10:47 +00:00
|
|
|
schema::{site, site_aggregates, user_},
|
2020-12-13 17:04:42 +00:00
|
|
|
source::{
|
|
|
|
site::Site,
|
|
|
|
user::{UserSafe, User_},
|
|
|
|
},
|
2020-12-02 19:32:47 +00:00
|
|
|
};
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Clone)]
|
|
|
|
pub struct SiteView {
|
|
|
|
pub site: Site,
|
|
|
|
pub creator: UserSafe,
|
2020-12-20 01:10:47 +00:00
|
|
|
pub counts: SiteAggregates,
|
2020-12-02 19:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SiteView {
|
|
|
|
pub fn read(conn: &PgConnection) -> Result<Self, Error> {
|
2020-12-20 01:10:47 +00:00
|
|
|
let (site, creator, counts) = site::table
|
2020-12-02 19:32:47 +00:00
|
|
|
.inner_join(user_::table)
|
2020-12-20 01:10:47 +00:00
|
|
|
.inner_join(site_aggregates::table)
|
|
|
|
.select((
|
|
|
|
site::all_columns,
|
|
|
|
User_::safe_columns_tuple(),
|
|
|
|
site_aggregates::all_columns,
|
|
|
|
))
|
|
|
|
.first::<(Site, UserSafe, SiteAggregates)>(conn)?;
|
2020-12-02 19:32:47 +00:00
|
|
|
|
2020-12-20 01:10:47 +00:00
|
|
|
Ok(SiteView {
|
|
|
|
site,
|
|
|
|
creator,
|
|
|
|
counts,
|
|
|
|
})
|
2020-12-02 19:32:47 +00:00
|
|
|
}
|
|
|
|
}
|