]> Untitled Git - lemmy.git/blob - server/src/api/mod.rs
Merge branch 'reorg' into dev
[lemmy.git] / server / src / api / mod.rs
1 use serde::{Deserialize, Serialize};
2 use failure::Error;
3 use db::*;
4 use db::community::*;
5 use db::user::*;
6 use db::post::*;
7 use db::comment::*;
8 use db::post_view::*;
9 use db::comment_view::*;
10 use db::category::*;
11 use db::community_view::*;
12 use db::user_view::*;
13 use db::moderator_views::*;
14 use db::moderator::*;
15 use {has_slurs, remove_slurs, Settings, naive_now, naive_from_unix};
16
17 pub mod user;
18 pub mod community;
19 pub mod post;
20 pub mod comment;
21 pub mod site;
22
23 #[derive(EnumString,ToString,Debug)]
24 pub enum UserOperation {
25   Login, Register, CreateCommunity, CreatePost, ListCommunities, ListCategories, GetPost, GetCommunity, CreateComment, EditComment, SaveComment, CreateCommentLike, GetPosts, CreatePostLike, EditPost, SavePost, EditCommunity, FollowCommunity, GetFollowedCommunities, GetUserDetails, GetReplies, GetModlog, BanFromCommunity, AddModToCommunity, CreateSite, EditSite, GetSite, AddAdmin, BanUser, Search, MarkAllAsRead
26 }
27
28 #[derive(Fail, Debug)]
29 #[fail(display = "{{\"op\":\"{}\", \"error\":\"{}\"}}", op, message)]
30 pub struct APIError {
31   pub op: String,
32   pub message: String,
33 }
34
35 impl APIError {
36   pub fn err(op: &UserOperation, msg: &str) -> Self {
37     APIError {
38       op: op.to_string(),
39       message: msg.to_string(),
40     }
41   }
42 }
43
44 pub struct Oper<T> {
45   op: UserOperation,
46   data: T
47 }
48
49 impl <T> Oper<T> {
50   pub fn new(op: UserOperation, data: T) -> Oper<T> {
51     Oper {
52       op: op,
53       data: data
54     }
55   }
56 }
57
58 pub trait Perform<T> {
59   fn perform(&self) -> Result<T, Error> where T: Sized;
60 }