]> Untitled Git - lemmy.git/blob - crates/db_views_actor/src/structs.rs
Use same table join code for both read and list functions (#3663)
[lemmy.git] / crates / db_views_actor / src / structs.rs
1 use lemmy_db_schema::{
2   aggregates::structs::{CommentAggregates, CommunityAggregates, PersonAggregates},
3   source::{
4     comment::Comment,
5     comment_reply::CommentReply,
6     community::Community,
7     person::Person,
8     person_mention::PersonMention,
9     post::Post,
10   },
11   SubscribedType,
12 };
13 use serde::{Deserialize, Serialize};
14 use serde_with::skip_serializing_none;
15 #[cfg(feature = "full")]
16 use ts_rs::TS;
17
18 #[derive(Debug, Serialize, Deserialize, Clone)]
19 #[cfg_attr(feature = "full", derive(TS))]
20 #[cfg_attr(feature = "full", ts(export))]
21 /// A community block.
22 pub struct CommunityBlockView {
23   pub person: Person,
24   pub community: Community,
25 }
26
27 #[derive(Debug, Serialize, Deserialize, Clone)]
28 #[cfg_attr(feature = "full", derive(TS))]
29 #[cfg_attr(feature = "full", ts(export))]
30 /// A community follower.
31 pub struct CommunityFollowerView {
32   pub community: Community,
33   pub follower: Person,
34 }
35
36 #[derive(Debug, Serialize, Deserialize, Clone)]
37 #[cfg_attr(feature = "full", derive(TS))]
38 #[cfg_attr(feature = "full", ts(export))]
39 /// A community moderator.
40 pub struct CommunityModeratorView {
41   pub community: Community,
42   pub moderator: Person,
43 }
44
45 #[derive(Debug, Serialize, Deserialize, Clone)]
46 /// A community person ban.
47 pub struct CommunityPersonBanView {
48   pub community: Community,
49   pub person: Person,
50 }
51
52 #[derive(Debug, Serialize, Deserialize, Clone)]
53 #[cfg_attr(feature = "full", derive(TS))]
54 #[cfg_attr(feature = "full", ts(export))]
55 /// A community view.
56 pub struct CommunityView {
57   pub community: Community,
58   pub subscribed: SubscribedType,
59   pub blocked: bool,
60   pub counts: CommunityAggregates,
61 }
62
63 #[derive(Debug, Serialize, Deserialize, Clone)]
64 #[cfg_attr(feature = "full", derive(TS))]
65 #[cfg_attr(feature = "full", ts(export))]
66 /// A person block.
67 pub struct PersonBlockView {
68   pub person: Person,
69   pub target: Person,
70 }
71
72 #[skip_serializing_none]
73 #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
74 #[cfg_attr(feature = "full", derive(TS))]
75 #[cfg_attr(feature = "full", ts(export))]
76 /// A person mention view.
77 pub struct PersonMentionView {
78   pub person_mention: PersonMention,
79   pub comment: Comment,
80   pub creator: Person,
81   pub post: Post,
82   pub community: Community,
83   pub recipient: Person,
84   pub counts: CommentAggregates,
85   pub creator_banned_from_community: bool,
86   pub subscribed: SubscribedType,
87   pub saved: bool,
88   pub creator_blocked: bool,
89   pub my_vote: Option<i16>,
90 }
91
92 #[skip_serializing_none]
93 #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
94 #[cfg_attr(feature = "full", derive(TS))]
95 #[cfg_attr(feature = "full", ts(export))]
96 /// A comment reply view.
97 pub struct CommentReplyView {
98   pub comment_reply: CommentReply,
99   pub comment: Comment,
100   pub creator: Person,
101   pub post: Post,
102   pub community: Community,
103   pub recipient: Person,
104   pub counts: CommentAggregates,
105   pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan
106   pub subscribed: SubscribedType,          // Left join to CommunityFollower
107   pub saved: bool,                         // Left join to CommentSaved
108   pub creator_blocked: bool,               // Left join to PersonBlock
109   pub my_vote: Option<i16>,                // Left join to CommentLike
110 }
111
112 #[derive(Debug, Serialize, Deserialize, Clone)]
113 #[cfg_attr(feature = "full", derive(TS))]
114 #[cfg_attr(feature = "full", ts(export))]
115 /// A person view.
116 pub struct PersonView {
117   pub person: Person,
118   pub counts: PersonAggregates,
119 }