Move remaining structs from lemmy_db::source to lemmy_db_schema

This commit is contained in:
Felix Ableitner 2020-12-21 14:38:34 +01:00
parent a7e231b35b
commit 5231666465
52 changed files with 13966 additions and 14600 deletions

File diff suppressed because it is too large Load diff

View file

@ -10,11 +10,7 @@ use crate::{
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_apub::{ApubLikeableType, ApubObjectType}; use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{ use lemmy_db::{
source::{ source::comment::Comment_,
comment::Comment_,
comment_report::{CommentReport, CommentReportForm},
moderator::*,
},
views::{ views::{
comment_report_view::{CommentReportQueryBuilder, CommentReportView}, comment_report_view::{CommentReportQueryBuilder, CommentReportView},
comment_view::{CommentQueryBuilder, CommentView}, comment_view::{CommentQueryBuilder, CommentView},
@ -27,11 +23,7 @@ use lemmy_db::{
Saveable, Saveable,
SortType, SortType,
}; };
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{comment::*, comment_report::*, moderator::*, post::Post, user::*};
comment::{Comment, CommentForm, CommentLike, CommentLikeForm, CommentSaved, CommentSavedForm},
post::Post,
user::*,
};
use lemmy_structs::{blocking, comment::*, send_local_notifs}; use lemmy_structs::{blocking, comment::*, send_local_notifs};
use lemmy_utils::{ use lemmy_utils::{
apub::{make_apub_endpoint, EndpointType}, apub::{make_apub_endpoint, EndpointType},

View file

@ -14,9 +14,7 @@ use lemmy_db::{
source::{ source::{
comment::Comment_, comment::Comment_,
community::{CommunityModerator_, Community_}, community::{CommunityModerator_, Community_},
moderator::*,
post::Post_, post::Post_,
site::*,
}, },
views::{ views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
@ -36,7 +34,7 @@ use lemmy_db::{
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
source::{comment::Comment, community::*, post::Post}, source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
}; };
use lemmy_structs::{blocking, community::*}; use lemmy_structs::{blocking, community::*};
use lemmy_utils::{ use lemmy_utils::{

View file

@ -10,11 +10,7 @@ use crate::{
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_apub::{ApubLikeableType, ApubObjectType}; use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{ use lemmy_db::{
source::{ source::post::Post_,
moderator::*,
post::Post_,
post_report::{PostReport, PostReportForm},
},
views::{ views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView}, community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
@ -31,7 +27,11 @@ use lemmy_db::{
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
source::post::{Post, PostForm, PostLike, PostLikeForm, PostSaved, PostSavedForm}, source::{
moderator::*,
post::*,
post_report::{PostReport, PostReportForm},
},
}; };
use lemmy_structs::{blocking, post::*}; use lemmy_structs::{blocking, post::*};
use lemmy_utils::{ use lemmy_utils::{

View file

@ -12,7 +12,7 @@ use lemmy_apub::fetcher::search_by_apub_id;
use lemmy_db::{ use lemmy_db::{
aggregates::site_aggregates::SiteAggregates, aggregates::site_aggregates::SiteAggregates,
diesel_option_overwrite, diesel_option_overwrite,
source::{category::*, moderator::*, site::*}, source::{category::Category_, site::Site_},
views::{ views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
community::community_view::CommunityQueryBuilder, community::community_view::CommunityQueryBuilder,
@ -35,7 +35,14 @@ use lemmy_db::{
SearchType, SearchType,
SortType, SortType,
}; };
use lemmy_db_schema::naive_now; use lemmy_db_schema::{
naive_now,
source::{
category::Category,
moderator::*,
site::{Site, *},
},
};
use lemmy_structs::{blocking, site::*, user::Register}; use lemmy_structs::{blocking, site::*, user::Register};
use lemmy_utils::{ use lemmy_utils::{
location_info, location_info,

View file

@ -19,13 +19,11 @@ use lemmy_db::{
source::{ source::{
comment::Comment_, comment::Comment_,
community::Community_, community::Community_,
moderator::*, password_reset_request::PasswordResetRequest_,
password_reset_request::*,
post::Post_, post::Post_,
private_message::*, private_message::PrivateMessage_,
site::*,
user::User, user::User,
user_mention::*, user_mention::UserMention_,
}, },
views::{ views::{
comment_report_view::CommentReportView, comment_report_view::CommentReportView,
@ -49,7 +47,17 @@ use lemmy_db::{
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
source::{comment::Comment, community::*, post::Post, user::*}, source::{
comment::Comment,
community::*,
moderator::*,
password_reset_request::*,
post::Post,
private_message::*,
site::*,
user::*,
user_mention::*,
},
}; };
use lemmy_structs::{blocking, send_email_to_user, user::*}; use lemmy_structs::{blocking, send_email_to_user, user::*};
use lemmy_utils::{ use lemmy_utils::{

View file

@ -14,9 +14,10 @@ use activitystreams::{
}; };
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use lemmy_db::{ use lemmy_db::{
source::private_message::PrivateMessage, source::private_message::PrivateMessage_,
views::private_message_view::PrivateMessageView, views::private_message_view::PrivateMessageView,
}; };
use lemmy_db_schema::source::private_message::PrivateMessage;
use lemmy_structs::{blocking, user::PrivateMessageResponse}; use lemmy_structs::{blocking, user::PrivateMessageResponse};
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperation};

View file

@ -16,8 +16,8 @@ use activitystreams::{
}, },
prelude::*, prelude::*,
}; };
use lemmy_db::{source::private_message::PrivateMessage, Crud}; use lemmy_db::Crud;
use lemmy_db_schema::source::user::User_; use lemmy_db_schema::source::{private_message::PrivateMessage, user::User_};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -1,7 +1,8 @@
use activitystreams::unparsed::UnparsedMutExt; use activitystreams::unparsed::UnparsedMutExt;
use activitystreams_ext::UnparsedExtension; use activitystreams_ext::UnparsedExtension;
use diesel::PgConnection; use diesel::PgConnection;
use lemmy_db::{source::category::Category, Crud}; use lemmy_db::Crud;
use lemmy_db_schema::source::category::Category;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -1,6 +1,7 @@
use crate::APUB_JSON_CONTENT_TYPE; use crate::APUB_JSON_CONTENT_TYPE;
use actix_web::{body::Body, web, HttpResponse}; use actix_web::{body::Body, web, HttpResponse};
use lemmy_db::source::activity::Activity; use lemmy_db::source::activity::Activity_;
use lemmy_db_schema::source::activity::Activity;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{settings::Settings, LemmyError}; use lemmy_utils::{settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -12,8 +12,8 @@ use activitystreams::{
}; };
use actix_web::HttpRequest; use actix_web::HttpRequest;
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use lemmy_db::{source::activity::Activity, ApubObject, DbPool}; use lemmy_db::{source::activity::Activity_, ApubObject, DbPool};
use lemmy_db_schema::source::{community::Community, user::User_}; use lemmy_db_schema::source::{activity::Activity, community::Community, user::User_};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_utils::{location_info, settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -41,8 +41,8 @@ use activitystreams::{
}; };
use anyhow::Context; use anyhow::Context;
use diesel::result::Error::NotFound; use diesel::result::Error::NotFound;
use lemmy_db::{source::site::Site, ApubObject, Crud}; use lemmy_db::{ApubObject, Crud};
use lemmy_db_schema::source::{comment::Comment, post::Post}; use lemmy_db_schema::source::{comment::Comment, post::Post, site::Site};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -48,13 +48,10 @@ use activitystreams::{
use actix_web::{web, HttpRequest, HttpResponse}; use actix_web::{web, HttpRequest, HttpResponse};
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use diesel::NotFound; use diesel::NotFound;
use lemmy_db::{ use lemmy_db::{source::user::User, ApubObject, Followable};
source::{private_message::PrivateMessage, user::User},
ApubObject,
Followable,
};
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
community::{Community, CommunityFollower}, community::{Community, CommunityFollower},
private_message::PrivateMessage,
user::User_, user::User_,
}; };
use lemmy_structs::blocking; use lemmy_structs::blocking;

View file

@ -22,8 +22,8 @@ use activitystreams::{
}; };
use activitystreams_ext::{Ext1, Ext2}; use activitystreams_ext::{Ext1, Ext2};
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use lemmy_db::{source::activity::Activity, DbPool}; use lemmy_db::{source::activity::Activity_, DbPool};
use lemmy_db_schema::source::user::User_; use lemmy_db_schema::source::{activity::Activity, user::User_};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_utils::{location_info, settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -19,12 +19,11 @@ use activitystreams::{
prelude::*, prelude::*,
}; };
use anyhow::Context; use anyhow::Context;
use lemmy_db::{ use lemmy_db::{Crud, DbPool};
source::private_message::{PrivateMessage, PrivateMessageForm}, use lemmy_db_schema::source::{
Crud, private_message::{PrivateMessage, PrivateMessageForm},
DbPool, user::User_,
}; };
use lemmy_db_schema::source::user::User_;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, utils::convert_datetime, LemmyError}; use lemmy_utils::{location_info, utils::convert_datetime, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -1,36 +1,13 @@
use crate::Crud; use crate::Crud;
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::schema::activity; use lemmy_db_schema::source::activity::*;
use log::debug; use log::debug;
use serde::Serialize; use serde::Serialize;
use serde_json::Value;
use std::{ use std::{
fmt::Debug, fmt::Debug,
io::{Error as IoError, ErrorKind}, io::{Error as IoError, ErrorKind},
}; };
#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "activity"]
pub struct Activity {
pub id: i32,
pub data: Value,
pub local: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: Option<String>,
pub sensitive: Option<bool>,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "activity"]
pub struct ActivityForm {
pub data: Value,
pub local: bool,
pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: String,
pub sensitive: bool,
}
impl Crud<ActivityForm> for Activity { impl Crud<ActivityForm> for Activity {
fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::activity::dsl::*; use lemmy_db_schema::schema::activity::dsl::*;
@ -60,14 +37,27 @@ impl Crud<ActivityForm> for Activity {
} }
} }
impl Activity { pub trait Activity_ {
pub fn insert<T>( fn insert<T>(
conn: &PgConnection, conn: &PgConnection,
ap_id: String, ap_id: String,
data: &T, data: &T,
local: bool, local: bool,
sensitive: bool, sensitive: bool,
) -> Result<Self, IoError> ) -> Result<Activity, IoError>
where
T: Serialize + Debug;
fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Activity, Error>;
}
impl Activity_ for Activity {
fn insert<T>(
conn: &PgConnection,
ap_id: String,
data: &T,
local: bool,
sensitive: bool,
) -> Result<Activity, IoError>
where where
T: Serialize + Debug, T: Serialize + Debug,
{ {
@ -89,7 +79,7 @@ impl Activity {
} }
} }
pub fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> { fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Activity, Error> {
use lemmy_db_schema::schema::activity::dsl::*; use lemmy_db_schema::schema::activity::dsl::*;
activity.filter(ap_id.eq(object_id)).first::<Self>(conn) activity.filter(ap_id.eq(object_id)).first::<Self>(conn)
} }
@ -97,14 +87,11 @@ impl Activity {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
source::activity::{Activity, ActivityForm}, use lemmy_db_schema::source::{
tests::establish_unpooled_connection, activity::{Activity, ActivityForm},
Crud, user::{UserForm, User_},
ListingType,
SortType,
}; };
use lemmy_db_schema::source::user::{UserForm, User_};
use serde_json::Value; use serde_json::Value;
#[test] #[test]

View file

@ -1,20 +1,6 @@
use crate::Crud; use crate::Crud;
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::schema::{category, category::dsl::*}; use lemmy_db_schema::{schema::category::dsl::*, source::category::*};
use serde::Serialize;
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Clone)]
#[table_name = "category"]
pub struct Category {
pub id: i32,
pub name: String,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "category"]
pub struct CategoryForm {
pub name: String,
}
impl Crud<CategoryForm> for Category { impl Crud<CategoryForm> for Category {
fn read(conn: &PgConnection, category_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, category_id: i32) -> Result<Self, Error> {
@ -38,15 +24,20 @@ impl Crud<CategoryForm> for Category {
} }
} }
impl Category { pub trait Category_ {
pub fn list_all(conn: &PgConnection) -> Result<Vec<Self>, Error> { fn list_all(conn: &PgConnection) -> Result<Vec<Category>, Error>;
}
impl Category_ for Category {
fn list_all(conn: &PgConnection) -> Result<Vec<Category>, Error> {
category.load::<Self>(conn) category.load::<Self>(conn)
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{source::category::Category, tests::establish_unpooled_connection}; use crate::tests::establish_unpooled_connection;
use lemmy_db_schema::source::category::Category;
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -1,31 +1,9 @@
use crate::Reportable; use crate::Reportable;
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, schema::comment_report, source::comment::Comment}; use lemmy_db_schema::{
use serde::{Deserialize, Serialize}; naive_now,
source::comment_report::{CommentReport, CommentReportForm},
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)] };
#[belongs_to(Comment)]
#[table_name = "comment_report"]
pub struct CommentReport {
pub id: i32,
pub creator_id: i32,
pub comment_id: i32,
pub original_comment_text: String,
pub reason: String,
pub resolved: bool,
pub resolver_id: Option<i32>,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
}
#[derive(Insertable, AsChangeset, Clone)]
#[table_name = "comment_report"]
pub struct CommentReportForm {
pub creator_id: i32,
pub comment_id: i32,
pub original_comment_text: String,
pub reason: String,
}
impl Reportable<CommentReportForm> for CommentReport { impl Reportable<CommentReportForm> for CommentReport {
/// creates a comment report and returns it /// creates a comment report and returns it

View file

@ -1,37 +1,6 @@
use crate::Crud; use crate::Crud;
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::schema::{ use lemmy_db_schema::source::moderator::*;
mod_add,
mod_add_community,
mod_ban,
mod_ban_from_community,
mod_lock_post,
mod_remove_comment,
mod_remove_community,
mod_remove_post,
mod_sticky_post,
};
use serde::Serialize;
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_remove_post"]
pub struct ModRemovePost {
pub id: i32,
pub mod_user_id: i32,
pub post_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_post"]
pub struct ModRemovePostForm {
pub mod_user_id: i32,
pub post_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
}
impl Crud<ModRemovePostForm> for ModRemovePost { impl Crud<ModRemovePostForm> for ModRemovePost {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
@ -54,24 +23,6 @@ impl Crud<ModRemovePostForm> for ModRemovePost {
} }
} }
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_lock_post"]
pub struct ModLockPost {
pub id: i32,
pub mod_user_id: i32,
pub post_id: i32,
pub locked: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_lock_post"]
pub struct ModLockPostForm {
pub mod_user_id: i32,
pub post_id: i32,
pub locked: Option<bool>,
}
impl Crud<ModLockPostForm> for ModLockPost { impl Crud<ModLockPostForm> for ModLockPost {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::mod_lock_post::dsl::*; use lemmy_db_schema::schema::mod_lock_post::dsl::*;
@ -93,24 +44,6 @@ impl Crud<ModLockPostForm> for ModLockPost {
} }
} }
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_sticky_post"]
pub struct ModStickyPost {
pub id: i32,
pub mod_user_id: i32,
pub post_id: i32,
pub stickied: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_sticky_post"]
pub struct ModStickyPostForm {
pub mod_user_id: i32,
pub post_id: i32,
pub stickied: Option<bool>,
}
impl Crud<ModStickyPostForm> for ModStickyPost { impl Crud<ModStickyPostForm> for ModStickyPost {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::mod_sticky_post::dsl::*; use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
@ -132,26 +65,6 @@ impl Crud<ModStickyPostForm> for ModStickyPost {
} }
} }
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_remove_comment"]
pub struct ModRemoveComment {
pub id: i32,
pub mod_user_id: i32,
pub comment_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_comment"]
pub struct ModRemoveCommentForm {
pub mod_user_id: i32,
pub comment_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
}
impl Crud<ModRemoveCommentForm> for ModRemoveComment { impl Crud<ModRemoveCommentForm> for ModRemoveComment {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::mod_remove_comment::dsl::*; use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
@ -173,28 +86,6 @@ impl Crud<ModRemoveCommentForm> for ModRemoveComment {
} }
} }
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_remove_community"]
pub struct ModRemoveCommunity {
pub id: i32,
pub mod_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_community"]
pub struct ModRemoveCommunityForm {
pub mod_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
}
impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity { impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::mod_remove_community::dsl::*; use lemmy_db_schema::schema::mod_remove_community::dsl::*;
@ -220,30 +111,6 @@ impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
} }
} }
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_ban_from_community"]
pub struct ModBanFromCommunity {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_ban_from_community"]
pub struct ModBanFromCommunityForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
}
impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity { impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::mod_ban_from_community::dsl::*; use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
@ -269,28 +136,6 @@ impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
} }
} }
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_ban"]
pub struct ModBan {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_ban"]
pub struct ModBanForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
}
impl Crud<ModBanForm> for ModBan { impl Crud<ModBanForm> for ModBan {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::mod_ban::dsl::*; use lemmy_db_schema::schema::mod_ban::dsl::*;
@ -310,26 +155,6 @@ impl Crud<ModBanForm> for ModBan {
} }
} }
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_add_community"]
pub struct ModAddCommunity {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_add_community"]
pub struct ModAddCommunityForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub removed: Option<bool>,
}
impl Crud<ModAddCommunityForm> for ModAddCommunity { impl Crud<ModAddCommunityForm> for ModAddCommunity {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::mod_add_community::dsl::*; use lemmy_db_schema::schema::mod_add_community::dsl::*;
@ -351,24 +176,6 @@ impl Crud<ModAddCommunityForm> for ModAddCommunity {
} }
} }
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_add"]
pub struct ModAdd {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_add"]
pub struct ModAddForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub removed: Option<bool>,
}
impl Crud<ModAddForm> for ModAdd { impl Crud<ModAddForm> for ModAdd {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::mod_add::dsl::*; use lemmy_db_schema::schema::mod_add::dsl::*;
@ -390,14 +197,8 @@ impl Crud<ModAddForm> for ModAdd {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
source::moderator::*, use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
// use Crud; // use Crud;
#[test] #[test]

View file

@ -1,24 +1,8 @@
use crate::Crud; use crate::Crud;
use diesel::{dsl::*, result::Error, PgConnection, *}; use diesel::{dsl::*, result::Error, PgConnection, *};
use lemmy_db_schema::schema::{password_reset_request, password_reset_request::dsl::*}; use lemmy_db_schema::{schema::password_reset_request::dsl::*, source::password_reset_request::*};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "password_reset_request"]
pub struct PasswordResetRequest {
pub id: i32,
pub user_id: i32,
pub token_encrypted: String,
pub published: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "password_reset_request"]
pub struct PasswordResetRequestForm {
pub user_id: i32,
pub token_encrypted: String,
}
impl Crud<PasswordResetRequestForm> for PasswordResetRequest { impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
fn read(conn: &PgConnection, password_reset_request_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, password_reset_request_id: i32) -> Result<Self, Error> {
password_reset_request password_reset_request
@ -41,11 +25,24 @@ impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
} }
} }
impl PasswordResetRequest { pub trait PasswordResetRequest_ {
pub fn create_token(conn: &PgConnection, from_user_id: i32, token: &str) -> Result<Self, Error> { fn create_token(
conn: &PgConnection,
from_user_id: i32,
token: &str,
) -> Result<PasswordResetRequest, Error>;
fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error>;
}
impl PasswordResetRequest_ for PasswordResetRequest {
fn create_token(
conn: &PgConnection,
from_user_id: i32,
token: &str,
) -> Result<PasswordResetRequest, Error> {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
hasher.update(token); hasher.update(token);
let token_hash: String = PasswordResetRequest::bytes_to_hex(hasher.finalize().to_vec()); let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
let form = PasswordResetRequestForm { let form = PasswordResetRequestForm {
user_id: from_user_id, user_id: from_user_id,
@ -54,35 +51,29 @@ impl PasswordResetRequest {
Self::create(&conn, &form) Self::create(&conn, &form)
} }
pub fn read_from_token(conn: &PgConnection, token: &str) -> Result<Self, Error> { fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error> {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
hasher.update(token); hasher.update(token);
let token_hash: String = PasswordResetRequest::bytes_to_hex(hasher.finalize().to_vec()); let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
password_reset_request password_reset_request
.filter(token_encrypted.eq(token_hash)) .filter(token_encrypted.eq(token_hash))
.filter(published.gt(now - 1.days())) .filter(published.gt(now - 1.days()))
.first::<Self>(conn) .first::<Self>(conn)
} }
}
fn bytes_to_hex(bytes: Vec<u8>) -> String { fn bytes_to_hex(bytes: Vec<u8>) -> String {
let mut str = String::new(); let mut str = String::new();
for byte in bytes { for byte in bytes {
str = format!("{}{:02x}", str, byte); str = format!("{}{:02x}", str, byte);
}
str
} }
str
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
source::password_reset_request::PasswordResetRequest, use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
use lemmy_db_schema::source::user::*;
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -1,35 +1,6 @@
use crate::Reportable; use crate::Reportable;
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, schema::post_report, source::post::Post}; use lemmy_db_schema::{naive_now, source::post_report::*};
use serde::{Deserialize, Serialize};
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
#[belongs_to(Post)]
#[table_name = "post_report"]
pub struct PostReport {
pub id: i32,
pub creator_id: i32,
pub post_id: i32,
pub original_post_name: String,
pub original_post_url: Option<String>,
pub original_post_body: Option<String>,
pub reason: String,
pub resolved: bool,
pub resolver_id: Option<i32>,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
}
#[derive(Insertable, AsChangeset, Clone)]
#[table_name = "post_report"]
pub struct PostReportForm {
pub creator_id: i32,
pub post_id: i32,
pub original_post_name: String,
pub original_post_url: Option<String>,
pub original_post_body: Option<String>,
pub reason: String,
}
impl Reportable<PostReportForm> for PostReport { impl Reportable<PostReportForm> for PostReport {
/// creates a post report and returns it /// creates a post report and returns it

View file

@ -1,36 +1,6 @@
use crate::{ApubObject, Crud}; use crate::{ApubObject, Crud};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, schema::private_message}; use lemmy_db_schema::{naive_now, source::private_message::*};
use serde::Serialize;
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "private_message"]
pub struct PrivateMessage {
pub id: i32,
pub creator_id: i32,
pub recipient_id: i32,
pub content: String,
pub deleted: bool,
pub read: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: String,
pub local: bool,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "private_message"]
pub struct PrivateMessageForm {
pub creator_id: i32,
pub recipient_id: i32,
pub content: String,
pub deleted: Option<bool>,
pub read: Option<bool>,
pub published: Option<chrono::NaiveDateTime>,
pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: Option<String>,
pub local: bool,
}
impl Crud<PrivateMessageForm> for PrivateMessage { impl Crud<PrivateMessageForm> for PrivateMessage {
fn read(conn: &PgConnection, private_message_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, private_message_id: i32) -> Result<Self, Error> {
@ -79,12 +49,39 @@ impl ApubObject<PrivateMessageForm> for PrivateMessage {
} }
} }
impl PrivateMessage { pub trait PrivateMessage_ {
pub fn update_ap_id( fn update_ap_id(
conn: &PgConnection, conn: &PgConnection,
private_message_id: i32, private_message_id: i32,
apub_id: String, apub_id: String,
) -> Result<Self, Error> { ) -> Result<PrivateMessage, Error>;
fn update_content(
conn: &PgConnection,
private_message_id: i32,
new_content: &str,
) -> Result<PrivateMessage, Error>;
fn update_deleted(
conn: &PgConnection,
private_message_id: i32,
new_deleted: bool,
) -> Result<PrivateMessage, Error>;
fn update_read(
conn: &PgConnection,
private_message_id: i32,
new_read: bool,
) -> Result<PrivateMessage, Error>;
fn mark_all_as_read(
conn: &PgConnection,
for_recipient_id: i32,
) -> Result<Vec<PrivateMessage>, Error>;
}
impl PrivateMessage_ for PrivateMessage {
fn update_ap_id(
conn: &PgConnection,
private_message_id: i32,
apub_id: String,
) -> Result<PrivateMessage, Error> {
use lemmy_db_schema::schema::private_message::dsl::*; use lemmy_db_schema::schema::private_message::dsl::*;
diesel::update(private_message.find(private_message_id)) diesel::update(private_message.find(private_message_id))
@ -92,40 +89,43 @@ impl PrivateMessage {
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
pub fn update_content( fn update_content(
conn: &PgConnection, conn: &PgConnection,
private_message_id: i32, private_message_id: i32,
new_content: &str, new_content: &str,
) -> Result<Self, Error> { ) -> Result<PrivateMessage, Error> {
use lemmy_db_schema::schema::private_message::dsl::*; use lemmy_db_schema::schema::private_message::dsl::*;
diesel::update(private_message.find(private_message_id)) diesel::update(private_message.find(private_message_id))
.set((content.eq(new_content), updated.eq(naive_now()))) .set((content.eq(new_content), updated.eq(naive_now())))
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
pub fn update_deleted( fn update_deleted(
conn: &PgConnection, conn: &PgConnection,
private_message_id: i32, private_message_id: i32,
new_deleted: bool, new_deleted: bool,
) -> Result<Self, Error> { ) -> Result<PrivateMessage, Error> {
use lemmy_db_schema::schema::private_message::dsl::*; use lemmy_db_schema::schema::private_message::dsl::*;
diesel::update(private_message.find(private_message_id)) diesel::update(private_message.find(private_message_id))
.set(deleted.eq(new_deleted)) .set(deleted.eq(new_deleted))
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
pub fn update_read( fn update_read(
conn: &PgConnection, conn: &PgConnection,
private_message_id: i32, private_message_id: i32,
new_read: bool, new_read: bool,
) -> Result<Self, Error> { ) -> Result<PrivateMessage, Error> {
use lemmy_db_schema::schema::private_message::dsl::*; use lemmy_db_schema::schema::private_message::dsl::*;
diesel::update(private_message.find(private_message_id)) diesel::update(private_message.find(private_message_id))
.set(read.eq(new_read)) .set(read.eq(new_read))
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
pub fn mark_all_as_read(conn: &PgConnection, for_recipient_id: i32) -> Result<Vec<Self>, Error> { fn mark_all_as_read(
conn: &PgConnection,
for_recipient_id: i32,
) -> Result<Vec<PrivateMessage>, Error> {
use lemmy_db_schema::schema::private_message::dsl::*; use lemmy_db_schema::schema::private_message::dsl::*;
diesel::update( diesel::update(
private_message private_message
@ -139,13 +139,8 @@ impl PrivateMessage {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{tests::establish_unpooled_connection, ListingType, SortType};
source::private_message::*, use lemmy_db_schema::source::{private_message::*, user::*};
tests::establish_unpooled_connection,
ListingType,
SortType,
};
use lemmy_db_schema::source::user::*;
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -1,38 +1,6 @@
use crate::Crud; use crate::Crud;
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, schema::site}; use lemmy_db_schema::{naive_now, source::site::*};
use serde::Serialize;
#[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize)]
#[table_name = "site"]
pub struct Site {
pub id: i32,
pub name: String,
pub description: Option<String>,
pub creator_id: i32,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub enable_downvotes: bool,
pub open_registration: bool,
pub enable_nsfw: bool,
pub icon: Option<String>,
pub banner: Option<String>,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "site"]
pub struct SiteForm {
pub name: String,
pub description: Option<String>,
pub creator_id: i32,
pub updated: Option<chrono::NaiveDateTime>,
pub enable_downvotes: bool,
pub open_registration: bool,
pub enable_nsfw: bool,
// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
pub icon: Option<Option<String>>,
pub banner: Option<Option<String>>,
}
impl Crud<SiteForm> for Site { impl Crud<SiteForm> for Site {
fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
@ -53,8 +21,12 @@ impl Crud<SiteForm> for Site {
} }
} }
impl Site { pub trait Site_ {
pub fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Self, Error> { fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error>;
}
impl Site_ for Site {
fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error> {
use lemmy_db_schema::schema::site::dsl::*; use lemmy_db_schema::schema::site::dsl::*;
diesel::update(site.find(1)) diesel::update(site.find(1))
.set((creator_id.eq(new_creator_id), updated.eq(naive_now()))) .set((creator_id.eq(new_creator_id), updated.eq(naive_now())))

View file

@ -1,26 +1,6 @@
use crate::Crud; use crate::Crud;
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{schema::user_mention, source::comment::Comment}; use lemmy_db_schema::source::user_mention::*;
use serde::Serialize;
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
#[belongs_to(Comment)]
#[table_name = "user_mention"]
pub struct UserMention {
pub id: i32,
pub recipient_id: i32,
pub comment_id: i32,
pub read: bool,
pub published: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "user_mention"]
pub struct UserMentionForm {
pub recipient_id: i32,
pub comment_id: i32,
pub read: Option<bool>,
}
impl Crud<UserMentionForm> for UserMention { impl Crud<UserMentionForm> for UserMention {
fn read(conn: &PgConnection, user_mention_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, user_mention_id: i32) -> Result<Self, Error> {
@ -52,19 +32,34 @@ impl Crud<UserMentionForm> for UserMention {
} }
} }
impl UserMention { pub trait UserMention_ {
pub fn update_read( fn update_read(
conn: &PgConnection, conn: &PgConnection,
user_mention_id: i32, user_mention_id: i32,
new_read: bool, new_read: bool,
) -> Result<Self, Error> { ) -> Result<UserMention, Error>;
fn mark_all_as_read(
conn: &PgConnection,
for_recipient_id: i32,
) -> Result<Vec<UserMention>, Error>;
}
impl UserMention_ for UserMention {
fn update_read(
conn: &PgConnection,
user_mention_id: i32,
new_read: bool,
) -> Result<UserMention, Error> {
use lemmy_db_schema::schema::user_mention::dsl::*; use lemmy_db_schema::schema::user_mention::dsl::*;
diesel::update(user_mention.find(user_mention_id)) diesel::update(user_mention.find(user_mention_id))
.set(read.eq(new_read)) .set(read.eq(new_read))
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
pub fn mark_all_as_read(conn: &PgConnection, for_recipient_id: i32) -> Result<Vec<Self>, Error> { fn mark_all_as_read(
conn: &PgConnection,
for_recipient_id: i32,
) -> Result<Vec<UserMention>, Error> {
use lemmy_db_schema::schema::user_mention::dsl::*; use lemmy_db_schema::schema::user_mention::dsl::*;
diesel::update( diesel::update(
user_mention user_mention
@ -78,18 +73,13 @@ impl UserMention {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
source::user_mention::*,
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
comment::*, comment::*,
community::{Community, CommunityForm}, community::{Community, CommunityForm},
post::*, post::*,
user::*, user::*,
user_mention::*,
}; };
#[test] #[test]

View file

@ -1,15 +1,10 @@
use crate::{ use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
limit_and_offset,
source::comment_report::CommentReport,
views::ViewToVec,
MaybeOptional,
ToSafe,
};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2}, schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2},
source::{ source::{
comment::Comment, comment::Comment,
comment_report::CommentReport,
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
post::Post, post::Post,
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_}, user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},

View file

@ -3,7 +3,6 @@ use crate::{
functions::hot_rank, functions::hot_rank,
fuzzy_search, fuzzy_search,
limit_and_offset, limit_and_offset,
source::category::Category,
views::ViewToVec, views::ViewToVec,
MaybeOptional, MaybeOptional,
SortType, SortType,
@ -13,6 +12,7 @@ use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{category, community, community_aggregates, community_follower, user_}, schema::{category, community, community_aggregates, community_follower, user_},
source::{ source::{
category::Category,
community::{Community, CommunityFollower, CommunitySafe}, community::{Community, CommunityFollower, CommunitySafe},
user::{UserSafe, User_}, user::{UserSafe, User_},
}, },

View file

@ -1,9 +1,10 @@
use crate::{limit_and_offset, source::moderator::ModAddCommunity, views::ViewToVec, ToSafe}; use crate::{limit_and_offset, views::ViewToVec, ToSafe};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, mod_add_community, user_, user_alias_1}, schema::{community, mod_add_community, user_, user_alias_1},
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModAddCommunity,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
}, },
}; };

View file

@ -1,8 +1,11 @@
use crate::{limit_and_offset, source::moderator::ModAdd, views::ViewToVec, ToSafe}; use crate::{limit_and_offset, views::ViewToVec, ToSafe};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{mod_add, user_, user_alias_1}, schema::{mod_add, user_, user_alias_1},
source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, source::{
moderator::ModAdd,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -1,9 +1,10 @@
use crate::{limit_and_offset, source::moderator::ModBanFromCommunity, views::ViewToVec, ToSafe}; use crate::{limit_and_offset, views::ViewToVec, ToSafe};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, mod_ban_from_community, user_, user_alias_1}, schema::{community, mod_ban_from_community, user_, user_alias_1},
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModBanFromCommunity,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
}, },
}; };

View file

@ -1,8 +1,11 @@
use crate::{limit_and_offset, source::moderator::ModBan, views::ViewToVec, ToSafe}; use crate::{limit_and_offset, views::ViewToVec, ToSafe};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{mod_ban, user_, user_alias_1}, schema::{mod_ban, user_, user_alias_1},
source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, source::{
moderator::ModBan,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -1,9 +1,10 @@
use crate::{limit_and_offset, source::moderator::ModLockPost, views::ViewToVec, ToSafe}; use crate::{limit_and_offset, views::ViewToVec, ToSafe};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, mod_lock_post, post, user_}, schema::{community, mod_lock_post, post, user_},
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModLockPost,
post::Post, post::Post,
user::{UserSafe, User_}, user::{UserSafe, User_},
}, },

View file

@ -1,10 +1,11 @@
use crate::{limit_and_offset, source::moderator::ModRemoveComment, views::ViewToVec, ToSafe}; use crate::{limit_and_offset, views::ViewToVec, ToSafe};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{comment, community, mod_remove_comment, post, user_, user_alias_1}, schema::{comment, community, mod_remove_comment, post, user_, user_alias_1},
source::{ source::{
comment::Comment, comment::Comment,
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModRemoveComment,
post::Post, post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
}, },

View file

@ -1,9 +1,10 @@
use crate::{limit_and_offset, source::moderator::ModRemoveCommunity, views::ViewToVec, ToSafe}; use crate::{limit_and_offset, views::ViewToVec, ToSafe};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, mod_remove_community, user_}, schema::{community, mod_remove_community, user_},
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModRemoveCommunity,
user::{UserSafe, User_}, user::{UserSafe, User_},
}, },
}; };

View file

@ -1,9 +1,10 @@
use crate::{limit_and_offset, source::moderator::ModRemovePost, views::ViewToVec, ToSafe}; use crate::{limit_and_offset, views::ViewToVec, ToSafe};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, mod_remove_post, post, user_}, schema::{community, mod_remove_post, post, user_},
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModRemovePost,
post::Post, post::Post,
user::{UserSafe, User_}, user::{UserSafe, User_},
}, },

View file

@ -1,9 +1,10 @@
use crate::{limit_and_offset, source::moderator::ModStickyPost, views::ViewToVec, ToSafe}; use crate::{limit_and_offset, views::ViewToVec, ToSafe};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, mod_sticky_post, post, user_}, schema::{community, mod_sticky_post, post, user_},
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModStickyPost,
post::Post, post::Post,
user::{UserSafe, User_}, user::{UserSafe, User_},
}, },

View file

@ -1,16 +1,11 @@
use crate::{ use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
limit_and_offset,
source::post_report::PostReport,
views::ViewToVec,
MaybeOptional,
ToSafe,
};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, post, post_report, user_, user_alias_1, user_alias_2}, schema::{community, post, post_report, user_, user_alias_1, user_alias_2},
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
post::Post, post::Post,
post_report::PostReport,
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_}, user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
}, },
}; };

View file

@ -1,14 +1,11 @@
use crate::{ use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
limit_and_offset,
source::private_message::PrivateMessage,
views::ViewToVec,
MaybeOptional,
ToSafe,
};
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{private_message, user_, user_alias_1}, schema::{private_message, user_, user_alias_1},
source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, source::{
private_message::PrivateMessage,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -1,8 +1,11 @@
use crate::{source::site::Site, ToSafe}; use crate::ToSafe;
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{site, user_}, schema::{site, user_},
source::user::{UserSafe, User_}, source::{
site::Site,
user::{UserSafe, User_},
},
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -2,7 +2,6 @@ use crate::{
aggregates::comment_aggregates::CommentAggregates, aggregates::comment_aggregates::CommentAggregates,
functions::hot_rank, functions::hot_rank,
limit_and_offset, limit_and_offset,
source::user_mention::UserMention,
views::ViewToVec, views::ViewToVec,
MaybeOptional, MaybeOptional,
SortType, SortType,
@ -28,6 +27,7 @@ use lemmy_db_schema::{
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan}, community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
post::Post, post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
user_mention::UserMention,
}, },
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -0,0 +1,25 @@
use crate::schema::activity;
use serde_json::Value;
use std::fmt::Debug;
#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "activity"]
pub struct Activity {
pub id: i32,
pub data: Value,
pub local: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: Option<String>,
pub sensitive: Option<bool>,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "activity"]
pub struct ActivityForm {
pub data: Value,
pub local: bool,
pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: String,
pub sensitive: bool,
}

View file

@ -0,0 +1,15 @@
use crate::schema::category;
use serde::Serialize;
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Clone)]
#[table_name = "category"]
pub struct Category {
pub id: i32,
pub name: String,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "category"]
pub struct CategoryForm {
pub name: String,
}

View file

@ -0,0 +1,26 @@
use crate::{schema::comment_report, source::comment::Comment};
use serde::{Deserialize, Serialize};
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
#[belongs_to(Comment)]
#[table_name = "comment_report"]
pub struct CommentReport {
pub id: i32,
pub creator_id: i32,
pub comment_id: i32,
pub original_comment_text: String,
pub reason: String,
pub resolved: bool,
pub resolver_id: Option<i32>,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
}
#[derive(Insertable, AsChangeset, Clone)]
#[table_name = "comment_report"]
pub struct CommentReportForm {
pub creator_id: i32,
pub comment_id: i32,
pub original_comment_text: String,
pub reason: String,
}

View file

@ -1,4 +1,13 @@
pub mod activity;
pub mod category;
pub mod comment; pub mod comment;
pub mod comment_report;
pub mod community; pub mod community;
pub mod moderator;
pub mod password_reset_request;
pub mod post; pub mod post;
pub mod post_report;
pub mod private_message;
pub mod site;
pub mod user; pub mod user;
pub mod user_mention;

View file

@ -0,0 +1,194 @@
use crate::schema::{
mod_add,
mod_add_community,
mod_ban,
mod_ban_from_community,
mod_lock_post,
mod_remove_comment,
mod_remove_community,
mod_remove_post,
mod_sticky_post,
};
use serde::Serialize;
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_remove_post"]
pub struct ModRemovePost {
pub id: i32,
pub mod_user_id: i32,
pub post_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_post"]
pub struct ModRemovePostForm {
pub mod_user_id: i32,
pub post_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_lock_post"]
pub struct ModLockPost {
pub id: i32,
pub mod_user_id: i32,
pub post_id: i32,
pub locked: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_lock_post"]
pub struct ModLockPostForm {
pub mod_user_id: i32,
pub post_id: i32,
pub locked: Option<bool>,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_sticky_post"]
pub struct ModStickyPost {
pub id: i32,
pub mod_user_id: i32,
pub post_id: i32,
pub stickied: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_sticky_post"]
pub struct ModStickyPostForm {
pub mod_user_id: i32,
pub post_id: i32,
pub stickied: Option<bool>,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_remove_comment"]
pub struct ModRemoveComment {
pub id: i32,
pub mod_user_id: i32,
pub comment_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_comment"]
pub struct ModRemoveCommentForm {
pub mod_user_id: i32,
pub comment_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_remove_community"]
pub struct ModRemoveCommunity {
pub id: i32,
pub mod_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_community"]
pub struct ModRemoveCommunityForm {
pub mod_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_ban_from_community"]
pub struct ModBanFromCommunity {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_ban_from_community"]
pub struct ModBanFromCommunityForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_ban"]
pub struct ModBan {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_ban"]
pub struct ModBanForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_add_community"]
pub struct ModAddCommunity {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_add_community"]
pub struct ModAddCommunityForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub removed: Option<bool>,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_add"]
pub struct ModAdd {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_add"]
pub struct ModAddForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub removed: Option<bool>,
}

View file

@ -0,0 +1,17 @@
use crate::schema::password_reset_request;
#[derive(Queryable, Identifiable, PartialEq, Debug)]
#[table_name = "password_reset_request"]
pub struct PasswordResetRequest {
pub id: i32,
pub user_id: i32,
pub token_encrypted: String,
pub published: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "password_reset_request"]
pub struct PasswordResetRequestForm {
pub user_id: i32,
pub token_encrypted: String,
}

View file

@ -0,0 +1,30 @@
use crate::{schema::post_report, source::post::Post};
use serde::{Deserialize, Serialize};
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
#[belongs_to(Post)]
#[table_name = "post_report"]
pub struct PostReport {
pub id: i32,
pub creator_id: i32,
pub post_id: i32,
pub original_post_name: String,
pub original_post_url: Option<String>,
pub original_post_body: Option<String>,
pub reason: String,
pub resolved: bool,
pub resolver_id: Option<i32>,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
}
#[derive(Insertable, AsChangeset, Clone)]
#[table_name = "post_report"]
pub struct PostReportForm {
pub creator_id: i32,
pub post_id: i32,
pub original_post_name: String,
pub original_post_url: Option<String>,
pub original_post_body: Option<String>,
pub reason: String,
}

View file

@ -0,0 +1,31 @@
use crate::schema::private_message;
use serde::Serialize;
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "private_message"]
pub struct PrivateMessage {
pub id: i32,
pub creator_id: i32,
pub recipient_id: i32,
pub content: String,
pub deleted: bool,
pub read: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: String,
pub local: bool,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "private_message"]
pub struct PrivateMessageForm {
pub creator_id: i32,
pub recipient_id: i32,
pub content: String,
pub deleted: Option<bool>,
pub read: Option<bool>,
pub published: Option<chrono::NaiveDateTime>,
pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: Option<String>,
pub local: bool,
}

View file

@ -0,0 +1,33 @@
use crate::schema::site;
use serde::Serialize;
#[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize)]
#[table_name = "site"]
pub struct Site {
pub id: i32,
pub name: String,
pub description: Option<String>,
pub creator_id: i32,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub enable_downvotes: bool,
pub open_registration: bool,
pub enable_nsfw: bool,
pub icon: Option<String>,
pub banner: Option<String>,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "site"]
pub struct SiteForm {
pub name: String,
pub description: Option<String>,
pub creator_id: i32,
pub updated: Option<chrono::NaiveDateTime>,
pub enable_downvotes: bool,
pub open_registration: bool,
pub enable_nsfw: bool,
// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
pub icon: Option<Option<String>>,
pub banner: Option<Option<String>>,
}

View file

@ -0,0 +1,21 @@
use crate::{schema::user_mention, source::comment::Comment};
use serde::Serialize;
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
#[belongs_to(Comment)]
#[table_name = "user_mention"]
pub struct UserMention {
pub id: i32,
pub recipient_id: i32,
pub comment_id: i32,
pub read: bool,
pub published: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "user_mention"]
pub struct UserMentionForm {
pub recipient_id: i32,
pub comment_id: i32,
pub read: Option<bool>,
}

View file

@ -6,15 +6,13 @@ pub mod user;
pub mod websocket; pub mod websocket;
use diesel::PgConnection; use diesel::PgConnection;
use lemmy_db::{ use lemmy_db::{source::user::User, Crud, DbPool};
source::{ use lemmy_db_schema::source::{
user::User, comment::Comment,
user_mention::{UserMention, UserMentionForm}, post::Post,
}, user::User_,
Crud, user_mention::{UserMention, UserMentionForm},
DbPool,
}; };
use lemmy_db_schema::source::{comment::Comment, post::Post, user::User_};
use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError}; use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
use log::error; use log::error;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -1,6 +1,5 @@
use lemmy_db::{ use lemmy_db::{
aggregates::site_aggregates::SiteAggregates, aggregates::site_aggregates::SiteAggregates,
source::category::*,
views::{ views::{
comment_view::CommentView, comment_view::CommentView,
community::community_view::CommunityView, community::community_view::CommunityView,
@ -20,7 +19,7 @@ use lemmy_db::{
user_view::UserViewSafe, user_view::UserViewSafe,
}, },
}; };
use lemmy_db_schema::source::user::User_; use lemmy_db_schema::source::{category::*, user::User_};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -4,7 +4,7 @@ use diesel::{
*, *,
}; };
use lemmy_db::{ use lemmy_db::{
source::{comment::Comment_, post::Post_, private_message::PrivateMessage}, source::{comment::Comment_, post::Post_, private_message::PrivateMessage_},
Crud, Crud,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -13,6 +13,7 @@ use lemmy_db_schema::{
comment::Comment, comment::Comment,
community::{Community, CommunityForm}, community::{Community, CommunityForm},
post::Post, post::Post,
private_message::PrivateMessage,
user::{UserForm, User_}, user::{UserForm, User_},
}, },
}; };