]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/site.rs
Automatically resolve report when post/comment is removed (#3850)
[lemmy.git] / crates / db_schema / src / source / site.rs
1 use crate::newtypes::{DbUrl, InstanceId, SiteId};
2 #[cfg(feature = "full")]
3 use crate::schema::site;
4 use chrono::NaiveDateTime;
5 use serde::{Deserialize, Serialize};
6 use serde_with::skip_serializing_none;
7 #[cfg(feature = "full")]
8 use ts_rs::TS;
9 use typed_builder::TypedBuilder;
10
11 #[skip_serializing_none]
12 #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
13 #[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))]
14 #[cfg_attr(feature = "full", diesel(table_name = site))]
15 #[cfg_attr(feature = "full", ts(export))]
16 /// The site.
17 pub struct Site {
18   pub id: SiteId,
19   pub name: String,
20   /// A sidebar for the site in markdown.
21   pub sidebar: Option<String>,
22   pub published: NaiveDateTime,
23   pub updated: Option<NaiveDateTime>,
24   /// An icon URL.
25   pub icon: Option<DbUrl>,
26   /// A banner url.
27   pub banner: Option<DbUrl>,
28   /// A shorter, one-line description of the site.
29   pub description: Option<String>,
30   /// The federated actor_id.
31   pub actor_id: DbUrl,
32   /// The time the site was last refreshed.
33   pub last_refreshed_at: NaiveDateTime,
34   /// The site inbox
35   pub inbox_url: DbUrl,
36   pub private_key: Option<String>,
37   pub public_key: String,
38   pub instance_id: InstanceId,
39 }
40
41 #[derive(Clone, TypedBuilder)]
42 #[builder(field_defaults(default))]
43 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
44 #[cfg_attr(feature = "full", diesel(table_name = site))]
45 pub struct SiteInsertForm {
46   #[builder(!default)]
47   pub name: String,
48   pub sidebar: Option<String>,
49   pub updated: Option<NaiveDateTime>,
50   pub icon: Option<DbUrl>,
51   pub banner: Option<DbUrl>,
52   pub description: Option<String>,
53   pub actor_id: Option<DbUrl>,
54   pub last_refreshed_at: Option<NaiveDateTime>,
55   pub inbox_url: Option<DbUrl>,
56   pub private_key: Option<String>,
57   pub public_key: Option<String>,
58   #[builder(!default)]
59   pub instance_id: InstanceId,
60 }
61
62 #[derive(Clone, Default)]
63 #[cfg_attr(feature = "full", derive(AsChangeset))]
64 #[cfg_attr(feature = "full", diesel(table_name = site))]
65 pub struct SiteUpdateForm {
66   pub name: Option<String>,
67   pub sidebar: Option<Option<String>>,
68   pub updated: Option<Option<NaiveDateTime>>,
69   // when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
70   pub icon: Option<Option<DbUrl>>,
71   pub banner: Option<Option<DbUrl>>,
72   pub description: Option<Option<String>>,
73   pub actor_id: Option<DbUrl>,
74   pub last_refreshed_at: Option<NaiveDateTime>,
75   pub inbox_url: Option<DbUrl>,
76   pub private_key: Option<Option<String>>,
77   pub public_key: Option<String>,
78 }