mirror of https://github.com/LemmyNet/lemmy
Starting on siteview.
parent
b587e147b0
commit
ca7224c086
@ -0,0 +1 @@
|
||||
pub mod site_view;
|
@ -0,0 +1,26 @@
|
||||
use crate::{
|
||||
schema::{site as site_table, user_},
|
||||
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> {
|
||||
let site_join = site_table::table
|
||||
.inner_join(user_::table)
|
||||
.first::<(Site, User_)>(conn)?;
|
||||
|
||||
Ok(SiteView {
|
||||
site: site_join.0,
|
||||
creator: site_join.1.to_safe(),
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
-- This file should undo anything in `up.sql`
|
@ -0,0 +1 @@
|
||||
-- Your SQL goes here
|
Loading…
Reference in New Issue