]> Untitled Git - lemmy.git/blobdiff - server/src/api/mod.rs
Merge branch 'master' into federation_merge_from_master_2
[lemmy.git] / server / src / api / mod.rs
index 6e3e8269da4b7f393713bce48809149635891c63..afd62aff8011a524cb45e0b748fb96c3af8c5c81 100644 (file)
@@ -1,60 +1,49 @@
-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>;
 }