-use serde::{Deserialize, Serialize};
+use crate::{
+ db::{community::*, community_view::*, moderator::*, site::*, user::*, user_view::*},
+ websocket::WebsocketInfo,
+};
+use diesel::{
+ r2d2::{ConnectionManager, Pool},
+ PgConnection,
+};
use failure::Error;
-use db::*;
-use db::community::*;
-use db::user::*;
-use db::post::*;
-use db::comment::*;
-use db::post_view::*;
-use db::comment_view::*;
-use db::category::*;
-use db::community_view::*;
-use db::user_view::*;
-use db::moderator_views::*;
-use db::moderator::*;
-use {has_slurs, remove_slurs, Settings, naive_now, naive_from_unix};
-pub mod user;
+pub mod comment;
pub mod community;
pub mod post;
-pub mod comment;
pub mod site;
-
-#[derive(EnumString,ToString,Debug)]
-pub enum UserOperation {
- 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
-}
+pub mod user;
#[derive(Fail, Debug)]
-#[fail(display = "{{\"op\":\"{}\", \"error\":\"{}\"}}", op, message)]
+#[fail(display = "{{\"error\":\"{}\"}}", message)]
pub struct APIError {
- pub op: String,
pub message: String,
}
impl APIError {
- pub fn err(op: &UserOperation, msg: &str) -> Self {
+ pub fn err(msg: &str) -> Self {
APIError {
- op: op.to_string(),
message: msg.to_string(),
}
}
}
pub struct Oper<T> {
- op: UserOperation,
- data: T
+ data: T,
}
-impl <T> Oper<T> {
- pub fn new(op: UserOperation, data: T) -> Oper<T> {
- Oper {
- op: op,
- data: data
- }
+impl<Data> Oper<Data> {
+ pub fn new(data: Data) -> Oper<Data> {
+ Oper { data }
}
}
-pub trait Perform<T> {
- fn perform(&self) -> Result<T, Error> where T: Sized;
+pub trait Perform {
+ type Response: serde::ser::Serialize + Send;
+
+ fn perform(
+ &self,
+ pool: Pool<ConnectionManager<PgConnection>>,
+ websocket_info: Option<WebsocketInfo>,
+ ) -> Result<Self::Response, Error>;
}