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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ use lemmy_apub::fetcher::search_by_apub_id;
use lemmy_db::{
aggregates::site_aggregates::SiteAggregates,
diesel_option_overwrite,
source::{category::*, moderator::*, site::*},
source::{category::Category_, site::Site_},
views::{
comment_view::CommentQueryBuilder,
community::community_view::CommunityQueryBuilder,
@ -35,7 +35,14 @@ use lemmy_db::{
SearchType,
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_utils::{
location_info,

View file

@ -19,13 +19,11 @@ use lemmy_db::{
source::{
comment::Comment_,
community::Community_,
moderator::*,
password_reset_request::*,
password_reset_request::PasswordResetRequest_,
post::Post_,
private_message::*,
site::*,
private_message::PrivateMessage_,
user::User,
user_mention::*,
user_mention::UserMention_,
},
views::{
comment_report_view::CommentReportView,
@ -49,7 +47,17 @@ use lemmy_db::{
};
use lemmy_db_schema::{
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_utils::{

View file

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

View file

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

View file

@ -1,7 +1,8 @@
use activitystreams::unparsed::UnparsedMutExt;
use activitystreams_ext::UnparsedExtension;
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 serde::{Deserialize, Serialize};

View file

@ -1,6 +1,7 @@
use crate::APUB_JSON_CONTENT_TYPE;
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_utils::{settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,36 +1,13 @@
use crate::Crud;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::schema::activity;
use lemmy_db_schema::source::activity::*;
use log::debug;
use serde::Serialize;
use serde_json::Value;
use std::{
fmt::Debug,
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 {
fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::activity::dsl::*;
@ -60,14 +37,27 @@ impl Crud<ActivityForm> for Activity {
}
}
impl Activity {
pub fn insert<T>(
pub trait Activity_ {
fn insert<T>(
conn: &PgConnection,
ap_id: String,
data: &T,
local: 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
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::*;
activity.filter(ap_id.eq(object_id)).first::<Self>(conn)
}
@ -97,14 +87,11 @@ impl Activity {
#[cfg(test)]
mod tests {
use crate::{
source::activity::{Activity, ActivityForm},
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
use lemmy_db_schema::source::{
activity::{Activity, ActivityForm},
user::{UserForm, User_},
};
use lemmy_db_schema::source::user::{UserForm, User_};
use serde_json::Value;
#[test]

View file

@ -1,20 +1,6 @@
use crate::Crud;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::schema::{category, category::dsl::*};
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,
}
use lemmy_db_schema::{schema::category::dsl::*, source::category::*};
impl Crud<CategoryForm> for Category {
fn read(conn: &PgConnection, category_id: i32) -> Result<Self, Error> {
@ -38,15 +24,20 @@ impl Crud<CategoryForm> for Category {
}
}
impl Category {
pub fn list_all(conn: &PgConnection) -> Result<Vec<Self>, Error> {
pub trait Category_ {
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)
}
}
#[cfg(test)]
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]
fn test_crud() {

View file

@ -1,31 +1,9 @@
use crate::Reportable;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, 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,
}
use lemmy_db_schema::{
naive_now,
source::comment_report::{CommentReport, CommentReportForm},
};
impl Reportable<CommentReportForm> for CommentReport {
/// creates a comment report and returns it

View file

@ -1,37 +1,6 @@
use crate::Crud;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::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>,
}
use lemmy_db_schema::source::moderator::*;
impl Crud<ModRemovePostForm> for ModRemovePost {
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 {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
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 {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
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 {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
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 {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
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 {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
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 {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
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 {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
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 {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::mod_add::dsl::*;
@ -390,14 +197,8 @@ impl Crud<ModAddForm> for ModAdd {
#[cfg(test)]
mod tests {
use crate::{
source::moderator::*,
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
// use Crud;
#[test]

View file

@ -1,24 +1,8 @@
use crate::Crud;
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};
#[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 {
fn read(conn: &PgConnection, password_reset_request_id: i32) -> Result<Self, Error> {
password_reset_request
@ -41,11 +25,24 @@ impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
}
}
impl PasswordResetRequest {
pub fn create_token(conn: &PgConnection, from_user_id: i32, token: &str) -> Result<Self, Error> {
pub trait PasswordResetRequest_ {
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();
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 {
user_id: from_user_id,
@ -54,35 +51,29 @@ impl PasswordResetRequest {
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();
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
.filter(token_encrypted.eq(token_hash))
.filter(published.gt(now - 1.days()))
.first::<Self>(conn)
}
}
fn bytes_to_hex(bytes: Vec<u8>) -> String {
fn bytes_to_hex(bytes: Vec<u8>) -> String {
let mut str = String::new();
for byte in bytes {
str = format!("{}{:02x}", str, byte);
}
str
}
}
#[cfg(test)]
mod tests {
use crate::{
source::password_reset_request::PasswordResetRequest,
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
use lemmy_db_schema::source::user::*;
use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
#[test]
fn test_crud() {

View file

@ -1,35 +1,6 @@
use crate::Reportable;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, 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,
}
use lemmy_db_schema::{naive_now, source::post_report::*};
impl Reportable<PostReportForm> for PostReport {
/// creates a post report and returns it

View file

@ -1,36 +1,6 @@
use crate::{ApubObject, Crud};
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, 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,
}
use lemmy_db_schema::{naive_now, source::private_message::*};
impl Crud<PrivateMessageForm> for PrivateMessage {
fn read(conn: &PgConnection, private_message_id: i32) -> Result<Self, Error> {
@ -79,12 +49,39 @@ impl ApubObject<PrivateMessageForm> for PrivateMessage {
}
}
impl PrivateMessage {
pub fn update_ap_id(
pub trait PrivateMessage_ {
fn update_ap_id(
conn: &PgConnection,
private_message_id: i32,
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::*;
diesel::update(private_message.find(private_message_id))
@ -92,40 +89,43 @@ impl PrivateMessage {
.get_result::<Self>(conn)
}
pub fn update_content(
fn update_content(
conn: &PgConnection,
private_message_id: i32,
new_content: &str,
) -> Result<Self, Error> {
) -> Result<PrivateMessage, Error> {
use lemmy_db_schema::schema::private_message::dsl::*;
diesel::update(private_message.find(private_message_id))
.set((content.eq(new_content), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
pub fn update_deleted(
fn update_deleted(
conn: &PgConnection,
private_message_id: i32,
new_deleted: bool,
) -> Result<Self, Error> {
) -> Result<PrivateMessage, Error> {
use lemmy_db_schema::schema::private_message::dsl::*;
diesel::update(private_message.find(private_message_id))
.set(deleted.eq(new_deleted))
.get_result::<Self>(conn)
}
pub fn update_read(
fn update_read(
conn: &PgConnection,
private_message_id: i32,
new_read: bool,
) -> Result<Self, Error> {
) -> Result<PrivateMessage, Error> {
use lemmy_db_schema::schema::private_message::dsl::*;
diesel::update(private_message.find(private_message_id))
.set(read.eq(new_read))
.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::*;
diesel::update(
private_message
@ -139,13 +139,8 @@ impl PrivateMessage {
#[cfg(test)]
mod tests {
use crate::{
source::private_message::*,
tests::establish_unpooled_connection,
ListingType,
SortType,
};
use lemmy_db_schema::source::user::*;
use crate::{tests::establish_unpooled_connection, ListingType, SortType};
use lemmy_db_schema::source::{private_message::*, user::*};
#[test]
fn test_crud() {

View file

@ -1,38 +1,6 @@
use crate::Crud;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, 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>>,
}
use lemmy_db_schema::{naive_now, source::site::*};
impl Crud<SiteForm> for Site {
fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
@ -53,8 +21,12 @@ impl Crud<SiteForm> for Site {
}
}
impl Site {
pub fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Self, Error> {
pub trait Site_ {
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::*;
diesel::update(site.find(1))
.set((creator_id.eq(new_creator_id), updated.eq(naive_now())))

View file

@ -1,26 +1,6 @@
use crate::Crud;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{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>,
}
use lemmy_db_schema::source::user_mention::*;
impl Crud<UserMentionForm> for UserMention {
fn read(conn: &PgConnection, user_mention_id: i32) -> Result<Self, Error> {
@ -52,19 +32,34 @@ impl Crud<UserMentionForm> for UserMention {
}
}
impl UserMention {
pub fn update_read(
pub trait UserMention_ {
fn update_read(
conn: &PgConnection,
user_mention_id: i32,
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::*;
diesel::update(user_mention.find(user_mention_id))
.set(read.eq(new_read))
.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::*;
diesel::update(
user_mention
@ -78,18 +73,13 @@ impl UserMention {
#[cfg(test)]
mod tests {
use crate::{
source::user_mention::*,
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
use lemmy_db_schema::source::{
comment::*,
community::{Community, CommunityForm},
post::*,
user::*,
user_mention::*,
};
#[test]

View file

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

View file

@ -3,7 +3,6 @@ use crate::{
functions::hot_rank,
fuzzy_search,
limit_and_offset,
source::category::Category,
views::ViewToVec,
MaybeOptional,
SortType,
@ -13,6 +12,7 @@ use diesel::{result::Error, *};
use lemmy_db_schema::{
schema::{category, community, community_aggregates, community_follower, user_},
source::{
category::Category,
community::{Community, CommunityFollower, CommunitySafe},
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 lemmy_db_schema::{
schema::{community, mod_add_community, user_, user_alias_1},
source::{
community::{Community, CommunitySafe},
moderator::ModAddCommunity,
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 lemmy_db_schema::{
schema::{mod_add, user_, user_alias_1},
source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
source::{
moderator::ModAdd,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
};
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 lemmy_db_schema::{
schema::{community, mod_ban_from_community, user_, user_alias_1},
source::{
community::{Community, CommunitySafe},
moderator::ModBanFromCommunity,
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 lemmy_db_schema::{
schema::{mod_ban, user_, user_alias_1},
source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
source::{
moderator::ModBan,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
};
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 lemmy_db_schema::{
schema::{community, mod_lock_post, post, user_},
source::{
community::{Community, CommunitySafe},
moderator::ModLockPost,
post::Post,
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 lemmy_db_schema::{
schema::{comment, community, mod_remove_comment, post, user_, user_alias_1},
source::{
comment::Comment,
community::{Community, CommunitySafe},
moderator::ModRemoveComment,
post::Post,
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 lemmy_db_schema::{
schema::{community, mod_remove_community, user_},
source::{
community::{Community, CommunitySafe},
moderator::ModRemoveCommunity,
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 lemmy_db_schema::{
schema::{community, mod_remove_post, post, user_},
source::{
community::{Community, CommunitySafe},
moderator::ModRemovePost,
post::Post,
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 lemmy_db_schema::{
schema::{community, mod_sticky_post, post, user_},
source::{
community::{Community, CommunitySafe},
moderator::ModStickyPost,
post::Post,
user::{UserSafe, User_},
},

View file

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

View file

@ -1,14 +1,11 @@
use crate::{
limit_and_offset,
source::private_message::PrivateMessage,
views::ViewToVec,
MaybeOptional,
ToSafe,
};
use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
use diesel::{result::Error, *};
use lemmy_db_schema::{
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;

View file

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

View file

@ -2,7 +2,6 @@ use crate::{
aggregates::comment_aggregates::CommentAggregates,
functions::hot_rank,
limit_and_offset,
source::user_mention::UserMention,
views::ViewToVec,
MaybeOptional,
SortType,
@ -28,6 +27,7 @@ use lemmy_db_schema::{
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
user_mention::UserMention,
},
};
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_report;
pub mod community;
pub mod moderator;
pub mod password_reset_request;
pub mod post;
pub mod post_report;
pub mod private_message;
pub mod site;
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;
use diesel::PgConnection;
use lemmy_db::{
source::{
user::User,
use lemmy_db::{source::user::User, Crud, DbPool};
use lemmy_db_schema::source::{
comment::Comment,
post::Post,
user::User_,
user_mention::{UserMention, UserMentionForm},
},
Crud,
DbPool,
};
use lemmy_db_schema::source::{comment::Comment, post::Post, user::User_};
use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
use log::error;
use serde::{Deserialize, Serialize};

View file

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

View file

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