2 newtypes::{CommunityId, DbUrl, PersonId},
5 use diesel::result::Error;
12 async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error>
15 async fn read(pool: &DbPool, id: Self::IdType) -> Result<Self, Error>
18 /// 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.
19 async fn update(pool: &DbPool, id: Self::IdType, form: &Self::UpdateForm) -> Result<Self, Error>
22 async fn delete(_pool: &DbPool, _id: Self::IdType) -> Result<usize, Error>
27 async { Err(Error::NotFound) }.await
32 pub trait Followable {
34 async fn follow(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
37 async fn follow_accepted(
39 community_id: CommunityId,
41 ) -> Result<Self, Error>
44 async fn unfollow(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
47 async fn has_local_followers(pool: &DbPool, community_id: CommunityId) -> Result<bool, Error>;
53 async fn join(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
56 async fn leave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
65 async fn like(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
71 item_id: Self::IdType,
72 ) -> Result<usize, Error>
80 async fn ban(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
83 async fn unban(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
91 async fn save(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
94 async fn unsave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
100 pub trait Blockable {
102 async fn block(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
105 async fn unblock(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
113 async fn mark_as_read(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
116 async fn mark_as_unread(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
122 pub trait Reportable {
125 async fn report(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
130 report_id: Self::IdType,
131 resolver_id: PersonId,
132 ) -> Result<usize, Error>
137 report_id: Self::IdType,
138 resolver_id: PersonId,
139 ) -> Result<usize, Error>
144 // TODO these should be removed, there should be another way to do this
145 pub trait DeleteableOrRemoveable {
146 fn blank_out_deleted_or_removed_info(self) -> Self;
151 fn safe_columns_tuple() -> Self::SafeColumns;
154 pub trait ToSafeSettings {
155 type SafeSettingsColumns;
156 fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns;
159 pub trait ViewToVec {
161 fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
167 pub trait ApubActor {
168 // TODO: this should be in a trait ApubObject (and implemented for Post, Comment, PrivateMessage as well)
169 async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error>
172 /// - actor_name is the name of the community or user to read.
173 /// - include_deleted, if true, will return communities or users that were deleted/removed
174 async fn read_from_name(
177 include_deleted: bool,
178 ) -> Result<Self, Error>
181 async fn read_from_name_and_domain(
184 protocol_domain: &str,
185 ) -> Result<Self, Error>