]> Untitled Git - lemmy.git/blob - crates/db_schema/src/aggregates/structs.rs
Add cargo feature for building lemmy_api_common with mininum deps (#2243)
[lemmy.git] / crates / db_schema / src / aggregates / structs.rs
1 use crate::newtypes::{CommentId, CommunityId, PersonId, PostId};
2 use serde::{Deserialize, Serialize};
3
4 #[cfg(feature = "full")]
5 use crate::schema::{
6   comment_aggregates,
7   community_aggregates,
8   person_aggregates,
9   post_aggregates,
10   site_aggregates,
11 };
12
13 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
14 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
15 #[cfg_attr(feature = "full", table_name = "comment_aggregates")]
16 pub struct CommentAggregates {
17   pub id: i32,
18   pub comment_id: CommentId,
19   pub score: i64,
20   pub upvotes: i64,
21   pub downvotes: i64,
22   pub published: chrono::NaiveDateTime,
23 }
24
25 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
26 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
27 #[cfg_attr(feature = "full", table_name = "community_aggregates")]
28 pub struct CommunityAggregates {
29   pub id: i32,
30   pub community_id: CommunityId,
31   pub subscribers: i64,
32   pub posts: i64,
33   pub comments: i64,
34   pub published: chrono::NaiveDateTime,
35   pub users_active_day: i64,
36   pub users_active_week: i64,
37   pub users_active_month: i64,
38   pub users_active_half_year: i64,
39 }
40
41 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone, Default)]
42 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
43 #[cfg_attr(feature = "full", table_name = "person_aggregates")]
44 pub struct PersonAggregates {
45   pub id: i32,
46   pub person_id: PersonId,
47   pub post_count: i64,
48   pub post_score: i64,
49   pub comment_count: i64,
50   pub comment_score: i64,
51 }
52
53 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
54 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
55 #[cfg_attr(feature = "full", table_name = "post_aggregates")]
56 pub struct PostAggregates {
57   pub id: i32,
58   pub post_id: PostId,
59   pub comments: i64,
60   pub score: i64,
61   pub upvotes: i64,
62   pub downvotes: i64,
63   pub stickied: bool,
64   pub published: chrono::NaiveDateTime,
65   pub newest_comment_time_necro: chrono::NaiveDateTime, // A newest comment time, limited to 2 days, to prevent necrobumping
66   pub newest_comment_time: chrono::NaiveDateTime,
67 }
68
69 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
70 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
71 #[cfg_attr(feature = "full", table_name = "site_aggregates")]
72 pub struct SiteAggregates {
73   pub id: i32,
74   pub site_id: i32,
75   pub users: i64,
76   pub posts: i64,
77   pub comments: i64,
78   pub communities: i64,
79   pub users_active_day: i64,
80   pub users_active_week: i64,
81   pub users_active_month: i64,
82   pub users_active_half_year: i64,
83 }