1 use crate::{schema::site, Crud};
2 use diesel::{dsl::*, result::Error, *};
3 use serde::{Deserialize, Serialize};
5 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
10 pub description: Option<String>,
12 pub published: chrono::NaiveDateTime,
13 pub updated: Option<chrono::NaiveDateTime>,
14 pub enable_downvotes: bool,
15 pub open_registration: bool,
16 pub enable_nsfw: bool,
19 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
20 #[table_name = "site"]
23 pub description: Option<String>,
25 pub updated: Option<chrono::NaiveDateTime>,
26 pub enable_downvotes: bool,
27 pub open_registration: bool,
28 pub enable_nsfw: bool,
31 impl Crud<SiteForm> for Site {
32 fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
33 use crate::schema::site::dsl::*;
34 site.first::<Self>(conn)
37 fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
38 use crate::schema::site::dsl::*;
39 diesel::delete(site.find(site_id)).execute(conn)
42 fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
43 use crate::schema::site::dsl::*;
44 insert_into(site).values(new_site).get_result::<Self>(conn)
47 fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
48 use crate::schema::site::dsl::*;
49 diesel::update(site.find(site_id))
51 .get_result::<Self>(conn)