dependencies = [
"lemmy_db",
"serde 1.0.114",
- "thiserror",
]
[[package]]
dependencies = [
"actix-web",
"futures",
- "lemmy_api_structs",
"lemmy_utils",
"log",
"strum",
"regex",
"serde 1.0.114",
"serde_json",
+ "thiserror",
"url",
]
[dependencies]
lemmy_db = { path = "../lemmy_db" }
serde = { version = "1.0.105", features = ["derive"] }
-thiserror = "1.0.20"
use lemmy_db::comment_view::CommentView;
use serde::{Deserialize, Serialize};
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct CreateComment {
pub content: String,
pub parent_id: Option<i32>,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct EditComment {
pub content: String,
pub edit_id: i32,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct DeleteComment {
pub edit_id: i32,
pub deleted: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct RemoveComment {
pub edit_id: i32,
pub removed: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct MarkCommentAsRead {
pub edit_id: i32,
pub read: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct SaveComment {
pub comment_id: i32,
pub save: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct CommentResponse {
pub comment: CommentView,
pub recipient_ids: Vec<i32>,
pub form_id: Option<String>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct CreateCommentLike {
pub comment_id: i32,
pub score: i16,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetComments {
pub type_: String,
pub sort: String,
pub auth: Option<String>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetCommentsResponse {
pub comments: Vec<CommentView>,
}
};
use serde::{Deserialize, Serialize};
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetCommunity {
pub id: Option<i32>,
pub name: Option<String>,
pub auth: Option<String>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetCommunityResponse {
pub community: CommunityView,
pub moderators: Vec<CommunityModeratorView>,
pub online: usize,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct CreateCommunity {
pub name: String,
pub title: String,
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct CommunityResponse {
pub community: CommunityView,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Deserialize, Debug)]
pub struct ListCommunities {
pub sort: String,
pub page: Option<i64>,
pub auth: Option<String>,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Debug)]
pub struct ListCommunitiesResponse {
pub communities: Vec<CommunityView>,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Deserialize, Clone)]
pub struct BanFromCommunity {
pub community_id: i32,
pub user_id: i32,
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct BanFromCommunityResponse {
pub user: UserView,
pub banned: bool,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct AddModToCommunity {
pub community_id: i32,
pub user_id: i32,
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct AddModToCommunityResponse {
pub moderators: Vec<CommunityModeratorView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct EditCommunity {
pub edit_id: i32,
pub title: String,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct DeleteCommunity {
pub edit_id: i32,
pub deleted: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct RemoveCommunity {
pub edit_id: i32,
pub removed: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct FollowCommunity {
pub community_id: i32,
pub follow: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetFollowedCommunities {
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetFollowedCommunitiesResponse {
pub communities: Vec<CommunityFollowerView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct TransferCommunity {
pub community_id: i32,
pub user_id: i32,
-pub extern crate serde;
-pub extern crate thiserror;
+extern crate serde;
pub mod comment;
pub mod community;
pub mod post;
pub mod site;
pub mod user;
-
-use thiserror::Error;
-
-#[derive(Debug, Error)]
-#[error("{{\"error\":\"{message}\"}}")]
-pub struct APIError {
- pub message: String,
-}
-
-impl APIError {
- pub fn err(msg: &str) -> Self {
- APIError {
- message: msg.to_string(),
- }
- }
-}
};
use serde::{Deserialize, Serialize};
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Deserialize, Debug)]
pub struct CreatePost {
pub name: String,
pub url: Option<String>,
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct PostResponse {
pub post: PostView,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetPost {
pub id: i32,
pub auth: Option<String>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetPostResponse {
pub post: PostView,
pub comments: Vec<CommentView>,
pub online: usize,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Deserialize, Debug)]
pub struct GetPosts {
pub type_: String,
pub sort: String,
pub auth: Option<String>,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Debug)]
pub struct GetPostsResponse {
pub posts: Vec<PostView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct CreatePostLike {
pub post_id: i32,
pub score: i16,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct EditPost {
pub edit_id: i32,
pub name: String,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct DeletePost {
pub edit_id: i32,
pub deleted: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct RemovePost {
pub edit_id: i32,
pub removed: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct LockPost {
pub edit_id: i32,
pub locked: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct StickyPost {
pub edit_id: i32,
pub stickied: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct SavePost {
pub post_id: i32,
pub save: bool,
};
use serde::{Deserialize, Serialize};
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct ListCategories {}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct ListCategoriesResponse {
pub categories: Vec<Category>,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Deserialize, Debug)]
pub struct Search {
pub q: String,
pub type_: String,
pub auth: Option<String>,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Debug)]
pub struct SearchResponse {
pub type_: String,
pub comments: Vec<CommentView>,
pub users: Vec<UserView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetModlog {
pub mod_user_id: Option<i32>,
pub community_id: Option<i32>,
pub limit: Option<i64>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetModlogResponse {
pub removed_posts: Vec<ModRemovePostView>,
pub locked_posts: Vec<ModLockPostView>,
pub added: Vec<ModAddView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct CreateSite {
pub name: String,
pub description: Option<String>,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct EditSite {
pub name: String,
pub description: Option<String>,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetSite {
pub auth: Option<String>,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct SiteResponse {
pub site: SiteView,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetSiteResponse {
pub site: Option<SiteView>,
pub admins: Vec<UserView>,
pub federated_instances: Vec<String>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct TransferSite {
pub user_id: i32,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetSiteConfig {
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetSiteConfigResponse {
pub config_hjson: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct SaveSiteConfig {
pub config_hjson: String,
pub auth: String,
};
use serde::{Deserialize, Serialize};
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Deserialize, Debug)]
pub struct Login {
pub username_or_email: String,
pub password: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct Register {
pub username: String,
pub email: Option<String>,
pub captcha_answer: Option<String>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetCaptcha {}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetCaptchaResponse {
pub ok: Option<CaptchaResponse>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct CaptchaResponse {
pub png: String, // A Base64 encoded png
pub wav: Option<String>, // A Base64 encoded wav audio
pub uuid: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct SaveUserSettings {
pub show_nsfw: bool,
pub theme: String,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct LoginResponse {
pub jwt: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetUserDetails {
pub user_id: Option<i32>,
pub username: Option<String>,
pub auth: Option<String>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetUserDetailsResponse {
pub user: UserView,
pub follows: Vec<CommunityFollowerView>,
pub posts: Vec<PostView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetRepliesResponse {
pub replies: Vec<ReplyView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize)]
pub struct GetUserMentionsResponse {
pub mentions: Vec<UserMentionView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct MarkAllAsRead {
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct AddAdmin {
pub user_id: i32,
pub added: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct AddAdminResponse {
pub admins: Vec<UserView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct BanUser {
pub user_id: i32,
pub ban: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct BanUserResponse {
pub user: UserView,
pub banned: bool,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetReplies {
pub sort: String,
pub page: Option<i64>,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetUserMentions {
pub sort: String,
pub page: Option<i64>,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct MarkUserMentionAsRead {
pub user_mention_id: i32,
pub read: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct UserMentionResponse {
pub mention: UserMentionView,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct DeleteAccount {
pub password: String,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct PasswordReset {
pub email: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct PasswordResetResponse {}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct PasswordChange {
pub token: String,
pub password: String,
pub password_verify: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct CreatePrivateMessage {
pub content: String,
pub recipient_id: i32,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct EditPrivateMessage {
pub edit_id: i32,
pub content: String,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct DeletePrivateMessage {
pub edit_id: i32,
pub deleted: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct MarkPrivateMessageAsRead {
pub edit_id: i32,
pub read: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Deserialize)]
pub struct GetPrivateMessages {
pub unread_only: bool,
pub page: Option<i64>,
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct PrivateMessagesResponse {
pub messages: Vec<PrivateMessageView>,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct PrivateMessageResponse {
pub message: PrivateMessageView,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Deserialize, Debug)]
pub struct UserJoin {
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Serialize, Clone)]
pub struct UserJoinResponse {
pub user_id: i32,
}
use crate::{schema::activity, Crud};
use diesel::{dsl::*, result::Error, *};
use log::debug;
-use serde::{Deserialize, Serialize};
+use serde::{Serialize};
use serde_json::Value;
use std::{
fmt::Debug,
io::{Error as IoError, ErrorKind},
};
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "activity"]
pub struct Activity {
pub id: i32,
pub updated: Option<chrono::NaiveDateTime>,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "activity"]
pub struct ActivityForm {
pub user_id: i32,
Crud,
};
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
+use serde::{Serialize};
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "category"]
pub struct Category {
pub id: i32,
pub name: String,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "category"]
pub struct CategoryForm {
pub name: String,
Saveable,
};
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
use url::{ParseError, Url};
// WITH RECURSIVE MyTree AS (
// )
// SELECT * FROM MyTree;
-#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug)]
#[belongs_to(Post)]
#[table_name = "comment"]
pub struct Comment {
pub published: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "comment_saved"]
pub struct CommentSavedForm {
pub comment_id: i32,
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "comment_fast_view"]
pub struct CommentView {
Joinable,
};
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "community"]
pub struct Community {
pub id: i32,
pub banner: Option<String>,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize, Debug)]
+#[derive(Insertable, AsChangeset, Debug)]
#[table_name = "community"]
pub struct CommunityForm {
pub name: String,
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "community_fast_view"]
pub struct CommunityView {
#[macro_use]
-pub extern crate diesel;
+extern crate diesel;
#[macro_use]
-pub extern crate strum_macros;
+extern crate strum_macros;
#[macro_use]
-pub extern crate lazy_static;
-pub extern crate bcrypt;
-pub extern crate chrono;
-pub extern crate log;
-pub extern crate regex;
-pub extern crate serde;
-pub extern crate serde_json;
-pub extern crate sha2;
-pub extern crate strum;
+extern crate lazy_static;
+extern crate bcrypt;
+extern crate chrono;
+extern crate log;
+extern crate regex;
+extern crate serde;
+extern crate serde_json;
+extern crate sha2;
+extern crate strum;
use chrono::NaiveDateTime;
use diesel::{result::Error, *};
Crud,
};
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "mod_remove_post"]
pub struct ModRemovePost {
pub id: i32,
pub when_: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_post"]
pub struct ModRemovePostForm {
pub mod_user_id: i32,
}
}
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "mod_lock_post"]
pub struct ModLockPost {
pub id: i32,
pub when_: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "mod_lock_post"]
pub struct ModLockPostForm {
pub mod_user_id: i32,
}
}
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "mod_sticky_post"]
pub struct ModStickyPost {
pub id: i32,
pub when_: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "mod_sticky_post"]
pub struct ModStickyPostForm {
pub mod_user_id: i32,
}
}
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "mod_remove_comment"]
pub struct ModRemoveComment {
pub id: i32,
pub when_: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_comment"]
pub struct ModRemoveCommentForm {
pub mod_user_id: i32,
}
}
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "mod_remove_community"]
pub struct ModRemoveCommunity {
pub id: i32,
pub when_: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_community"]
pub struct ModRemoveCommunityForm {
pub mod_user_id: i32,
}
}
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "mod_ban_from_community"]
pub struct ModBanFromCommunity {
pub id: i32,
pub when_: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "mod_ban_from_community"]
pub struct ModBanFromCommunityForm {
pub mod_user_id: i32,
}
}
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "mod_ban"]
pub struct ModBan {
pub id: i32,
pub when_: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "mod_ban"]
pub struct ModBanForm {
pub mod_user_id: i32,
}
}
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "mod_add_community"]
pub struct ModAddCommunity {
pub id: i32,
pub when_: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "mod_add_community"]
pub struct ModAddCommunityForm {
pub mod_user_id: i32,
}
}
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "mod_add"]
pub struct ModAdd {
pub id: i32,
pub when_: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "mod_add"]
pub struct ModAddForm {
pub mod_user_id: i32,
use crate::limit_and_offset;
use diesel::{result::Error, *};
-use serde::{Deserialize, Serialize};
+use serde::{Serialize};
table! {
mod_remove_post_view (id) {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_remove_post_view"]
pub struct ModRemovePostView {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_lock_post_view"]
pub struct ModLockPostView {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_sticky_post_view"]
pub struct ModStickyPostView {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_remove_comment_view"]
pub struct ModRemoveCommentView {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_remove_community_view"]
pub struct ModRemoveCommunityView {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_ban_from_community_view"]
pub struct ModBanFromCommunityView {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_ban_view"]
pub struct ModBanView {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_add_community_view"]
pub struct ModAddCommunityView {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_add_view"]
pub struct ModAddView {
pub published: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "password_reset_request"]
pub struct PasswordResetRequestForm {
pub user_id: i32,
Saveable,
};
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
use url::{ParseError, Url};
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "post"]
pub struct Post {
pub id: i32,
pub local: bool,
}
-#[derive(Insertable, AsChangeset, Clone, Debug)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "post"]
pub struct PostForm {
pub name: String,
pub published: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "post_saved"]
pub struct PostSavedForm {
pub post_id: i32,
pub published: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "post_read"]
pub struct PostReadForm {
pub post_id: i32,
use super::post_view::post_fast_view::BoxedQuery;
use crate::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType};
use diesel::{dsl::*, pg::Pg, result::Error, *};
-use serde::{Deserialize, Serialize};
+use serde::{Serialize};
// The faked schema since diesel doesn't do views
table! {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "post_fast_view"]
pub struct PostView {
use crate::{naive_now, schema::private_message, Crud};
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "private_message"]
pub struct PrivateMessage {
pub id: i32,
pub local: bool,
}
-#[derive(Insertable, AsChangeset, Clone)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "private_message"]
pub struct PrivateMessageForm {
pub creator_id: i32,
use crate::{limit_and_offset, MaybeOptional};
use diesel::{pg::Pg, result::Error, *};
-use serde::{Deserialize, Serialize};
+use serde::{Serialize};
// The faked schema since diesel doesn't do views
table! {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "private_message_view"]
pub struct PrivateMessageView {
use crate::{naive_now, schema::site, Crud};
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "site"]
pub struct Site {
pub id: i32,
pub banner: Option<String>,
}
-#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "site"]
pub struct SiteForm {
pub name: String,
use diesel::{result::Error, *};
-use serde::{Deserialize, Serialize};
+use serde::{Serialize};
table! {
site_view (id) {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "site_view"]
pub struct SiteView {
};
use bcrypt::{hash, DEFAULT_COST};
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
+use serde::{Serialize};
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "user_"]
pub struct User_ {
pub id: i32,
pub banner: Option<String>,
}
-#[derive(Insertable, AsChangeset, Clone, Debug)]
+#[derive(Insertable, AsChangeset, Clone)]
#[table_name = "user_"]
pub struct UserForm {
pub name: String,
use super::comment::Comment;
use crate::{schema::user_mention, Crud};
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
-#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
+#[derive(Queryable, Associations, Identifiable, PartialEq, Debug)]
#[belongs_to(Comment)]
#[table_name = "user_mention"]
pub struct UserMention {
pub published: chrono::NaiveDateTime,
}
-#[derive(Insertable, AsChangeset, Clone)]
+#[derive(Insertable, AsChangeset)]
#[table_name = "user_mention"]
pub struct UserMentionForm {
pub recipient_id: i32,
use crate::{limit_and_offset, MaybeOptional, SortType};
use diesel::{dsl::*, pg::Pg, result::Error, *};
-use serde::{Deserialize, Serialize};
+use serde::{Serialize};
// The faked schema since diesel doesn't do views
table! {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "user_mention_fast_view"]
pub struct UserMentionView {
use super::user_view::user_fast::BoxedQuery;
use crate::{fuzzy_search, limit_and_offset, MaybeOptional, SortType};
use diesel::{dsl::*, pg::Pg, result::Error, *};
-use serde::{Deserialize, Serialize};
+use serde::{Serialize};
table! {
user_view (id) {
}
#[derive(
- Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
+ Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "user_fast"]
pub struct UserView {
[dependencies]
lemmy_utils = { path = "../lemmy_utils" }
-lemmy_api_structs = { path = "../lemmy_api_structs" }
tokio = "0.2.21"
strum = "0.18.0"
strum_macros = "0.18.0"
#[macro_use]
-pub extern crate strum_macros;
-pub extern crate actix_web;
-pub extern crate futures;
-pub extern crate log;
-pub extern crate tokio;
+extern crate strum_macros;
+extern crate actix_web;
+extern crate futures;
+extern crate log;
+extern crate tokio;
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
use futures::future::{ok, Ready};
-use lemmy_api_structs::APIError;
-use lemmy_utils::{IPAddr, LemmyError};
+use lemmy_utils::{APIError, IPAddr, LemmyError};
use log::debug;
use std::{collections::HashMap, time::SystemTime};
use strum::IntoEnumIterator;
rand = "0.7.3"
serde = { version = "1.0.105", features = ["derive"] }
serde_json = { version = "1.0.52", features = ["preserve_order"]}
+thiserror = "1.0.20"
comrak = "0.7"
lazy_static = "1.3.0"
openssl = "0.10"
#[macro_use]
-pub extern crate lazy_static;
-pub extern crate actix_web;
-pub extern crate anyhow;
-pub extern crate comrak;
-pub extern crate lettre;
-pub extern crate lettre_email;
-pub extern crate openssl;
-pub extern crate rand;
-pub extern crate regex;
-pub extern crate serde_json;
-pub extern crate url;
+extern crate lazy_static;
+extern crate actix_web;
+extern crate anyhow;
+extern crate comrak;
+extern crate lettre;
+extern crate lettre_email;
+extern crate openssl;
+extern crate rand;
+extern crate regex;
+extern crate serde_json;
+extern crate thiserror;
+extern crate url;
pub mod settings;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use regex::{Regex, RegexBuilder};
use std::io::{Error, ErrorKind};
+use thiserror::Error;
use url::Url;
pub type ConnectionId = usize;
};
}
+#[derive(Debug, Error)]
+#[error("{{\"error\":\"{message}\"}}")]
+pub struct APIError {
+ pub message: String,
+}
+
+impl APIError {
+ pub fn err(msg: &str) -> Self {
+ APIError {
+ message: msg.to_string(),
+ }
+ }
+}
+
#[derive(Debug)]
pub struct LemmyError {
inner: anyhow::Error,
LemmyContext,
};
use actix_web::web::Data;
-use lemmy_api_structs::{comment::*, APIError};
+use lemmy_api_structs::comment::*;
use lemmy_db::{
comment::*,
comment_view::*,
scrape_text_for_mentions,
send_email,
settings::Settings,
+ APIError,
ConnectionId,
EndpointType,
LemmyError,
};
use actix_web::web::Data;
use anyhow::Context;
-use lemmy_api_structs::{community::*, APIError};
+use lemmy_api_structs::community::*;
use lemmy_db::{
comment::Comment,
comment_view::CommentQueryBuilder,
location_info,
make_apub_endpoint,
naive_from_unix,
+ APIError,
ConnectionId,
EndpointType,
LemmyError,
use crate::{api::claims::Claims, blocking, DbPool, LemmyContext};
use actix_web::web::Data;
-use lemmy_api_structs::APIError;
use lemmy_db::{
community::Community,
community_view::CommunityUserBanView,
user::User_,
Crud,
};
-use lemmy_utils::{slur_check, slurs_vec_to_str, ConnectionId, LemmyError};
+use lemmy_utils::{slur_check, slurs_vec_to_str, APIError, ConnectionId, LemmyError};
pub mod claims;
pub mod comment;
LemmyContext,
};
use actix_web::web::Data;
-use lemmy_api_structs::{post::*, APIError};
+use lemmy_api_structs::post::*;
use lemmy_db::{
comment_view::*,
community_view::*,
use lemmy_utils::{
is_valid_post_title,
make_apub_endpoint,
+ APIError,
ConnectionId,
EndpointType,
LemmyError,
};
use actix_web::web::Data;
use anyhow::Context;
-use lemmy_api_structs::{site::*, user::Register, APIError};
+use lemmy_api_structs::{site::*, user::Register};
use lemmy_db::{
category::*,
comment_view::*,
SearchType,
SortType,
};
-use lemmy_utils::{location_info, settings::Settings, ConnectionId, LemmyError};
+use lemmy_utils::{location_info, settings::Settings, APIError, ConnectionId, LemmyError};
use log::{debug, info};
use std::str::FromStr;
use bcrypt::verify;
use captcha::{gen, Difficulty};
use chrono::Duration;
-use lemmy_api_structs::{user::*, APIError};
+use lemmy_api_structs::user::*;
use lemmy_db::{
comment::*,
comment_view::*,
remove_slurs,
send_email,
settings::Settings,
+ APIError,
ConnectionId,
EndpointType,
LemmyError,
#![recursion_limit = "512"]
#[macro_use]
-pub extern crate strum_macros;
+extern crate strum_macros;
#[macro_use]
-pub extern crate lazy_static;
-pub extern crate actix;
-pub extern crate actix_web;
-pub extern crate base64;
-pub extern crate bcrypt;
-pub extern crate captcha;
-pub extern crate chrono;
-pub extern crate diesel;
-pub extern crate dotenv;
-pub extern crate jsonwebtoken;
+extern crate lazy_static;
+extern crate actix;
+extern crate actix_web;
+extern crate base64;
+extern crate bcrypt;
+extern crate captcha;
+extern crate chrono;
+extern crate diesel;
+extern crate dotenv;
+extern crate jsonwebtoken;
extern crate log;
-pub extern crate openssl;
-pub extern crate reqwest;
-pub extern crate rss;
-pub extern crate serde;
-pub extern crate serde_json;
-pub extern crate sha2;
-pub extern crate strum;
+extern crate openssl;
+extern crate reqwest;
+extern crate rss;
+extern crate serde;
+extern crate serde_json;
+extern crate sha2;
+extern crate strum;
pub mod api;
pub mod apub;
#[macro_use]
extern crate diesel_migrations;
-#[macro_use]
-pub extern crate lazy_static;
use actix::prelude::*;
use actix_web::{
r2d2::{ConnectionManager, Pool},
PgConnection,
};
+use lazy_static::lazy_static;
use lemmy_db::get_database_url_from_env;
use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit};
use lemmy_server::{
use actix_web::{error::ErrorBadRequest, *};
use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*};
use lemmy_rate_limit::RateLimit;
-use serde::Serialize;
+use serde::Deserialize;
pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
cfg.service(
Ok(res)
}
-async fn route_get<Data>(
+async fn route_get<'a, Data>(
data: web::Query<Data>,
context: web::Data<LemmyContext>,
) -> Result<HttpResponse, Error>
where
- Data: Serialize + Send + 'static + Perform,
+ Data: Deserialize<'a> + Send + 'static + Perform,
{
perform::<Data>(data.0, context).await
}
-async fn route_post<Data>(
+async fn route_post<'a, Data>(
data: web::Json<Data>,
context: web::Data<LemmyContext>,
) -> Result<HttpResponse, Error>
where
- Data: Serialize + Send + 'static + Perform,
+ Data: Deserialize<'a> + Send + 'static + Perform,
{
perform::<Data>(data.0, context).await
}
r2d2::{ConnectionManager, Pool},
PgConnection,
};
-use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*, APIError};
+use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*};
use lemmy_rate_limit::RateLimit;
-use lemmy_utils::{location_info, CommunityId, ConnectionId, IPAddr, LemmyError, PostId, UserId};
+use lemmy_utils::{
+ location_info,
+ APIError,
+ CommunityId,
+ ConnectionId,
+ IPAddr,
+ LemmyError,
+ PostId,
+ UserId,
+};
use rand::rngs::ThreadRng;
use reqwest::Client;
use serde::Serialize;