2019-05-05 05:20:38 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use failure::Error;
|
2019-06-03 17:47:12 +00:00
|
|
|
use crate::db::*;
|
|
|
|
use crate::db::community::*;
|
|
|
|
use crate::db::user::*;
|
|
|
|
use crate::db::post::*;
|
|
|
|
use crate::db::comment::*;
|
|
|
|
use crate::db::post_view::*;
|
|
|
|
use crate::db::comment_view::*;
|
|
|
|
use crate::db::category::*;
|
|
|
|
use crate::db::community_view::*;
|
|
|
|
use crate::db::user_view::*;
|
|
|
|
use crate::db::moderator_views::*;
|
|
|
|
use crate::db::moderator::*;
|
|
|
|
use crate::{has_slurs, remove_slurs, Settings, naive_now, naive_from_unix};
|
2019-05-05 05:20:38 +00:00
|
|
|
|
|
|
|
pub mod user;
|
|
|
|
pub mod community;
|
|
|
|
pub mod post;
|
|
|
|
pub mod comment;
|
|
|
|
pub mod site;
|
|
|
|
|
|
|
|
#[derive(EnumString,ToString,Debug)]
|
|
|
|
pub enum UserOperation {
|
2019-08-14 02:52:43 +00:00
|
|
|
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, SaveUserSettings
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Fail, Debug)]
|
|
|
|
#[fail(display = "{{\"op\":\"{}\", \"error\":\"{}\"}}", op, message)]
|
|
|
|
pub struct APIError {
|
2019-05-05 16:20:30 +00:00
|
|
|
pub op: String,
|
|
|
|
pub message: String,
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl APIError {
|
2019-05-05 16:20:30 +00:00
|
|
|
pub fn err(op: &UserOperation, msg: &str) -> Self {
|
2019-05-05 05:20:38 +00:00
|
|
|
APIError {
|
|
|
|
op: op.to_string(),
|
|
|
|
message: msg.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Oper<T> {
|
|
|
|
op: UserOperation,
|
|
|
|
data: T
|
|
|
|
}
|
|
|
|
|
|
|
|
impl <T> Oper<T> {
|
|
|
|
pub fn new(op: UserOperation, data: T) -> Oper<T> {
|
|
|
|
Oper {
|
|
|
|
op: op,
|
|
|
|
data: data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Perform<T> {
|
|
|
|
fn perform(&self) -> Result<T, Error> where T: Sized;
|
|
|
|
}
|