lemmy/lemmy_db/src/views/site_view.rs

27 lines
502 B
Rust
Raw Normal View History

2020-12-02 19:32:47 +00:00
use crate::{
2020-12-03 18:39:56 +00:00
schema::{site, user_},
2020-12-02 19:32:47 +00:00
site::Site,
user::{UserSafe, User_},
};
use diesel::{result::Error, *};
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)
.first::<(Site, User_)>(conn)?;
Ok(SiteView {
2020-12-03 18:39:56 +00:00
site,
creator: creator.to_safe(),
2020-12-02 19:32:47 +00:00
})
}
}