1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use crate::newtypes::{CommunityId, PersonId};
use diesel::{result::Error, PgConnection};

pub trait Crud {
  type Form;
  type IdType;
  fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn read(conn: &PgConnection, id: Self::IdType) -> Result<Self, Error>
  where
    Self: Sized;
  fn update(conn: &PgConnection, id: Self::IdType, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn delete(_conn: &PgConnection, _id: Self::IdType) -> Result<usize, Error>
  where
    Self: Sized,
  {
    unimplemented!()
  }
}

pub trait Followable {
  type Form;
  fn follow(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn follow_accepted(
    conn: &PgConnection,
    community_id: CommunityId,
    person_id: PersonId,
  ) -> Result<Self, Error>
  where
    Self: Sized;
  fn unfollow(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
  where
    Self: Sized;
  fn has_local_followers(conn: &PgConnection, community_id: CommunityId) -> Result<bool, Error>;
}

pub trait Joinable {
  type Form;
  fn join(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn leave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
  where
    Self: Sized;
}

pub trait Likeable {
  type Form;
  type IdType;
  fn like(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn remove(
    conn: &PgConnection,
    person_id: PersonId,
    item_id: Self::IdType,
  ) -> Result<usize, Error>
  where
    Self: Sized;
}

pub trait Bannable {
  type Form;
  fn ban(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn unban(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
  where
    Self: Sized;
}

pub trait Saveable {
  type Form;
  fn save(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn unsave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
  where
    Self: Sized;
}

pub trait Blockable {
  type Form;
  fn block(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn unblock(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
  where
    Self: Sized;
}

pub trait Readable {
  type Form;
  fn mark_as_read(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn mark_as_unread(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
  where
    Self: Sized;
}

pub trait Reportable {
  type Form;
  type IdType;
  fn report(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
  where
    Self: Sized;
  fn resolve(
    conn: &PgConnection,
    report_id: Self::IdType,
    resolver_id: PersonId,
  ) -> Result<usize, Error>
  where
    Self: Sized;
  fn unresolve(
    conn: &PgConnection,
    report_id: Self::IdType,
    resolver_id: PersonId,
  ) -> Result<usize, Error>
  where
    Self: Sized;
}

pub trait DeleteableOrRemoveable {
  fn blank_out_deleted_or_removed_info(self) -> Self;
}

pub trait MaybeOptional<T> {
  fn get_optional(self) -> Option<T>;
}

impl<T> MaybeOptional<T> for T {
  fn get_optional(self) -> Option<T> {
    Some(self)
  }
}

impl<T> MaybeOptional<T> for Option<T> {
  fn get_optional(self) -> Option<T> {
    self
  }
}

pub trait ToSafe {
  type SafeColumns;
  fn safe_columns_tuple() -> Self::SafeColumns;
}

pub trait ToSafeSettings {
  type SafeSettingsColumns;
  fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns;
}

pub trait ViewToVec {
  type DbTuple;
  fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
  where
    Self: Sized;
}