2020-12-02 19:32:47 +00:00
|
|
|
use crate::{
|
2020-12-13 17:04:42 +00:00
|
|
|
source::{
|
|
|
|
site::Site,
|
|
|
|
user::{UserSafe, User_},
|
|
|
|
},
|
2020-12-05 04:18:30 +00:00
|
|
|
ToSafe,
|
2020-12-02 19:32:47 +00:00
|
|
|
};
|
|
|
|
use diesel::{result::Error, *};
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::{site, 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,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SiteView {
|
|
|
|
pub fn read(conn: &PgConnection) -> Result<Self, Error> {
|
2020-12-03 18:39:56 +00:00
|
|
|
let (site, creator) = site::table
|
2020-12-02 19:32:47 +00:00
|
|
|
.inner_join(user_::table)
|
2020-12-05 04:18:30 +00:00
|
|
|
.select((site::all_columns, User_::safe_columns_tuple()))
|
|
|
|
.first::<(Site, UserSafe)>(conn)?;
|
2020-12-02 19:32:47 +00:00
|
|
|
|
2020-12-05 04:18:30 +00:00
|
|
|
Ok(SiteView { site, creator })
|
2020-12-02 19:32:47 +00:00
|
|
|
}
|
|
|
|
}
|