lemmy/server/src/api/mod.rs

47 lines
921 B
Rust
Raw Normal View History

use crate::{websocket::WebsocketInfo, DbPool, LemmyError};
use actix_web::client::Client;
use lemmy_db::{community::*, community_view::*, moderator::*, site::*, user::*, user_view::*};
2019-05-05 05:20:38 +00:00
pub mod claims;
pub mod comment;
2019-05-05 05:20:38 +00:00
pub mod community;
pub mod post;
pub mod site;
pub mod user;
2019-05-05 05:20:38 +00:00
#[derive(Fail, Debug)]
2020-01-16 14:39:08 +00:00
#[fail(display = "{{\"error\":\"{}\"}}", message)]
2019-05-05 05:20:38 +00:00
pub struct APIError {
2019-05-05 16:20:30 +00:00
pub message: String,
2019-05-05 05:20:38 +00:00
}
impl APIError {
2020-01-16 14:39:08 +00:00
pub fn err(msg: &str) -> Self {
2019-05-05 05:20:38 +00:00
APIError {
message: msg.to_string(),
}
}
}
pub struct Oper<T> {
data: T,
client: Client,
2019-05-05 05:20:38 +00:00
}
2020-04-24 14:04:36 +00:00
impl<Data> Oper<Data> {
pub fn new(data: Data, client: Client) -> Oper<Data> {
Oper { data, client }
2019-05-05 05:20:38 +00:00
}
}
#[async_trait::async_trait(?Send)]
pub trait Perform {
2020-04-21 20:40:03 +00:00
type Response: serde::ser::Serialize + Send;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
) -> Result<Self::Response, LemmyError>;
2019-05-05 05:20:38 +00:00
}