2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::category::*;
|
2019-06-03 17:47:12 +00:00
|
|
|
use crate::db::comment::*;
|
|
|
|
use crate::db::comment_view::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::community::*;
|
2019-06-03 17:47:12 +00:00
|
|
|
use crate::db::community_view::*;
|
|
|
|
use crate::db::moderator::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::moderator_views::*;
|
2019-11-02 06:43:21 +00:00
|
|
|
use crate::db::password_reset_request::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::post::*;
|
|
|
|
use crate::db::post_view::*;
|
2019-12-11 20:21:47 +00:00
|
|
|
use crate::db::site::*;
|
|
|
|
use crate::db::site_view::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::user::*;
|
2019-10-20 00:46:29 +00:00
|
|
|
use crate::db::user_mention::*;
|
|
|
|
use crate::db::user_mention_view::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::user_view::*;
|
|
|
|
use crate::db::*;
|
2019-12-15 16:40:55 +00:00
|
|
|
use crate::{extract_usernames, has_slurs, naive_from_unix, naive_now, remove_slurs};
|
2019-09-07 15:35:05 +00:00
|
|
|
use failure::Error;
|
|
|
|
use serde::{Deserialize, Serialize};
|
2019-05-05 05:20:38 +00:00
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
pub mod comment;
|
2019-05-05 05:20:38 +00:00
|
|
|
pub mod community;
|
|
|
|
pub mod post;
|
|
|
|
pub mod site;
|
2019-09-07 15:35:05 +00:00
|
|
|
pub mod user;
|
2019-05-05 05:20:38 +00:00
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
#[derive(EnumString, ToString, Debug)]
|
2019-05-05 05:20:38 +00:00
|
|
|
pub enum UserOperation {
|
2019-09-07 15:35:05 +00:00
|
|
|
Login,
|
|
|
|
Register,
|
|
|
|
CreateCommunity,
|
|
|
|
CreatePost,
|
|
|
|
ListCommunities,
|
|
|
|
ListCategories,
|
|
|
|
GetPost,
|
|
|
|
GetCommunity,
|
|
|
|
CreateComment,
|
|
|
|
EditComment,
|
|
|
|
SaveComment,
|
|
|
|
CreateCommentLike,
|
|
|
|
GetPosts,
|
|
|
|
CreatePostLike,
|
|
|
|
EditPost,
|
|
|
|
SavePost,
|
|
|
|
EditCommunity,
|
|
|
|
FollowCommunity,
|
|
|
|
GetFollowedCommunities,
|
|
|
|
GetUserDetails,
|
|
|
|
GetReplies,
|
2019-10-20 00:46:29 +00:00
|
|
|
GetUserMentions,
|
|
|
|
EditUserMention,
|
2019-09-07 15:35:05 +00:00
|
|
|
GetModlog,
|
|
|
|
BanFromCommunity,
|
|
|
|
AddModToCommunity,
|
|
|
|
CreateSite,
|
|
|
|
EditSite,
|
|
|
|
GetSite,
|
|
|
|
AddAdmin,
|
|
|
|
BanUser,
|
|
|
|
Search,
|
|
|
|
MarkAllAsRead,
|
|
|
|
SaveUserSettings,
|
|
|
|
TransferCommunity,
|
|
|
|
TransferSite,
|
2019-10-15 22:09:01 +00:00
|
|
|
DeleteAccount,
|
2019-11-02 06:43:21 +00:00
|
|
|
PasswordReset,
|
2019-10-30 03:35:39 +00:00
|
|
|
PasswordChange,
|
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,
|
2019-09-07 15:35:05 +00:00
|
|
|
data: T,
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
impl<T> Oper<T> {
|
2019-05-05 05:20:38 +00:00
|
|
|
pub fn new(op: UserOperation, data: T) -> Oper<T> {
|
2019-12-09 19:08:19 +00:00
|
|
|
Oper { op, data }
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Perform<T> {
|
2019-09-07 15:35:05 +00:00
|
|
|
fn perform(&self) -> Result<T, Error>
|
|
|
|
where
|
|
|
|
T: Sized;
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|