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