]> Untitled Git - lemmy.git/blob - crates/db_schema/src/aggregates/structs.rs
08d5e9144099ef22e121df7489e3d11b78f5bb7b
[lemmy.git] / crates / db_schema / src / aggregates / structs.rs
1 use crate::newtypes::{CommentId, CommunityId, PersonId, PostId, SiteId};
2 #[cfg(feature = "full")]
3 use crate::schema::{
4   comment_aggregates,
5   community_aggregates,
6   person_aggregates,
7   person_post_aggregates,
8   post_aggregates,
9   site_aggregates,
10 };
11 use serde::{Deserialize, Serialize};
12
13 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
14 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
15 #[cfg_attr(feature = "full", diesel(table_name = comment_aggregates))]
16 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
17 pub struct CommentAggregates {
18   pub id: i32,
19   pub comment_id: CommentId,
20   pub score: i64,
21   pub upvotes: i64,
22   pub downvotes: i64,
23   pub published: chrono::NaiveDateTime,
24   pub child_count: i32,
25 }
26
27 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
28 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
29 #[cfg_attr(feature = "full", diesel(table_name = community_aggregates))]
30 #[cfg_attr(
31   feature = "full",
32   diesel(belongs_to(crate::source::community::Community))
33 )]
34 pub struct CommunityAggregates {
35   pub id: i32,
36   pub community_id: CommunityId,
37   pub subscribers: i64,
38   pub posts: i64,
39   pub comments: i64,
40   pub published: chrono::NaiveDateTime,
41   pub users_active_day: i64,
42   pub users_active_week: i64,
43   pub users_active_month: i64,
44   pub users_active_half_year: i64,
45 }
46
47 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
48 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
49 #[cfg_attr(feature = "full", diesel(table_name = person_aggregates))]
50 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
51 pub struct PersonAggregates {
52   pub id: i32,
53   pub person_id: PersonId,
54   pub post_count: i64,
55   pub post_score: i64,
56   pub comment_count: i64,
57   pub comment_score: i64,
58 }
59
60 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
61 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
62 #[cfg_attr(feature = "full", diesel(table_name = post_aggregates))]
63 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
64 pub struct PostAggregates {
65   pub id: i32,
66   pub post_id: PostId,
67   pub comments: i64,
68   pub score: i64,
69   pub upvotes: i64,
70   pub downvotes: i64,
71   pub stickied: bool,
72   pub published: chrono::NaiveDateTime,
73   pub newest_comment_time_necro: chrono::NaiveDateTime, // A newest comment time, limited to 2 days, to prevent necrobumping
74   pub newest_comment_time: chrono::NaiveDateTime,
75 }
76
77 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
78 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
79 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
80 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
81 pub struct PersonPostAggregates {
82   pub id: i32,
83   pub person_id: PersonId,
84   pub post_id: PostId,
85   pub read_comments: i64,
86   pub published: chrono::NaiveDateTime,
87 }
88
89 #[derive(Clone, Default)]
90 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
91 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
92 pub struct PersonPostAggregatesForm {
93   pub person_id: PersonId,
94   pub post_id: PostId,
95   pub read_comments: i64,
96   pub published: Option<chrono::NaiveDateTime>,
97 }
98
99 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
100 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
101 #[cfg_attr(feature = "full", diesel(table_name = site_aggregates))]
102 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
103 pub struct SiteAggregates {
104   pub id: i32,
105   pub site_id: SiteId,
106   pub users: i64,
107   pub posts: i64,
108   pub comments: i64,
109   pub communities: i64,
110   pub users_active_day: i64,
111   pub users_active_week: i64,
112   pub users_active_month: i64,
113   pub users_active_half_year: i64,
114 }