]> Untitled Git - lemmy.git/blob - server/src/api/mod.rs
Merge branch 'nocross-nomusl' of https://github.com/iav/lemmy into iav-nocross-nomusl
[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 }
60
61 #[derive(Fail, Debug)]
62 #[fail(display = "{{\"op\":\"{}\", \"error\":\"{}\"}}", op, message)]
63 pub struct APIError {
64   pub op: String,
65   pub message: String,
66 }
67
68 impl APIError {
69   pub fn err(op: &UserOperation, msg: &str) -> Self {
70     APIError {
71       op: op.to_string(),
72       message: msg.to_string(),
73     }
74   }
75 }
76
77 pub struct Oper<T> {
78   op: UserOperation,
79   data: T,
80 }
81
82 impl<T> Oper<T> {
83   pub fn new(op: UserOperation, data: T) -> Oper<T> {
84     Oper { op: op, data: data }
85   }
86 }
87
88 pub trait Perform<T> {
89   fn perform(&self) -> Result<T, Error>
90   where
91     T: Sized;
92 }