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>
52 async fn join(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
55 async fn leave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
64 async fn like(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
70 item_id: Self::IdType,
71 ) -> Result<usize, Error>
79 async fn ban(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
82 async fn unban(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
90 async fn save(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
93 async fn unsave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
101 async fn block(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
104 async fn unblock(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
112 async fn mark_as_read(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
115 async fn mark_as_unread(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
121 pub trait Reportable {
124 async fn report(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
129 report_id: Self::IdType,
130 resolver_id: PersonId,
131 ) -> Result<usize, Error>
136 report_id: Self::IdType,
137 resolver_id: PersonId,
138 ) -> Result<usize, Error>
143 // TODO these should be removed, there should be another way to do this
144 pub trait DeleteableOrRemoveable {
145 fn blank_out_deleted_or_removed_info(self) -> Self;
150 fn safe_columns_tuple() -> Self::SafeColumns;
153 pub trait ToSafeSettings {
154 type SafeSettingsColumns;
155 fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns;
158 pub trait ViewToVec {
160 fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
166 pub trait ApubActor {
167 // TODO: this should be in a trait ApubObject (and implemented for Post, Comment, PrivateMessage as well)
168 async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error>
171 /// - actor_name is the name of the community or user to read.
172 /// - include_deleted, if true, will return communities or users that were deleted/removed
173 async fn read_from_name(
176 include_deleted: bool,
177 ) -> Result<Self, Error>
180 async fn read_from_name_and_domain(
183 protocol_domain: &str,
184 ) -> Result<Self, Error>