1 use crate::newtypes::{CommunityId, DbUrl, PersonId};
2 use diesel::{result::Error, PgConnection};
7 fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
10 fn read(conn: &PgConnection, id: Self::IdType) -> Result<Self, Error>
13 fn update(conn: &PgConnection, id: Self::IdType, form: &Self::Form) -> Result<Self, Error>
16 fn delete(_conn: &PgConnection, _id: Self::IdType) -> Result<usize, Error>
24 pub trait Followable {
26 fn follow(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
31 community_id: CommunityId,
33 ) -> Result<Self, Error>
36 fn unfollow(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
39 fn has_local_followers(conn: &PgConnection, community_id: CommunityId) -> Result<bool, Error>;
44 fn join(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
47 fn leave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
55 fn like(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
61 item_id: Self::IdType,
62 ) -> Result<usize, Error>
69 fn ban(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
72 fn unban(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
79 fn save(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
82 fn unsave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
89 fn block(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
92 fn unblock(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
99 fn mark_as_read(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
102 fn mark_as_unread(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
107 pub trait Reportable {
110 fn report(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
115 report_id: Self::IdType,
116 resolver_id: PersonId,
117 ) -> Result<usize, Error>
122 report_id: Self::IdType,
123 resolver_id: PersonId,
124 ) -> Result<usize, Error>
129 pub trait DeleteableOrRemoveable {
130 fn blank_out_deleted_or_removed_info(self) -> Self;
133 pub trait MaybeOptional<T> {
134 fn get_optional(self) -> Option<T>;
137 impl<T> MaybeOptional<T> for T {
138 fn get_optional(self) -> Option<T> {
143 impl<T> MaybeOptional<T> for Option<T> {
144 fn get_optional(self) -> Option<T> {
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>
166 pub trait ApubActor {
167 // TODO: this should be in a trait ApubObject (and implemented for Post, Comment, PrivateMessage as well)
168 fn read_from_apub_id(conn: &PgConnection, 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
176 include_deleted: bool,
177 ) -> Result<Self, Error>
180 fn read_from_name_and_domain(
183 protocol_domain: &str,
184 ) -> Result<Self, Error>