]> Untitled Git - lemmy.git/blob - server/src/api/mod.rs
Adding permanently delete account comments and posts.
[lemmy.git] / server / src / api / mod.rs
1 use crate::db::category::*;
2 use crate::db::comment::*;
3 use crate::db::comment_view::*;
4 use crate::db::community::*;
5 use crate::db::community_view::*;
6 use crate::db::moderator::*;
7 use crate::db::moderator_views::*;
8 use crate::db::post::*;
9 use crate::db::post_view::*;
10 use crate::db::user::*;
11 use crate::db::user_view::*;
12 use crate::db::*;
13 use crate::{has_slurs, naive_from_unix, naive_now, remove_slurs, Settings};
14 use failure::Error;
15 use serde::{Deserialize, Serialize};
16
17 pub mod comment;
18 pub mod community;
19 pub mod post;
20 pub mod site;
21 pub mod user;
22
23 #[derive(EnumString, ToString, Debug)]
24 pub enum UserOperation {
25   Login,
26   Register,
27   CreateCommunity,
28   CreatePost,
29   ListCommunities,
30   ListCategories,
31   GetPost,
32   GetCommunity,
33   CreateComment,
34   EditComment,
35   SaveComment,
36   CreateCommentLike,
37   GetPosts,
38   CreatePostLike,
39   EditPost,
40   SavePost,
41   EditCommunity,
42   FollowCommunity,
43   GetFollowedCommunities,
44   GetUserDetails,
45   GetReplies,
46   GetModlog,
47   BanFromCommunity,
48   AddModToCommunity,
49   CreateSite,
50   EditSite,
51   GetSite,
52   AddAdmin,
53   BanUser,
54   Search,
55   MarkAllAsRead,
56   SaveUserSettings,
57   TransferCommunity,
58   TransferSite,
59   DeleteAccount,
60 }
61
62 #[derive(Fail, Debug)]
63 #[fail(display = "{{\"op\":\"{}\", \"error\":\"{}\"}}", op, message)]
64 pub struct APIError {
65   pub op: String,
66   pub message: String,
67 }
68
69 impl APIError {
70   pub fn err(op: &UserOperation, msg: &str) -> Self {
71     APIError {
72       op: op.to_string(),
73       message: msg.to_string(),
74     }
75   }
76 }
77
78 pub struct Oper<T> {
79   op: UserOperation,
80   data: T,
81 }
82
83 impl<T> Oper<T> {
84   pub fn new(op: UserOperation, data: T) -> Oper<T> {
85     Oper { op: op, data: data }
86   }
87 }
88
89 pub trait Perform<T> {
90   fn perform(&self) -> Result<T, Error>
91   where
92     T: Sized;
93 }