]> Untitled Git - lemmy.git/blob - crates/db_schema/src/lib.rs
Feature add hours as sorting options backend (#3161)
[lemmy.git] / crates / db_schema / src / lib.rs
1 #![recursion_limit = "256"]
2
3 #[cfg(feature = "full")]
4 #[macro_use]
5 extern crate diesel;
6 #[cfg(feature = "full")]
7 #[macro_use]
8 extern crate diesel_derive_newtype;
9
10 #[cfg(feature = "full")]
11 #[macro_use]
12 extern crate diesel_derive_enum;
13
14 // this is used in tests
15 #[cfg(feature = "full")]
16 #[macro_use]
17 extern crate diesel_migrations;
18
19 #[cfg(feature = "full")]
20 #[macro_use]
21 extern crate async_trait;
22
23 pub mod aggregates;
24 #[cfg(feature = "full")]
25 pub mod impls;
26 pub mod newtypes;
27 #[cfg(feature = "full")]
28 #[rustfmt::skip]
29 pub mod schema;
30 pub mod source;
31 #[cfg(feature = "full")]
32 pub mod traits;
33 #[cfg(feature = "full")]
34 pub mod utils;
35
36 use serde::{Deserialize, Serialize};
37 use strum_macros::{Display, EnumString};
38 #[cfg(feature = "full")]
39 use ts_rs::TS;
40
41 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
42 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
43 #[cfg_attr(
44   feature = "full",
45   ExistingTypePath = "crate::schema::sql_types::SortTypeEnum"
46 )]
47 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
48 #[cfg_attr(feature = "full", ts(export))]
49 /// The post sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
50 pub enum SortType {
51   Active,
52   Hot,
53   New,
54   Old,
55   TopDay,
56   TopWeek,
57   TopMonth,
58   TopYear,
59   TopAll,
60   MostComments,
61   NewComments,
62   TopHour,
63   TopSixHour,
64   TopTwelveHour,
65 }
66
67 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
68 #[cfg_attr(feature = "full", derive(TS))]
69 #[cfg_attr(feature = "full", ts(export))]
70 /// The comment sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
71 pub enum CommentSortType {
72   Hot,
73   Top,
74   New,
75   Old,
76 }
77
78 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
79 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
80 #[cfg_attr(
81   feature = "full",
82   ExistingTypePath = "crate::schema::sql_types::ListingTypeEnum"
83 )]
84 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
85 #[cfg_attr(feature = "full", ts(export))]
86 /// A listing type for post and comment list fetches.
87 pub enum ListingType {
88   /// Content from your own site, as well as all connected / federated sites.
89   All,
90   /// Content from your site only.
91   Local,
92   /// Content only from communities you've subscribed to.
93   Subscribed,
94 }
95
96 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
97 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
98 #[cfg_attr(
99   feature = "full",
100   ExistingTypePath = "crate::schema::sql_types::RegistrationModeEnum"
101 )]
102 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
103 #[cfg_attr(feature = "full", ts(export))]
104 /// The registration mode for your site. Determines what happens after a user signs up.
105 pub enum RegistrationMode {
106   /// Closed to public.
107   Closed,
108   /// Open, but pending approval of a registration application.
109   RequireApplication,
110   /// Open to all.
111   Open,
112 }
113
114 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
115 #[cfg_attr(feature = "full", derive(TS))]
116 #[cfg_attr(feature = "full", ts(export))]
117 /// The type of content returned from a search.
118 pub enum SearchType {
119   All,
120   Comments,
121   Posts,
122   Communities,
123   Users,
124   Url,
125 }
126
127 #[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)]
128 #[cfg_attr(feature = "full", derive(TS))]
129 #[cfg_attr(feature = "full", ts(export))]
130 /// A type / status for a community subscribe.
131 pub enum SubscribedType {
132   Subscribed,
133   NotSubscribed,
134   Pending,
135 }
136
137 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
138 #[cfg_attr(feature = "full", derive(TS))]
139 #[cfg_attr(feature = "full", ts(export))]
140 /// A list of possible types for the various modlog actions.
141 pub enum ModlogActionType {
142   All,
143   ModRemovePost,
144   ModLockPost,
145   ModFeaturePost,
146   ModRemoveComment,
147   ModRemoveCommunity,
148   ModBanFromCommunity,
149   ModAddCommunity,
150   ModTransferCommunity,
151   ModAdd,
152   ModBan,
153   ModHideCommunity,
154   AdminPurgePerson,
155   AdminPurgeCommunity,
156   AdminPurgePost,
157   AdminPurgeComment,
158 }
159
160 #[derive(
161   EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq,
162 )]
163 #[cfg_attr(feature = "full", derive(TS))]
164 #[cfg_attr(feature = "full", ts(export))]
165 /// The feature type for a post.
166 pub enum PostFeatureType {
167   #[default]
168   /// Features to the top of your site.
169   Local,
170   /// Features to the top of the community.
171   Community,
172 }