"lazy_static",
"lemmy_apub",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_rate_limit",
"lemmy_structs",
"lemmy_utils",
"itertools",
"lazy_static",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_structs",
"lemmy_utils",
"lemmy_websocket",
"diesel",
"diesel_migrations",
"lazy_static",
+ "lemmy_db_schema",
"lemmy_utils",
"log",
"regex",
"url",
]
+[[package]]
+name = "lemmy_db_schema"
+version = "0.1.0"
+dependencies = [
+ "chrono",
+ "diesel",
+ "log",
+ "serde 1.0.118",
+ "serde_json",
+ "url",
+]
+
[[package]]
name = "lemmy_rate_limit"
version = "0.1.0"
"lemmy_api",
"lemmy_apub",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_rate_limit",
"lemmy_structs",
"lemmy_utils",
"chrono",
"diesel",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_utils",
"log",
"serde 1.0.118",
"chrono",
"diesel",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_rate_limit",
"lemmy_structs",
"lemmy_utils",
"lemmy_apub",
"lemmy_utils",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_structs",
"lemmy_rate_limit",
"lemmy_websocket",
lemmy_api = { path = "./lemmy_api" }
lemmy_apub = { path = "./lemmy_apub" }
lemmy_utils = { path = "./lemmy_utils" }
+lemmy_db_schema = { path = "./lemmy_db_schema" }
lemmy_db = { path = "./lemmy_db" }
lemmy_structs = { path = "./lemmy_structs" }
lemmy_rate_limit = { path = "./lemmy_rate_limit" }
lemmy_apub = { path = "../lemmy_apub" }
lemmy_utils = { path = "../lemmy_utils" }
lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_structs = { path = "../lemmy_structs" }
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
lemmy_websocket = { path = "../lemmy_websocket" }
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation};
-use lemmy_db::source::user::User_;
+use lemmy_db_schema::source::user::User_;
use lemmy_utils::settings::Settings;
use serde::{Deserialize, Serialize};
use actix_web::web::Data;
use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{
- source::{
- comment::{Comment, CommentForm, CommentLike, CommentLikeForm, CommentSaved, CommentSavedForm},
- comment_report::{CommentReport, CommentReportForm},
- moderator::{ModRemoveComment, ModRemoveCommentForm},
- },
+ source::comment::Comment_,
views::{
comment_report_view::{CommentReportQueryBuilder, CommentReportView},
comment_view::{CommentQueryBuilder, CommentView},
Saveable,
SortType,
};
+use lemmy_db_schema::source::{comment::*, comment_report::*, moderator::*};
use lemmy_structs::{blocking, comment::*, send_local_notifs};
use lemmy_utils::{
apub::{make_apub_endpoint, EndpointType},
use lemmy_apub::ActorType;
use lemmy_db::{
diesel_option_overwrite,
- naive_now,
- source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
+ source::{
+ comment::Comment_,
+ community::{CommunityModerator_, Community_},
+ post::Post_,
+ },
views::{
comment_view::CommentQueryBuilder,
community::{
Joinable,
SortType,
};
+use lemmy_db_schema::{
+ naive_now,
+ source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
+};
use lemmy_structs::{blocking, community::*};
use lemmy_utils::{
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
use actix_web::{web, web::Data};
use lemmy_db::{
source::{
- community::{Community, CommunityModerator},
- post::Post,
- site::Site,
- user::User_,
+ community::{CommunityModerator_, Community_},
+ site::Site_,
},
views::community::community_user_ban_view::CommunityUserBanView,
Crud,
DbPool,
};
+use lemmy_db_schema::source::{
+ community::{Community, CommunityModerator},
+ post::Post,
+ site::Site,
+ user::User_,
+};
use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
use actix_web::web::Data;
use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{
- naive_now,
- source::{
- moderator::*,
- post::*,
- post_report::{PostReport, PostReportForm},
- },
+ source::post::Post_,
views::{
comment_view::CommentQueryBuilder,
community::community_moderator_view::CommunityModeratorView,
Saveable,
SortType,
};
+use lemmy_db_schema::{
+ naive_now,
+ source::{
+ moderator::*,
+ post::*,
+ post_report::{PostReport, PostReportForm},
+ },
+};
use lemmy_structs::{blocking, post::*};
use lemmy_utils::{
apub::{make_apub_endpoint, EndpointType},
use lemmy_apub::fetcher::search_by_apub_id;
use lemmy_db::{
diesel_option_overwrite,
- naive_now,
- source::{category::*, moderator::*, site::*},
+ source::{category::Category_, site::Site_},
views::{
comment_view::CommentQueryBuilder,
community::community_view::CommunityQueryBuilder,
SearchType,
SortType,
};
+use lemmy_db_schema::{
+ naive_now,
+ source::{
+ category::Category,
+ moderator::*,
+ site::{Site, *},
+ },
+};
use lemmy_structs::{blocking, site::*, user::Register};
use lemmy_utils::{
location_info,
use lemmy_apub::ApubObjectType;
use lemmy_db::{
diesel_option_overwrite,
- naive_now,
source::{
- comment::*,
- community::*,
- moderator::*,
- password_reset_request::*,
- post::*,
- private_message::*,
- site::*,
- user::*,
- user_mention::*,
+ comment::Comment_,
+ community::Community_,
+ password_reset_request::PasswordResetRequest_,
+ post::Post_,
+ private_message::PrivateMessage_,
+ site::Site_,
+ user::User,
+ user_mention::UserMention_,
},
views::{
comment_report_view::CommentReportView,
ListingType,
SortType,
};
+use lemmy_db_schema::{
+ naive_now,
+ 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::{
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
[dependencies]
lemmy_utils = { path = "../lemmy_utils" }
lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_structs = { path = "../lemmy_structs" }
lemmy_websocket = { path = "../lemmy_websocket" }
diesel = "1.4.5"
base::ExtendsExt,
};
use anyhow::Context;
-use lemmy_db::{
- source::{
- comment::{Comment, CommentLike, CommentLikeForm},
- post::Post,
- },
- views::comment_view::CommentView,
- Crud,
- Likeable,
+use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Crud, Likeable};
+use lemmy_db_schema::source::{
+ comment::{Comment, CommentLike, CommentLikeForm},
+ post::Post,
};
use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs};
use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError};
use crate::activities::receive::get_actor_as_user;
use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{
- source::comment::{Comment, CommentLike},
- views::comment_view::CommentView,
- Likeable,
-};
+use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Likeable};
+use lemmy_db_schema::source::comment::{Comment, CommentLike};
use lemmy_structs::{blocking, comment::CommentResponse};
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
};
use anyhow::Context;
use lemmy_db::{
- source::community::Community,
+ source::community::Community_,
views::community::community_view::CommunityView,
ApubObject,
};
+use lemmy_db_schema::source::community::Community;
use lemmy_structs::{blocking, community::CommunityResponse};
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
error::DomainError,
};
use anyhow::{anyhow, Context};
-use lemmy_db::source::user::User_;
+use lemmy_db_schema::source::user::User_;
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext;
use log::debug;
prelude::*,
};
use anyhow::Context;
-use lemmy_db::{
- source::post::{Post, PostLike, PostLikeForm},
- views::post_view::PostView,
- Likeable,
-};
+use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable};
+use lemmy_db_schema::source::post::{Post, PostLike, PostLikeForm};
use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
use crate::activities::receive::get_actor_as_user;
use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{
- source::post::{Post, PostLike},
- views::post_view::PostView,
- Likeable,
-};
+use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable};
+use lemmy_db_schema::source::post::{Post, PostLike};
use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
};
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};
};
use anyhow::anyhow;
use itertools::Itertools;
-use lemmy_db::{
- source::{comment::Comment, community::Community, post::Post, user::User_},
- Crud,
- DbPool,
-};
+use lemmy_db::{Crud, DbPool};
+use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post, user::User_};
use lemmy_structs::{blocking, WebFingerResponse};
use lemmy_utils::{
request::{retry, RecvError},
};
use anyhow::Context;
use itertools::Itertools;
-use lemmy_db::{
- source::community::Community,
- views::community::community_follower_view::CommunityFollowerView,
- DbPool,
-};
+use lemmy_db::{views::community::community_follower_view::CommunityFollowerView, DbPool};
+use lemmy_db_schema::source::community::Community;
use lemmy_structs::blocking;
use lemmy_utils::{location_info, settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext;
prelude::*,
public,
};
-use lemmy_db::{
- source::{community::Community, post::Post, user::User_},
- Crud,
-};
+use lemmy_db::Crud;
+use lemmy_db_schema::source::{community::Community, post::Post, user::User_};
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
},
prelude::*,
};
-use lemmy_db::{
- source::{private_message::PrivateMessage, user::User_},
- Crud,
-};
+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;
base::{AnyBase, BaseExt, ExtendsExt},
object::ObjectExt,
};
-use lemmy_db::{
- source::{
- community::{Community, CommunityFollower, CommunityFollowerForm},
- user::User_,
- },
- ApubObject,
- DbPool,
- Followable,
+use lemmy_db::{ApubObject, DbPool, Followable};
+use lemmy_db_schema::source::{
+ community::{Community, CommunityFollower, CommunityFollowerForm},
+ user::User_,
};
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
WorkerConfig,
};
use itertools::Itertools;
-use lemmy_db::{
- source::{community::Community, user::User_},
- DbPool,
-};
+use lemmy_db::DbPool;
+use lemmy_db_schema::source::{community::Community, user::User_};
use lemmy_utils::{location_info, settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext;
use log::{debug, warn};
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};
use chrono::NaiveDateTime;
use diesel::result::Error::NotFound;
use lemmy_db::{
- naive_now,
- source::{
- comment::Comment,
- community::{Community, CommunityModerator, CommunityModeratorForm},
- post::Post,
- user::User_,
- },
+ source::user::User,
views::{
comment_view::CommentView,
community::community_view::CommunityView,
Joinable,
SearchType,
};
+use lemmy_db_schema::{
+ naive_now,
+ source::{
+ comment::Comment,
+ community::{Community, CommunityModerator, CommunityModeratorForm},
+ post::Post,
+ user::User_,
+ },
+};
use lemmy_structs::{blocking, site::SearchResponse};
use lemmy_utils::{
location_info,
};
use actix_web::{body::Body, web, web::Path, HttpResponse};
use diesel::result::Error::NotFound;
-use lemmy_db::{source::comment::Comment, Crud};
+use lemmy_db::Crud;
+use lemmy_db_schema::source::comment::Comment;
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
};
use actix_web::{body::Body, web, HttpResponse};
use lemmy_db::{
- source::{community::Community, post::Post},
+ source::{community::Community_, post::Post_},
views::community::community_follower_view::CommunityFollowerView,
};
+use lemmy_db_schema::source::{community::Community, post::Post};
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
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;
};
use actix_web::{body::Body, web, HttpResponse};
use diesel::result::Error::NotFound;
-use lemmy_db::{source::post::Post, Crud};
+use lemmy_db::Crud;
+use lemmy_db_schema::source::post::Post;
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
collection::{CollectionExt, OrderedCollection},
};
use actix_web::{body::Body, web, HttpResponse};
-use lemmy_db::source::user::User_;
+use lemmy_db::source::user::User;
+use lemmy_db_schema::source::user::User_;
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use actix_web::{web, HttpRequest, HttpResponse};
use anyhow::{anyhow, Context};
use lemmy_db::{
- source::{
- community::{Community, CommunityFollower, CommunityFollowerForm},
- user::User_,
- },
+ source::community::Community_,
views::community::community_user_ban_view::CommunityUserBanView,
ApubObject,
DbPool,
Followable,
};
+use lemmy_db_schema::source::{
+ community::{Community, CommunityFollower, CommunityFollowerForm},
+ user::User_,
+};
use lemmy_structs::blocking;
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext;
};
use actix_web::HttpRequest;
use anyhow::{anyhow, Context};
-use lemmy_db::{
- source::{activity::Activity, community::Community, user::User_},
- ApubObject,
- DbPool,
-};
+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;
};
use anyhow::Context;
use diesel::result::Error::NotFound;
-use lemmy_db::{
- source::{comment::Comment, post::Post, site::Site},
- ApubObject,
- Crud,
-};
+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;
use activitystreams::{activity::ActorAndObject, prelude::*};
use actix_web::{web, HttpRequest, HttpResponse};
use anyhow::Context;
-use lemmy_db::{source::community::Community, ApubObject, DbPool};
+use lemmy_db::{ApubObject, DbPool};
+use lemmy_db_schema::source::community::Community;
use lemmy_structs::blocking;
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext;
use actix_web::{web, HttpRequest, HttpResponse};
use anyhow::{anyhow, Context};
use diesel::NotFound;
-use lemmy_db::{
- source::{
- community::{Community, CommunityFollower},
- 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;
use lemmy_utils::{location_info, LemmyError};
};
use activitystreams_ext::{Ext1, Ext2};
use anyhow::{anyhow, Context};
-use lemmy_db::{
- source::{activity::Activity, user::User_},
- DbPool,
-};
+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;
prelude::*,
};
use anyhow::{anyhow, Context};
-use lemmy_db::{
- source::{
- comment::{Comment, CommentForm},
- community::Community,
- post::Post,
- user::User_,
- },
- Crud,
- DbPool,
+use lemmy_db::{Crud, DbPool};
+use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm},
+ community::Community,
+ post::Post,
+ user::User_,
};
use lemmy_structs::blocking;
use lemmy_utils::{
};
use activitystreams_ext::Ext2;
use anyhow::Context;
-use lemmy_db::{
+use lemmy_db::{views::community::community_moderator_view::CommunityModeratorView, DbPool};
+use lemmy_db_schema::{
naive_now,
source::community::{Community, CommunityForm},
- views::community::community_moderator_view::CommunityModeratorView,
- DbPool,
};
use lemmy_structs::blocking;
use lemmy_utils::{
};
use activitystreams_ext::Ext1;
use anyhow::Context;
-use lemmy_db::{
- source::{
- community::Community,
- post::{Post, PostForm},
- user::User_,
- },
- Crud,
- DbPool,
+use lemmy_db::{Crud, DbPool};
+use lemmy_db_schema::source::{
+ community::Community,
+ post::{Post, PostForm},
+ user::User_,
};
use lemmy_structs::blocking;
use lemmy_utils::{
prelude::*,
};
use anyhow::Context;
-use lemmy_db::{
- source::{
- private_message::{PrivateMessage, PrivateMessageForm},
- user::User_,
- },
- Crud,
- DbPool,
+use lemmy_db::{Crud, DbPool};
+use lemmy_db_schema::source::{
+ private_message::{PrivateMessage, PrivateMessageForm},
+ user::User_,
};
use lemmy_structs::blocking;
use lemmy_utils::{location_info, utils::convert_datetime, LemmyError};
};
use activitystreams_ext::Ext1;
use anyhow::Context;
-use lemmy_db::{
+use lemmy_db::{ApubObject, DbPool};
+use lemmy_db_schema::{
naive_now,
source::user::{UserForm, User_},
- ApubObject,
- DbPool,
};
use lemmy_structs::blocking;
use lemmy_utils::{
[dependencies]
lemmy_utils = { path = "../lemmy_utils" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
diesel_migrations = "1.4.0"
chrono = { version = "0.4.19", features = ["serde"] }
strum_macros = "0.20.1"
log = "0.4.11"
sha2 = "0.9.2"
-bcrypt = "0.9.0"
url = { version = "2.2.0", features = ["serde"] }
lazy_static = "1.4.0"
regex = "1.4.2"
+bcrypt = "0.9.0"
-use crate::schema::comment_aggregates;
use diesel::{result::Error, *};
+use lemmy_db_schema::schema::comment_aggregates;
use serde::Serialize;
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
-use crate::schema::community_aggregates;
use diesel::{result::Error, *};
+use lemmy_db_schema::schema::community_aggregates;
use serde::Serialize;
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
mod tests {
use crate::{
aggregates::community_aggregates::CommunityAggregates,
- source::{
- comment::{Comment, CommentForm},
- community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
- post::{Post, PostForm},
- user::{UserForm, User_},
- },
tests::establish_unpooled_connection,
Crud,
Followable,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm},
+ community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
+ post::{Post, PostForm},
+ user::{UserForm, User_},
+ };
#[test]
fn test_crud() {
-use crate::schema::post_aggregates;
use diesel::{result::Error, *};
+use lemmy_db_schema::schema::post_aggregates;
use serde::Serialize;
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
mod tests {
use crate::{
aggregates::post_aggregates::PostAggregates,
- source::{
- comment::{Comment, CommentForm},
- community::{Community, CommunityForm},
- post::{Post, PostForm, PostLike, PostLikeForm},
- user::{UserForm, User_},
- },
tests::establish_unpooled_connection,
Crud,
Likeable,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm},
+ community::{Community, CommunityForm},
+ post::{Post, PostForm, PostLike, PostLikeForm},
+ user::{UserForm, User_},
+ };
#[test]
fn test_crud() {
-use crate::schema::site_aggregates;
use diesel::{result::Error, *};
+use lemmy_db_schema::schema::site_aggregates;
use serde::Serialize;
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
mod tests {
use crate::{
aggregates::site_aggregates::SiteAggregates,
- source::{
- comment::{Comment, CommentForm},
- community::{Community, CommunityForm},
- post::{Post, PostForm},
- site::{Site, SiteForm},
- user::{UserForm, User_},
- },
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm},
+ community::{Community, CommunityForm},
+ post::{Post, PostForm},
+ user::{UserForm, User_},
+ };
#[test]
fn test_crud() {
-use crate::schema::user_aggregates;
use diesel::{result::Error, *};
+use lemmy_db_schema::schema::user_aggregates;
use serde::Serialize;
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
mod tests {
use crate::{
aggregates::user_aggregates::UserAggregates,
- source::{
- comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
- community::{Community, CommunityForm},
- post::{Post, PostForm, PostLike, PostLikeForm},
- user::{UserForm, User_},
- },
tests::establish_unpooled_connection,
Crud,
Likeable,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+ community::{Community, CommunityForm},
+ post::{Post, PostForm, PostLike, PostLikeForm},
+ user::{UserForm, User_},
+ };
#[test]
fn test_crud() {
#[macro_use]
extern crate diesel_migrations;
-use chrono::NaiveDateTime;
use diesel::{result::Error, *};
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::{env, env::VarError};
pub mod aggregates;
-pub mod schema;
pub mod source;
pub mod views;
(limit, offset)
}
-pub fn naive_now() -> NaiveDateTime {
- chrono::prelude::Utc::now().naive_utc()
-}
-
pub fn is_email_regex(test: &str) -> bool {
EMAIL_REGEX.is_match(test)
}
-use crate::{schema::activity, Crud};
+use crate::Crud;
use diesel::{dsl::*, result::Error, *};
+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 crate::schema::activity::dsl::*;
+ use lemmy_db_schema::schema::activity::dsl::*;
activity.find(activity_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
- use crate::schema::activity::dsl::*;
+ use lemmy_db_schema::schema::activity::dsl::*;
insert_into(activity)
.values(new_activity)
.get_result::<Self>(conn)
activity_id: i32,
new_activity: &ActivityForm,
) -> Result<Self, Error> {
- use crate::schema::activity::dsl::*;
+ use lemmy_db_schema::schema::activity::dsl::*;
diesel::update(activity.find(activity_id))
.set(new_activity)
.get_result::<Self>(conn)
}
fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
- use crate::schema::activity::dsl::*;
+ use lemmy_db_schema::schema::activity::dsl::*;
diesel::delete(activity.find(activity_id)).execute(conn)
}
}
-impl Activity {
- pub fn insert<T>(
+pub trait Activity_ {
+ fn insert<T>(
+ conn: &PgConnection,
+ ap_id: String,
+ data: &T,
+ local: bool,
+ sensitive: bool,
+ ) -> 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<Self, IoError>
+ ) -> Result<Activity, IoError>
where
T: Serialize + Debug,
{
}
}
- pub fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
- use crate::schema::activity::dsl::*;
+ 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)
}
}
#[cfg(test)]
mod tests {
- use crate::{
- source::{
- activity::{Activity, ActivityForm},
- user::{UserForm, User_},
- },
- 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 serde_json::Value;
-use crate::{
- schema::{category, category::dsl::*},
- Crud,
-};
+use crate::Crud;
use diesel::{dsl::*, result::Error, *};
-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> {
}
}
-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() {
-use super::post::Post;
-use crate::{
+use crate::{ApubObject, Crud, Likeable, Saveable};
+use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::{
naive_now,
- schema::{comment, comment_alias_1, comment_like, comment_saved},
- ApubObject,
- Crud,
- Likeable,
- Saveable,
+ source::comment::{
+ Comment,
+ CommentForm,
+ CommentLike,
+ CommentLikeForm,
+ CommentSaved,
+ CommentSavedForm,
+ },
};
-use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-use url::{ParseError, Url};
-
-// WITH RECURSIVE MyTree AS (
-// SELECT * FROM comment WHERE parent_id IS NULL
-// UNION ALL
-// SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
-// )
-// SELECT * FROM MyTree;
-
-#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
-#[belongs_to(Post)]
-#[table_name = "comment"]
-pub struct Comment {
- pub id: i32,
- pub creator_id: i32,
- pub post_id: i32,
- pub parent_id: Option<i32>,
- pub content: String,
- pub removed: bool,
- pub read: bool, // Whether the recipient has read the comment or not
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub deleted: bool,
- pub ap_id: String,
- pub local: bool,
-}
-
-#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
-#[belongs_to(Post)]
-#[table_name = "comment_alias_1"]
-pub struct CommentAlias1 {
- pub id: i32,
- pub creator_id: i32,
- pub post_id: i32,
- pub parent_id: Option<i32>,
- pub content: String,
- pub removed: bool,
- pub read: bool, // Whether the recipient has read the comment or not
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub deleted: bool,
- pub ap_id: String,
- pub local: bool,
-}
-
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "comment"]
-pub struct CommentForm {
- pub creator_id: i32,
- pub post_id: i32,
- pub parent_id: Option<i32>,
- pub content: String,
- pub removed: Option<bool>,
- pub read: Option<bool>,
- pub published: Option<chrono::NaiveDateTime>,
- pub updated: Option<chrono::NaiveDateTime>,
- pub deleted: Option<bool>,
- pub ap_id: Option<String>,
- pub local: bool,
-}
-impl CommentForm {
- pub fn get_ap_id(&self) -> Result<Url, ParseError> {
- Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
- }
-}
-
-impl Crud<CommentForm> for Comment {
- fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
- comment.find(comment_id).first::<Self>(conn)
- }
-
- fn delete(conn: &PgConnection, comment_id: i32) -> Result<usize, Error> {
- use crate::schema::comment::dsl::*;
- diesel::delete(comment.find(comment_id)).execute(conn)
- }
-
- fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
- insert_into(comment)
- .values(comment_form)
- .get_result::<Self>(conn)
- }
-
- fn update(
+pub trait Comment_ {
+ fn update_ap_id(conn: &PgConnection, comment_id: i32, apub_id: String) -> Result<Comment, Error>;
+ fn permadelete_for_creator(
+ conn: &PgConnection,
+ for_creator_id: i32,
+ ) -> Result<Vec<Comment>, Error>;
+ fn update_deleted(
conn: &PgConnection,
comment_id: i32,
- comment_form: &CommentForm,
- ) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
- diesel::update(comment.find(comment_id))
- .set(comment_form)
- .get_result::<Self>(conn)
- }
-}
-
-impl ApubObject<CommentForm> for Comment {
- fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
- comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
- }
-
- fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
- insert_into(comment)
- .values(comment_form)
- .on_conflict(ap_id)
- .do_update()
- .set(comment_form)
- .get_result::<Self>(conn)
- }
-}
-
-impl Comment {
- pub fn update_ap_id(
+ new_deleted: bool,
+ ) -> Result<Comment, Error>;
+ fn update_removed(
conn: &PgConnection,
comment_id: i32,
- apub_id: String,
- ) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
+ new_removed: bool,
+ ) -> Result<Comment, Error>;
+ fn update_removed_for_creator(
+ conn: &PgConnection,
+ for_creator_id: i32,
+ new_removed: bool,
+ ) -> Result<Vec<Comment>, Error>;
+ fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Comment, Error>;
+ fn update_content(
+ conn: &PgConnection,
+ comment_id: i32,
+ new_content: &str,
+ ) -> Result<Comment, Error>;
+}
+
+impl Comment_ for Comment {
+ fn update_ap_id(conn: &PgConnection, comment_id: i32, apub_id: String) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::comment::dsl::*;
diesel::update(comment.find(comment_id))
.set(ap_id.eq(apub_id))
.get_result::<Self>(conn)
}
- pub fn permadelete_for_creator(
- conn: &PgConnection,
- for_creator_id: i32,
- ) -> Result<Vec<Self>, Error> {
- use crate::schema::comment::dsl::*;
+ fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result<Vec<Self>, Error> {
+ use lemmy_db_schema::schema::comment::dsl::*;
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
.set((
content.eq("*Permananently Deleted*"),
.get_results::<Self>(conn)
}
- pub fn update_deleted(
+ fn update_deleted(
conn: &PgConnection,
comment_id: i32,
new_deleted: bool,
) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
+ use lemmy_db_schema::schema::comment::dsl::*;
diesel::update(comment.find(comment_id))
.set((deleted.eq(new_deleted), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
- pub fn update_removed(
+ fn update_removed(
conn: &PgConnection,
comment_id: i32,
new_removed: bool,
) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
+ use lemmy_db_schema::schema::comment::dsl::*;
diesel::update(comment.find(comment_id))
.set((removed.eq(new_removed), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
- pub fn update_removed_for_creator(
+ fn update_removed_for_creator(
conn: &PgConnection,
for_creator_id: i32,
new_removed: bool,
) -> Result<Vec<Self>, Error> {
- use crate::schema::comment::dsl::*;
+ use lemmy_db_schema::schema::comment::dsl::*;
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
.set((removed.eq(new_removed), updated.eq(naive_now())))
.get_results::<Self>(conn)
}
- pub fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
+ fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::comment::dsl::*;
diesel::update(comment.find(comment_id))
.set(read.eq(new_read))
.get_result::<Self>(conn)
}
- pub fn update_content(
+ fn update_content(
conn: &PgConnection,
comment_id: i32,
new_content: &str,
) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
+ use lemmy_db_schema::schema::comment::dsl::*;
diesel::update(comment.find(comment_id))
.set((content.eq(new_content), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
}
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
-#[belongs_to(Comment)]
-#[table_name = "comment_like"]
-pub struct CommentLike {
- pub id: i32,
- pub user_id: i32,
- pub comment_id: i32,
- pub post_id: i32, // TODO this is redundant
- pub score: i16,
- pub published: chrono::NaiveDateTime,
+impl Crud<CommentForm> for Comment {
+ fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::comment::dsl::*;
+ comment.find(comment_id).first::<Self>(conn)
+ }
+
+ fn delete(conn: &PgConnection, comment_id: i32) -> Result<usize, Error> {
+ use lemmy_db_schema::schema::comment::dsl::*;
+ diesel::delete(comment.find(comment_id)).execute(conn)
+ }
+
+ fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::comment::dsl::*;
+ insert_into(comment)
+ .values(comment_form)
+ .get_result::<Self>(conn)
+ }
+
+ fn update(
+ conn: &PgConnection,
+ comment_id: i32,
+ comment_form: &CommentForm,
+ ) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::comment::dsl::*;
+ diesel::update(comment.find(comment_id))
+ .set(comment_form)
+ .get_result::<Self>(conn)
+ }
}
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "comment_like"]
-pub struct CommentLikeForm {
- pub user_id: i32,
- pub comment_id: i32,
- pub post_id: i32, // TODO this is redundant
- pub score: i16,
+impl ApubObject<CommentForm> for Comment {
+ fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::comment::dsl::*;
+ comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
+ }
+
+ fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::comment::dsl::*;
+ insert_into(comment)
+ .values(comment_form)
+ .on_conflict(ap_id)
+ .do_update()
+ .set(comment_form)
+ .get_result::<Self>(conn)
+ }
}
impl Likeable<CommentLikeForm> for CommentLike {
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
- use crate::schema::comment_like::dsl::*;
+ use lemmy_db_schema::schema::comment_like::dsl::*;
insert_into(comment_like)
.values(comment_like_form)
.on_conflict((comment_id, user_id))
.get_result::<Self>(conn)
}
fn remove(conn: &PgConnection, user_id: i32, comment_id: i32) -> Result<usize, Error> {
- use crate::schema::comment_like::dsl;
+ use lemmy_db_schema::schema::comment_like::dsl;
diesel::delete(
dsl::comment_like
.filter(dsl::comment_id.eq(comment_id))
}
}
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Comment)]
-#[table_name = "comment_saved"]
-pub struct CommentSaved {
- pub id: i32,
- pub comment_id: i32,
- pub user_id: i32,
- pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "comment_saved"]
-pub struct CommentSavedForm {
- pub comment_id: i32,
- pub user_id: i32,
-}
-
impl Saveable<CommentSavedForm> for CommentSaved {
fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
- use crate::schema::comment_saved::dsl::*;
+ use lemmy_db_schema::schema::comment_saved::dsl::*;
insert_into(comment_saved)
.values(comment_saved_form)
.on_conflict((comment_id, user_id))
.get_result::<Self>(conn)
}
fn unsave(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
- use crate::schema::comment_saved::dsl::*;
+ use lemmy_db_schema::schema::comment_saved::dsl::*;
diesel::delete(
comment_saved
.filter(comment_id.eq(comment_saved_form.comment_id))
#[cfg(test)]
mod tests {
use crate::{
- source::{comment::*, community::*, post::*, user::*},
tests::establish_unpooled_connection,
Crud,
+ Likeable,
ListingType,
+ Saveable,
SortType,
};
+ use lemmy_db_schema::source::{
+ comment::*,
+ community::{Community, CommunityForm},
+ post::*,
+ user::{UserForm, User_},
+ };
#[test]
fn test_crud() {
+use crate::Reportable;
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
-
-use crate::{naive_now, schema::comment_report, source::comment::Comment, Reportable};
-
-#[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
/// * `conn` - the postgres connection
/// * `comment_report_form` - the filled CommentReportForm to insert
fn report(conn: &PgConnection, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
- use crate::schema::comment_report::dsl::*;
+ use lemmy_db_schema::schema::comment_report::dsl::*;
insert_into(comment_report)
.values(comment_report_form)
.get_result::<Self>(conn)
/// * `report_id` - the id of the report to resolve
/// * `by_resolver_id` - the id of the user resolving the report
fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
- use crate::schema::comment_report::dsl::*;
+ use lemmy_db_schema::schema::comment_report::dsl::*;
update(comment_report.find(report_id))
.set((
resolved.eq(true),
/// * `report_id` - the id of the report to unresolve
/// * `by_resolver_id` - the id of the user unresolving the report
fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
- use crate::schema::comment_report::dsl::*;
+ use lemmy_db_schema::schema::comment_report::dsl::*;
update(comment_report.find(report_id))
.set((
resolved.eq(false),
use crate::{
- naive_now,
- schema::{community, community_follower, community_moderator, community_user_ban},
views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
ApubObject,
Bannable,
Joinable,
};
use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "community"]
-pub struct Community {
- pub id: i32,
- pub name: String,
- pub title: String,
- pub description: Option<String>,
- pub category_id: i32,
- pub creator_id: i32,
- pub removed: bool,
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub deleted: bool,
- pub nsfw: bool,
- pub actor_id: String,
- pub local: bool,
- pub private_key: Option<String>,
- pub public_key: Option<String>,
- pub last_refreshed_at: chrono::NaiveDateTime,
- pub icon: Option<String>,
- pub banner: Option<String>,
-}
-
-/// A safe representation of community, without the sensitive info
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "community"]
-pub struct CommunitySafe {
- pub id: i32,
- pub name: String,
- pub title: String,
- pub description: Option<String>,
- pub category_id: i32,
- pub creator_id: i32,
- pub removed: bool,
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub deleted: bool,
- pub nsfw: bool,
- pub actor_id: String,
- pub local: bool,
- pub icon: Option<String>,
- pub banner: Option<String>,
-}
+use lemmy_db_schema::{
+ naive_now,
+ source::community::{
+ Community,
+ CommunityFollower,
+ CommunityFollowerForm,
+ CommunityForm,
+ CommunityModerator,
+ CommunityModeratorForm,
+ CommunityUserBan,
+ CommunityUserBanForm,
+ },
+};
mod safe_type {
- use crate::{schema::community::columns::*, source::community::Community, ToSafe};
+ use crate::{source::community::Community, ToSafe};
+ use lemmy_db_schema::schema::community::*;
+
type Columns = (
id,
name,
}
}
-#[derive(Insertable, AsChangeset, Debug)]
-#[table_name = "community"]
-pub struct CommunityForm {
- pub name: String,
- pub title: String,
- pub description: Option<String>,
- pub category_id: i32,
- pub creator_id: i32,
- pub removed: Option<bool>,
- pub published: Option<chrono::NaiveDateTime>,
- pub updated: Option<chrono::NaiveDateTime>,
- pub deleted: Option<bool>,
- pub nsfw: bool,
- pub actor_id: Option<String>,
- pub local: bool,
- pub private_key: Option<String>,
- pub public_key: Option<String>,
- pub last_refreshed_at: Option<chrono::NaiveDateTime>,
- pub icon: Option<Option<String>>,
- pub banner: Option<Option<String>>,
-}
-
impl Crud<CommunityForm> for Community {
fn read(conn: &PgConnection, community_id: i32) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::*;
community.find(community_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, community_id: i32) -> Result<usize, Error> {
- use crate::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::*;
diesel::delete(community.find(community_id)).execute(conn)
}
fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::*;
insert_into(community)
.values(new_community)
.get_result::<Self>(conn)
community_id: i32,
new_community: &CommunityForm,
) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::*;
diesel::update(community.find(community_id))
.set(new_community)
.get_result::<Self>(conn)
impl ApubObject<CommunityForm> for Community {
fn read_from_apub_id(conn: &PgConnection, for_actor_id: &str) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::*;
community
.filter(actor_id.eq(for_actor_id))
.first::<Self>(conn)
}
fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
- use crate::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::*;
insert_into(community)
.values(community_form)
.on_conflict(actor_id)
}
}
-impl Community {
- pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
+pub trait Community_ {
+ fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error>;
+ fn update_deleted(
+ conn: &PgConnection,
+ community_id: i32,
+ new_deleted: bool,
+ ) -> Result<Community, Error>;
+ fn update_removed(
+ conn: &PgConnection,
+ community_id: i32,
+ new_removed: bool,
+ ) -> Result<Community, Error>;
+ fn update_removed_for_creator(
+ conn: &PgConnection,
+ for_creator_id: i32,
+ new_removed: bool,
+ ) -> Result<Vec<Community>, Error>;
+ fn update_creator(
+ conn: &PgConnection,
+ community_id: i32,
+ new_creator_id: i32,
+ ) -> Result<Community, Error>;
+ fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error>;
+ fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
+ fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool;
+}
+
+impl Community_ for Community {
+ fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error> {
+ use lemmy_db_schema::schema::community::dsl::*;
community
.filter(local.eq(true))
.filter(name.eq(community_name))
.first::<Self>(conn)
}
- pub fn update_deleted(
+ fn update_deleted(
conn: &PgConnection,
community_id: i32,
new_deleted: bool,
- ) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
+ ) -> Result<Community, Error> {
+ use lemmy_db_schema::schema::community::dsl::*;
diesel::update(community.find(community_id))
.set((deleted.eq(new_deleted), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
- pub fn update_removed(
+ fn update_removed(
conn: &PgConnection,
community_id: i32,
new_removed: bool,
- ) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
+ ) -> Result<Community, Error> {
+ use lemmy_db_schema::schema::community::dsl::*;
diesel::update(community.find(community_id))
.set((removed.eq(new_removed), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
- pub fn update_removed_for_creator(
+ fn update_removed_for_creator(
conn: &PgConnection,
for_creator_id: i32,
new_removed: bool,
- ) -> Result<Vec<Self>, Error> {
- use crate::schema::community::dsl::*;
+ ) -> Result<Vec<Community>, Error> {
+ use lemmy_db_schema::schema::community::dsl::*;
diesel::update(community.filter(creator_id.eq(for_creator_id)))
.set((removed.eq(new_removed), updated.eq(naive_now())))
.get_results::<Self>(conn)
}
- pub fn update_creator(
+ fn update_creator(
conn: &PgConnection,
community_id: i32,
new_creator_id: i32,
- ) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
+ ) -> Result<Community, Error> {
+ use lemmy_db_schema::schema::community::dsl::*;
diesel::update(community.find(community_id))
.set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
.get_result::<Self>(conn)
Ok(mods_and_admins)
}
- pub fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
- use crate::schema::community::dsl::*;
+ fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
+ use lemmy_db_schema::schema::community::dsl::*;
community.select(actor_id).distinct().load::<String>(conn)
}
- pub fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
+ fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
Self::community_mods_and_admins(conn, community_id)
.unwrap_or_default()
.contains(&user_id)
}
}
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Community)]
-#[table_name = "community_moderator"]
-pub struct CommunityModerator {
- pub id: i32,
- pub community_id: i32,
- pub user_id: i32,
- pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "community_moderator"]
-pub struct CommunityModeratorForm {
- pub community_id: i32,
- pub user_id: i32,
-}
-
impl Joinable<CommunityModeratorForm> for CommunityModerator {
fn join(
conn: &PgConnection,
community_user_form: &CommunityModeratorForm,
) -> Result<Self, Error> {
- use crate::schema::community_moderator::dsl::*;
+ use lemmy_db_schema::schema::community_moderator::dsl::*;
insert_into(community_moderator)
.values(community_user_form)
.get_result::<Self>(conn)
conn: &PgConnection,
community_user_form: &CommunityModeratorForm,
) -> Result<usize, Error> {
- use crate::schema::community_moderator::dsl::*;
+ use lemmy_db_schema::schema::community_moderator::dsl::*;
diesel::delete(
community_moderator
.filter(community_id.eq(community_user_form.community_id))
}
}
-impl CommunityModerator {
- pub fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result<usize, Error> {
- use crate::schema::community_moderator::dsl::*;
+pub trait CommunityModerator_ {
+ fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result<usize, Error>;
+ fn get_user_moderated_communities(
+ conn: &PgConnection,
+ for_user_id: i32,
+ ) -> Result<Vec<i32>, Error>;
+}
+
+impl CommunityModerator_ for CommunityModerator {
+ fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result<usize, Error> {
+ use lemmy_db_schema::schema::community_moderator::dsl::*;
diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn)
}
- pub fn get_user_moderated_communities(
+ fn get_user_moderated_communities(
conn: &PgConnection,
for_user_id: i32,
) -> Result<Vec<i32>, Error> {
- use crate::schema::community_moderator::dsl::*;
+ use lemmy_db_schema::schema::community_moderator::dsl::*;
community_moderator
.filter(user_id.eq(for_user_id))
.select(community_id)
}
}
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Community)]
-#[table_name = "community_user_ban"]
-pub struct CommunityUserBan {
- pub id: i32,
- pub community_id: i32,
- pub user_id: i32,
- pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "community_user_ban"]
-pub struct CommunityUserBanForm {
- pub community_id: i32,
- pub user_id: i32,
-}
-
impl Bannable<CommunityUserBanForm> for CommunityUserBan {
fn ban(
conn: &PgConnection,
community_user_ban_form: &CommunityUserBanForm,
) -> Result<Self, Error> {
- use crate::schema::community_user_ban::dsl::*;
+ use lemmy_db_schema::schema::community_user_ban::dsl::*;
insert_into(community_user_ban)
.values(community_user_ban_form)
.get_result::<Self>(conn)
conn: &PgConnection,
community_user_ban_form: &CommunityUserBanForm,
) -> Result<usize, Error> {
- use crate::schema::community_user_ban::dsl::*;
+ use lemmy_db_schema::schema::community_user_ban::dsl::*;
diesel::delete(
community_user_ban
.filter(community_id.eq(community_user_ban_form.community_id))
}
}
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Community)]
-#[table_name = "community_follower"]
-pub struct CommunityFollower {
- pub id: i32,
- pub community_id: i32,
- pub user_id: i32,
- pub published: chrono::NaiveDateTime,
- pub pending: Option<bool>,
-}
-
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "community_follower"]
-pub struct CommunityFollowerForm {
- pub community_id: i32,
- pub user_id: i32,
- pub pending: bool,
-}
-
impl Followable<CommunityFollowerForm> for CommunityFollower {
fn follow(
conn: &PgConnection,
community_follower_form: &CommunityFollowerForm,
) -> Result<Self, Error> {
- use crate::schema::community_follower::dsl::*;
+ use lemmy_db_schema::schema::community_follower::dsl::*;
insert_into(community_follower)
.values(community_follower_form)
.on_conflict((community_id, user_id))
where
Self: Sized,
{
- use crate::schema::community_follower::dsl::*;
+ use lemmy_db_schema::schema::community_follower::dsl::*;
diesel::update(
community_follower
.filter(community_id.eq(community_id_))
conn: &PgConnection,
community_follower_form: &CommunityFollowerForm,
) -> Result<usize, Error> {
- use crate::schema::community_follower::dsl::*;
+ use lemmy_db_schema::schema::community_follower::dsl::*;
diesel::delete(
community_follower
.filter(community_id.eq(&community_follower_form.community_id))
// TODO: this function name only makes sense if you call it with a remote community. for a local
// community, it will also return true if only remote followers exist
fn has_local_followers(conn: &PgConnection, community_id_: i32) -> Result<bool, Error> {
- use crate::schema::community_follower::dsl::*;
+ use lemmy_db_schema::schema::community_follower::dsl::*;
diesel::select(exists(
community_follower.filter(community_id.eq(community_id_)),
))
#[cfg(test)]
mod tests {
use crate::{
- source::{community::*, user::*},
tests::establish_unpooled_connection,
+ Bannable,
+ Crud,
+ Followable,
+ Joinable,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{community::*, user::*};
#[test]
fn test_crud() {
-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,
- },
- Crud,
-};
+use crate::Crud;
use diesel::{dsl::*, result::Error, *};
-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> {
- use crate::schema::mod_remove_post::dsl::*;
+ use lemmy_db_schema::schema::mod_remove_post::dsl::*;
mod_remove_post.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_post::dsl::*;
+ use lemmy_db_schema::schema::mod_remove_post::dsl::*;
insert_into(mod_remove_post)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_post::dsl::*;
+ use lemmy_db_schema::schema::mod_remove_post::dsl::*;
diesel::update(mod_remove_post.find(from_id))
.set(form)
.get_result::<Self>(conn)
}
}
-#[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 crate::schema::mod_lock_post::dsl::*;
+ use lemmy_db_schema::schema::mod_lock_post::dsl::*;
mod_lock_post.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
- use crate::schema::mod_lock_post::dsl::*;
+ use lemmy_db_schema::schema::mod_lock_post::dsl::*;
insert_into(mod_lock_post)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
- use crate::schema::mod_lock_post::dsl::*;
+ use lemmy_db_schema::schema::mod_lock_post::dsl::*;
diesel::update(mod_lock_post.find(from_id))
.set(form)
.get_result::<Self>(conn)
}
}
-#[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 crate::schema::mod_sticky_post::dsl::*;
+ use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
mod_sticky_post.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
- use crate::schema::mod_sticky_post::dsl::*;
+ use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
insert_into(mod_sticky_post)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModStickyPostForm) -> Result<Self, Error> {
- use crate::schema::mod_sticky_post::dsl::*;
+ use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
diesel::update(mod_sticky_post.find(from_id))
.set(form)
.get_result::<Self>(conn)
}
}
-#[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 crate::schema::mod_remove_comment::dsl::*;
+ use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
mod_remove_comment.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_comment::dsl::*;
+ use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
insert_into(mod_remove_comment)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_comment::dsl::*;
+ use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
diesel::update(mod_remove_comment.find(from_id))
.set(form)
.get_result::<Self>(conn)
}
}
-#[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 crate::schema::mod_remove_community::dsl::*;
+ use lemmy_db_schema::schema::mod_remove_community::dsl::*;
mod_remove_community.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_community::dsl::*;
+ use lemmy_db_schema::schema::mod_remove_community::dsl::*;
insert_into(mod_remove_community)
.values(form)
.get_result::<Self>(conn)
from_id: i32,
form: &ModRemoveCommunityForm,
) -> Result<Self, Error> {
- use crate::schema::mod_remove_community::dsl::*;
+ use lemmy_db_schema::schema::mod_remove_community::dsl::*;
diesel::update(mod_remove_community.find(from_id))
.set(form)
.get_result::<Self>(conn)
}
}
-#[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 crate::schema::mod_ban_from_community::dsl::*;
+ use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
mod_ban_from_community.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_ban_from_community::dsl::*;
+ use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
insert_into(mod_ban_from_community)
.values(form)
.get_result::<Self>(conn)
from_id: i32,
form: &ModBanFromCommunityForm,
) -> Result<Self, Error> {
- use crate::schema::mod_ban_from_community::dsl::*;
+ use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
diesel::update(mod_ban_from_community.find(from_id))
.set(form)
.get_result::<Self>(conn)
}
}
-#[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 crate::schema::mod_ban::dsl::*;
+ use lemmy_db_schema::schema::mod_ban::dsl::*;
mod_ban.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
- use crate::schema::mod_ban::dsl::*;
+ use lemmy_db_schema::schema::mod_ban::dsl::*;
insert_into(mod_ban).values(form).get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
- use crate::schema::mod_ban::dsl::*;
+ use lemmy_db_schema::schema::mod_ban::dsl::*;
diesel::update(mod_ban.find(from_id))
.set(form)
.get_result::<Self>(conn)
}
}
-#[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 crate::schema::mod_add_community::dsl::*;
+ use lemmy_db_schema::schema::mod_add_community::dsl::*;
mod_add_community.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_add_community::dsl::*;
+ use lemmy_db_schema::schema::mod_add_community::dsl::*;
insert_into(mod_add_community)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_add_community::dsl::*;
+ use lemmy_db_schema::schema::mod_add_community::dsl::*;
diesel::update(mod_add_community.find(from_id))
.set(form)
.get_result::<Self>(conn)
}
}
-#[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 crate::schema::mod_add::dsl::*;
+ use lemmy_db_schema::schema::mod_add::dsl::*;
mod_add.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
- use crate::schema::mod_add::dsl::*;
+ use lemmy_db_schema::schema::mod_add::dsl::*;
insert_into(mod_add).values(form).get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
- use crate::schema::mod_add::dsl::*;
+ use lemmy_db_schema::schema::mod_add::dsl::*;
diesel::update(mod_add.find(from_id))
.set(form)
.get_result::<Self>(conn)
#[cfg(test)]
mod tests {
- use crate::{
- source::{comment::*, community::*, moderator::*, post::*, user::*},
- tests::establish_unpooled_connection,
- ListingType,
- SortType,
- };
+ use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+ use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
// use Crud;
#[test]
-use crate::{
- schema::{password_reset_request, password_reset_request::dsl::*},
- Crud,
-};
+use crate::Crud;
use diesel::{dsl::*, result::Error, PgConnection, *};
+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> {
- use crate::schema::password_reset_request::dsl::*;
password_reset_request
.find(password_reset_request_id)
.first::<Self>(conn)
}
}
-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,
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 {
- let mut str = String::new();
- for byte in bytes {
- str = format!("{}{:02x}", str, byte);
- }
- str
+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 super::super::user::*;
- use crate::{
- source::password_reset_request::PasswordResetRequest,
- tests::establish_unpooled_connection,
- Crud,
- ListingType,
- SortType,
- };
+ use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+ use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
#[test]
fn test_crud() {
-use crate::{
+use crate::{ApubObject, Crud, Likeable, Readable, Saveable};
+use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::{
naive_now,
- schema::{post, post_like, post_read, post_saved},
- ApubObject,
- Crud,
- Likeable,
- Readable,
- Saveable,
+ source::post::{
+ Post,
+ PostForm,
+ PostLike,
+ PostLikeForm,
+ PostRead,
+ PostReadForm,
+ PostSaved,
+ PostSavedForm,
+ },
};
-use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-use url::{ParseError, Url};
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "post"]
-pub struct Post {
- pub id: i32,
- pub name: String,
- pub url: Option<String>,
- pub body: Option<String>,
- pub creator_id: i32,
- pub community_id: i32,
- pub removed: bool,
- pub locked: bool,
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub deleted: bool,
- pub nsfw: bool,
- pub stickied: bool,
- pub embed_title: Option<String>,
- pub embed_description: Option<String>,
- pub embed_html: Option<String>,
- pub thumbnail_url: Option<String>,
- pub ap_id: String,
- pub local: bool,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "post"]
-pub struct PostForm {
- pub name: String,
- pub url: Option<String>,
- pub body: Option<String>,
- pub creator_id: i32,
- pub community_id: i32,
- pub removed: Option<bool>,
- pub locked: Option<bool>,
- pub published: Option<chrono::NaiveDateTime>,
- pub updated: Option<chrono::NaiveDateTime>,
- pub deleted: Option<bool>,
- pub nsfw: bool,
- pub stickied: Option<bool>,
- pub embed_title: Option<String>,
- pub embed_description: Option<String>,
- pub embed_html: Option<String>,
- pub thumbnail_url: Option<String>,
- pub ap_id: Option<String>,
- pub local: bool,
-}
-
-impl PostForm {
- pub fn get_ap_id(&self) -> Result<Url, ParseError> {
- Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
- }
-}
impl Crud<PostForm> for Post {
fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
+ use lemmy_db_schema::schema::post::dsl::*;
post.find(post_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, post_id: i32) -> Result<usize, Error> {
- use crate::schema::post::dsl::*;
+ use lemmy_db_schema::schema::post::dsl::*;
diesel::delete(post.find(post_id)).execute(conn)
}
fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
+ use lemmy_db_schema::schema::post::dsl::*;
insert_into(post).values(new_post).get_result::<Self>(conn)
}
fn update(conn: &PgConnection, post_id: i32, new_post: &PostForm) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
+ use lemmy_db_schema::schema::post::dsl::*;
diesel::update(post.find(post_id))
.set(new_post)
.get_result::<Self>(conn)
}
}
-impl ApubObject<PostForm> for Post {
- fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
- post.filter(ap_id.eq(object_id)).first::<Self>(conn)
- }
-
- fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
- use crate::schema::post::dsl::*;
- insert_into(post)
- .values(post_form)
- .on_conflict(ap_id)
- .do_update()
- .set(post_form)
- .get_result::<Self>(conn)
- }
+pub trait Post_ {
+ //fn read(conn: &PgConnection, post_id: i32) -> Result<Post, Error>;
+ fn list_for_community(conn: &PgConnection, the_community_id: i32) -> Result<Vec<Post>, Error>;
+ fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Post, Error>;
+ fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result<Vec<Post>, Error>;
+ fn update_deleted(conn: &PgConnection, post_id: i32, new_deleted: bool) -> Result<Post, Error>;
+ fn update_removed(conn: &PgConnection, post_id: i32, new_removed: bool) -> Result<Post, Error>;
+ fn update_removed_for_creator(
+ conn: &PgConnection,
+ for_creator_id: i32,
+ for_community_id: Option<i32>,
+ new_removed: bool,
+ ) -> Result<Vec<Post>, Error>;
+ fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Post, Error>;
+ fn update_stickied(conn: &PgConnection, post_id: i32, new_stickied: bool) -> Result<Post, Error>;
+ fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool;
}
-impl Post {
- pub fn list_for_community(
- conn: &PgConnection,
- the_community_id: i32,
- ) -> Result<Vec<Self>, Error> {
- use crate::schema::post::dsl::*;
+impl Post_ for Post {
+ fn list_for_community(conn: &PgConnection, the_community_id: i32) -> Result<Vec<Self>, Error> {
+ use lemmy_db_schema::schema::post::dsl::*;
post
.filter(community_id.eq(the_community_id))
.then_order_by(published.desc())
.load::<Self>(conn)
}
- pub fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
+ fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::post::dsl::*;
diesel::update(post.find(post_id))
.set(ap_id.eq(apub_id))
.get_result::<Self>(conn)
}
- pub fn permadelete_for_creator(
- conn: &PgConnection,
- for_creator_id: i32,
- ) -> Result<Vec<Self>, Error> {
- use crate::schema::post::dsl::*;
+ fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result<Vec<Self>, Error> {
+ use lemmy_db_schema::schema::post::dsl::*;
let perma_deleted = "*Permananently Deleted*";
let perma_deleted_url = "https://deleted.com";
.get_results::<Self>(conn)
}
- pub fn update_deleted(
- conn: &PgConnection,
- post_id: i32,
- new_deleted: bool,
- ) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
+ fn update_deleted(conn: &PgConnection, post_id: i32, new_deleted: bool) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::post::dsl::*;
diesel::update(post.find(post_id))
.set((deleted.eq(new_deleted), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
- pub fn update_removed(
- conn: &PgConnection,
- post_id: i32,
- new_removed: bool,
- ) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
+ fn update_removed(conn: &PgConnection, post_id: i32, new_removed: bool) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::post::dsl::*;
diesel::update(post.find(post_id))
.set((removed.eq(new_removed), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
- pub fn update_removed_for_creator(
+ fn update_removed_for_creator(
conn: &PgConnection,
for_creator_id: i32,
for_community_id: Option<i32>,
new_removed: bool,
) -> Result<Vec<Self>, Error> {
- use crate::schema::post::dsl::*;
+ use lemmy_db_schema::schema::post::dsl::*;
let mut update = diesel::update(post).into_boxed();
update = update.filter(creator_id.eq(for_creator_id));
.get_results::<Self>(conn)
}
- pub fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
+ fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::post::dsl::*;
diesel::update(post.find(post_id))
.set(locked.eq(new_locked))
.get_result::<Self>(conn)
}
- pub fn update_stickied(
- conn: &PgConnection,
- post_id: i32,
- new_stickied: bool,
- ) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
+ fn update_stickied(conn: &PgConnection, post_id: i32, new_stickied: bool) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::post::dsl::*;
diesel::update(post.find(post_id))
.set(stickied.eq(new_stickied))
.get_result::<Self>(conn)
}
- pub fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool {
+ fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool {
user_id == post_creator_id
}
}
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Post)]
-#[table_name = "post_like"]
-pub struct PostLike {
- pub id: i32,
- pub post_id: i32,
- pub user_id: i32,
- pub score: i16,
- pub published: chrono::NaiveDateTime,
-}
+impl ApubObject<PostForm> for Post {
+ fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::post::dsl::*;
+ post.filter(ap_id.eq(object_id)).first::<Self>(conn)
+ }
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "post_like"]
-pub struct PostLikeForm {
- pub post_id: i32,
- pub user_id: i32,
- pub score: i16,
+ fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
+ use lemmy_db_schema::schema::post::dsl::*;
+ insert_into(post)
+ .values(post_form)
+ .on_conflict(ap_id)
+ .do_update()
+ .set(post_form)
+ .get_result::<Self>(conn)
+ }
}
impl Likeable<PostLikeForm> for PostLike {
fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
- use crate::schema::post_like::dsl::*;
+ use lemmy_db_schema::schema::post_like::dsl::*;
insert_into(post_like)
.values(post_like_form)
.on_conflict((post_id, user_id))
.get_result::<Self>(conn)
}
fn remove(conn: &PgConnection, user_id: i32, post_id: i32) -> Result<usize, Error> {
- use crate::schema::post_like::dsl;
+ use lemmy_db_schema::schema::post_like::dsl;
diesel::delete(
dsl::post_like
.filter(dsl::post_id.eq(post_id))
}
}
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Post)]
-#[table_name = "post_saved"]
-pub struct PostSaved {
- pub id: i32,
- pub post_id: i32,
- pub user_id: i32,
- pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "post_saved"]
-pub struct PostSavedForm {
- pub post_id: i32,
- pub user_id: i32,
-}
-
impl Saveable<PostSavedForm> for PostSaved {
fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
- use crate::schema::post_saved::dsl::*;
+ use lemmy_db_schema::schema::post_saved::dsl::*;
insert_into(post_saved)
.values(post_saved_form)
.on_conflict((post_id, user_id))
.get_result::<Self>(conn)
}
fn unsave(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
- use crate::schema::post_saved::dsl::*;
+ use lemmy_db_schema::schema::post_saved::dsl::*;
diesel::delete(
post_saved
.filter(post_id.eq(post_saved_form.post_id))
}
}
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Post)]
-#[table_name = "post_read"]
-pub struct PostRead {
- pub id: i32,
-
- pub post_id: i32,
-
- pub user_id: i32,
-
- pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "post_read"]
-pub struct PostReadForm {
- pub post_id: i32,
-
- pub user_id: i32,
-}
-
impl Readable<PostReadForm> for PostRead {
fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
- use crate::schema::post_read::dsl::*;
+ use lemmy_db_schema::schema::post_read::dsl::*;
insert_into(post_read)
.values(post_read_form)
.get_result::<Self>(conn)
}
fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> {
- use crate::schema::post_read::dsl::*;
+ use lemmy_db_schema::schema::post_read::dsl::*;
diesel::delete(
post_read
.filter(post_id.eq(post_read_form.post_id))
#[cfg(test)]
mod tests {
- use crate::{
- source::{community::*, post::*, user::*},
- tests::establish_unpooled_connection,
- ListingType,
- SortType,
+ use crate::{source::post::*, tests::establish_unpooled_connection, ListingType, SortType};
+ use lemmy_db_schema::source::{
+ community::{Community, CommunityForm},
+ user::*,
};
#[test]
+use crate::Reportable;
use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
-
-use crate::{naive_now, schema::post_report, source::post::Post, Reportable};
-
-#[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
/// * `conn` - the postgres connection
/// * `post_report_form` - the filled CommentReportForm to insert
fn report(conn: &PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
- use crate::schema::post_report::dsl::*;
+ use lemmy_db_schema::schema::post_report::dsl::*;
insert_into(post_report)
.values(post_report_form)
.get_result::<Self>(conn)
/// * `report_id` - the id of the report to resolve
/// * `by_resolver_id` - the id of the user resolving the report
fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
- use crate::schema::post_report::dsl::*;
+ use lemmy_db_schema::schema::post_report::dsl::*;
update(post_report.find(report_id))
.set((
resolved.eq(true),
/// * `report_id` - the id of the report to unresolve
/// * `by_resolver_id` - the id of the user unresolving the report
fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
- use crate::schema::post_report::dsl::*;
+ use lemmy_db_schema::schema::post_report::dsl::*;
update(post_report.find(report_id))
.set((
resolved.eq(false),
-use crate::{naive_now, schema::private_message, ApubObject, Crud};
+use crate::{ApubObject, Crud};
use diesel::{dsl::*, result::Error, *};
-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> {
- use crate::schema::private_message::dsl::*;
+ use lemmy_db_schema::schema::private_message::dsl::*;
private_message.find(private_message_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
- use crate::schema::private_message::dsl::*;
+ use lemmy_db_schema::schema::private_message::dsl::*;
insert_into(private_message)
.values(private_message_form)
.get_result::<Self>(conn)
private_message_id: i32,
private_message_form: &PrivateMessageForm,
) -> Result<Self, Error> {
- use crate::schema::private_message::dsl::*;
+ use lemmy_db_schema::schema::private_message::dsl::*;
diesel::update(private_message.find(private_message_id))
.set(private_message_form)
.get_result::<Self>(conn)
where
Self: Sized,
{
- use crate::schema::private_message::dsl::*;
+ use lemmy_db_schema::schema::private_message::dsl::*;
private_message
.filter(ap_id.eq(object_id))
.first::<Self>(conn)
}
fn upsert(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
- use crate::schema::private_message::dsl::*;
+ use lemmy_db_schema::schema::private_message::dsl::*;
insert_into(private_message)
.values(private_message_form)
.on_conflict(ap_id)
}
}
-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> {
- use crate::schema::private_message::dsl::*;
+ ) -> 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))
.set(ap_id.eq(apub_id))
.get_result::<Self>(conn)
}
- pub fn update_content(
+ fn update_content(
conn: &PgConnection,
private_message_id: i32,
new_content: &str,
- ) -> Result<Self, Error> {
- use crate::schema::private_message::dsl::*;
+ ) -> 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> {
- use crate::schema::private_message::dsl::*;
+ ) -> 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> {
- use crate::schema::private_message::dsl::*;
+ ) -> 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> {
- use crate::schema::private_message::dsl::*;
+ 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
.filter(recipient_id.eq(for_recipient_id))
#[cfg(test)]
mod tests {
- use crate::{
- source::{private_message::*, user::*},
- tests::establish_unpooled_connection,
- ListingType,
- SortType,
- };
+ use crate::{tests::establish_unpooled_connection, ListingType, SortType};
+ use lemmy_db_schema::source::{private_message::*, user::*};
#[test]
fn test_crud() {
-use crate::{naive_now, schema::site, Crud};
+use crate::Crud;
use diesel::{dsl::*, result::Error, *};
-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> {
- use crate::schema::site::dsl::*;
+ use lemmy_db_schema::schema::site::dsl::*;
site.first::<Self>(conn)
}
fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
- use crate::schema::site::dsl::*;
+ use lemmy_db_schema::schema::site::dsl::*;
insert_into(site).values(new_site).get_result::<Self>(conn)
}
fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
- use crate::schema::site::dsl::*;
+ use lemmy_db_schema::schema::site::dsl::*;
diesel::update(site.find(site_id))
.set(new_site)
.get_result::<Self>(conn)
}
fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
- use crate::schema::site::dsl::*;
+ use lemmy_db_schema::schema::site::dsl::*;
diesel::delete(site.find(site_id)).execute(conn)
}
}
-impl Site {
- pub fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Self, Error> {
- use crate::schema::site::dsl::*;
+pub trait Site_ {
+ fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error>;
+ fn read_simple(conn: &PgConnection) -> 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())))
.get_result::<Self>(conn)
}
- pub fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
- use crate::schema::site::dsl::*;
+ fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
+ use lemmy_db_schema::schema::site::dsl::*;
site.first::<Self>(conn)
}
}
-use crate::{
- is_email_regex,
- naive_now,
- schema::{user_, user_::dsl::*, user_alias_1, user_alias_2},
- ApubObject,
- Crud,
-};
+use crate::{is_email_regex, ApubObject, Crud};
use bcrypt::{hash, DEFAULT_COST};
use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::{
+ naive_now,
+ schema::user_::dsl::*,
+ source::user::{UserForm, User_},
+};
use lemmy_utils::settings::Settings;
-use serde::Serialize;
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_"]
-pub struct User_ {
- pub id: i32,
- pub name: String,
- pub preferred_username: Option<String>,
- pub password_encrypted: String,
- pub email: Option<String>,
- pub avatar: Option<String>,
- pub admin: bool,
- pub banned: bool,
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub show_nsfw: bool,
- pub theme: String,
- pub default_sort_type: i16,
- pub default_listing_type: i16,
- pub lang: String,
- pub show_avatars: bool,
- pub send_notifications_to_email: bool,
- pub matrix_user_id: Option<String>,
- pub actor_id: String,
- pub bio: Option<String>,
- pub local: bool,
- pub private_key: Option<String>,
- pub public_key: Option<String>,
- pub last_refreshed_at: chrono::NaiveDateTime,
- pub banner: Option<String>,
- pub deleted: bool,
-}
-
-/// A safe representation of user, without the sensitive info
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_"]
-pub struct UserSafe {
- pub id: i32,
- pub name: String,
- pub preferred_username: Option<String>,
- pub avatar: Option<String>,
- pub admin: bool,
- pub banned: bool,
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub matrix_user_id: Option<String>,
- pub actor_id: String,
- pub bio: Option<String>,
- pub local: bool,
- pub banner: Option<String>,
- pub deleted: bool,
-}
mod safe_type {
- use crate::{schema::user_::columns::*, source::user::User_, ToSafe};
+ use crate::ToSafe;
+ use lemmy_db_schema::{schema::user_::columns::*, source::user::User_};
+
type Columns = (
id,
name,
}
}
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_1"]
-pub struct UserAlias1 {
- pub id: i32,
- pub name: String,
- pub preferred_username: Option<String>,
- pub password_encrypted: String,
- pub email: Option<String>,
- pub avatar: Option<String>,
- pub admin: bool,
- pub banned: bool,
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub show_nsfw: bool,
- pub theme: String,
- pub default_sort_type: i16,
- pub default_listing_type: i16,
- pub lang: String,
- pub show_avatars: bool,
- pub send_notifications_to_email: bool,
- pub matrix_user_id: Option<String>,
- pub actor_id: String,
- pub bio: Option<String>,
- pub local: bool,
- pub private_key: Option<String>,
- pub public_key: Option<String>,
- pub last_refreshed_at: chrono::NaiveDateTime,
- pub banner: Option<String>,
- pub deleted: bool,
-}
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_1"]
-pub struct UserSafeAlias1 {
- pub id: i32,
- pub name: String,
- pub preferred_username: Option<String>,
- pub avatar: Option<String>,
- pub admin: bool,
- pub banned: bool,
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub matrix_user_id: Option<String>,
- pub actor_id: String,
- pub bio: Option<String>,
- pub local: bool,
- pub banner: Option<String>,
- pub deleted: bool,
-}
-
mod safe_type_alias_1 {
- use crate::{schema::user_alias_1::columns::*, source::user::UserAlias1, ToSafe};
+ use crate::ToSafe;
+ use lemmy_db_schema::{schema::user_alias_1::columns::*, source::user::UserAlias1};
+
type Columns = (
id,
name,
}
}
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_2"]
-pub struct UserAlias2 {
- pub id: i32,
- pub name: String,
- pub preferred_username: Option<String>,
- pub password_encrypted: String,
- pub email: Option<String>,
- pub avatar: Option<String>,
- pub admin: bool,
- pub banned: bool,
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub show_nsfw: bool,
- pub theme: String,
- pub default_sort_type: i16,
- pub default_listing_type: i16,
- pub lang: String,
- pub show_avatars: bool,
- pub send_notifications_to_email: bool,
- pub matrix_user_id: Option<String>,
- pub actor_id: String,
- pub bio: Option<String>,
- pub local: bool,
- pub private_key: Option<String>,
- pub public_key: Option<String>,
- pub last_refreshed_at: chrono::NaiveDateTime,
- pub banner: Option<String>,
- pub deleted: bool,
-}
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_2"]
-pub struct UserSafeAlias2 {
- pub id: i32,
- pub name: String,
- pub preferred_username: Option<String>,
- pub avatar: Option<String>,
- pub admin: bool,
- pub banned: bool,
- pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>,
- pub matrix_user_id: Option<String>,
- pub actor_id: String,
- pub bio: Option<String>,
- pub local: bool,
- pub banner: Option<String>,
- pub deleted: bool,
-}
-
mod safe_type_alias_2 {
- use crate::{schema::user_alias_2::columns::*, source::user::UserAlias2, ToSafe};
+ use crate::ToSafe;
+ use lemmy_db_schema::{schema::user_alias_2::columns::*, source::user::UserAlias2};
+
type Columns = (
id,
name,
}
}
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "user_"]
-pub struct UserForm {
- pub name: String,
- pub preferred_username: Option<Option<String>>,
- pub password_encrypted: String,
- pub admin: bool,
- pub banned: Option<bool>,
- pub email: Option<Option<String>>,
- pub avatar: Option<Option<String>>,
- pub published: Option<chrono::NaiveDateTime>,
- pub updated: Option<chrono::NaiveDateTime>,
- pub show_nsfw: bool,
- pub theme: String,
- pub default_sort_type: i16,
- pub default_listing_type: i16,
- pub lang: String,
- pub show_avatars: bool,
- pub send_notifications_to_email: bool,
- pub matrix_user_id: Option<Option<String>>,
- pub actor_id: Option<String>,
- pub bio: Option<Option<String>>,
- pub local: bool,
- pub private_key: Option<String>,
- pub public_key: Option<String>,
- pub last_refreshed_at: Option<chrono::NaiveDateTime>,
- pub banner: Option<Option<String>>,
-}
-
impl Crud<UserForm> for User_ {
fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
user_
impl ApubObject<UserForm> for User_ {
fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
- use crate::schema::user_::dsl::*;
+ use lemmy_db_schema::schema::user_::dsl::*;
user_
.filter(deleted.eq(false))
.filter(actor_id.eq(object_id))
}
}
-impl User_ {
- pub fn register(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
+pub trait User {
+ fn register(conn: &PgConnection, form: &UserForm) -> Result<User_, Error>;
+ fn update_password(conn: &PgConnection, user_id: i32, new_password: &str)
+ -> Result<User_, Error>;
+ fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<User_, Error>;
+ fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<User_, Error>;
+ fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<User_, Error>;
+ fn find_by_email_or_username(
+ conn: &PgConnection,
+ username_or_email: &str,
+ ) -> Result<User_, Error>;
+ fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error>;
+ fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error>;
+ fn get_profile_url(&self, hostname: &str) -> String;
+ fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error>;
+ fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error>;
+}
+
+impl User for User_ {
+ fn register(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
let mut edited_user = form.clone();
let password_hash =
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
}
// TODO do more individual updates like these
- pub fn update_password(
- conn: &PgConnection,
- user_id: i32,
- new_password: &str,
- ) -> Result<Self, Error> {
+ fn update_password(conn: &PgConnection, user_id: i32, new_password: &str) -> Result<Self, Error> {
let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password");
diesel::update(user_.find(user_id))
.get_result::<Self>(conn)
}
- pub fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<Self, Error> {
+ fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<Self, Error> {
user_
.filter(local.eq(true))
.filter(deleted.eq(false))
.first::<Self>(conn)
}
- pub fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<Self, Error> {
+ fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<Self, Error> {
diesel::update(user_.find(user_id))
.set(admin.eq(added))
.get_result::<Self>(conn)
}
- pub fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<Self, Error> {
+ fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<Self, Error> {
diesel::update(user_.find(user_id))
.set(banned.eq(ban))
.get_result::<Self>(conn)
}
- pub fn find_by_email_or_username(
+ fn find_by_email_or_username(
conn: &PgConnection,
username_or_email: &str,
) -> Result<Self, Error> {
}
}
- pub fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
+ fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
user_
.filter(deleted.eq(false))
.filter(local.eq(true))
.first::<User_>(conn)
}
- pub fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
+ fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
user_
.filter(deleted.eq(false))
.filter(local.eq(true))
.first::<User_>(conn)
}
- pub fn get_profile_url(&self, hostname: &str) -> String {
+ fn get_profile_url(&self, hostname: &str) -> String {
format!(
"{}://{}/u/{}",
Settings::get().get_protocol_string(),
)
}
- pub fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
+ fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
diesel::update(user_.find(user_id))
.set((last_refreshed_at.eq(naive_now()),))
.get_result::<Self>(conn)
}
- pub fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
+ fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
diesel::update(user_.find(user_id))
.set((
preferred_username.eq::<Option<String>>(None),
-use super::comment::Comment;
-use crate::{schema::user_mention, Crud};
+use crate::Crud;
use diesel::{dsl::*, result::Error, *};
-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> {
- use crate::schema::user_mention::dsl::*;
+ use lemmy_db_schema::schema::user_mention::dsl::*;
user_mention.find(user_mention_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> {
- use crate::schema::user_mention::dsl::*;
+ use lemmy_db_schema::schema::user_mention::dsl::*;
// since the return here isnt utilized, we dont need to do an update
// but get_result doesnt return the existing row here
insert_into(user_mention)
user_mention_id: i32,
user_mention_form: &UserMentionForm,
) -> Result<Self, Error> {
- use crate::schema::user_mention::dsl::*;
+ use lemmy_db_schema::schema::user_mention::dsl::*;
diesel::update(user_mention.find(user_mention_id))
.set(user_mention_form)
.get_result::<Self>(conn)
}
}
-impl UserMention {
- pub fn update_read(
+pub trait UserMention_ {
+ fn update_read(
conn: &PgConnection,
user_mention_id: i32,
new_read: bool,
- ) -> Result<Self, Error> {
- use crate::schema::user_mention::dsl::*;
+ ) -> 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> {
- use crate::schema::user_mention::dsl::*;
+ 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
.filter(recipient_id.eq(for_recipient_id))
#[cfg(test)]
mod tests {
- use crate::{
- source::{comment::*, community::*, post::*, user::*, user_mention::*},
- tests::establish_unpooled_connection,
- 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]
-use crate::{
- limit_and_offset,
+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,
post::Post,
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
},
- views::ViewToVec,
- MaybeOptional,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, PartialEq, Serialize, Clone)]
functions::hot_rank,
fuzzy_search,
limit_and_offset,
+ views::ViewToVec,
+ ListingType,
+ MaybeOptional,
+ SortType,
+ ToSafe,
+};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
schema::{
comment,
comment_aggregates,
post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
- views::ViewToVec,
- ListingType,
- MaybeOptional,
- SortType,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, PartialEq, Serialize, Clone)]
#[cfg(test)]
mod tests {
- use crate::{
- source::{comment::*, community::*, post::*, user::*},
- tests::establish_unpooled_connection,
- views::comment_view::*,
- Crud,
- Likeable,
- *,
- };
+ use crate::{tests::establish_unpooled_connection, views::comment_view::*, Crud, Likeable, *};
+ use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
#[test]
fn test_crud() {
-use crate::{
+use crate::{views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
schema::{community, community_follower, user_},
source::{
community::{Community, CommunitySafe},
user::{UserSafe, User_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
+use crate::{views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
schema::{community, community_moderator, user_},
source::{
community::{Community, CommunitySafe},
user::{UserSafe, User_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
+use crate::ToSafe;
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
schema::{community, community_user_ban, user_},
source::{
community::{Community, CommunitySafe},
user::{UserSafe, User_},
},
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
functions::hot_rank,
fuzzy_search,
limit_and_offset,
+ views::ViewToVec,
+ MaybeOptional,
+ SortType,
+ ToSafe,
+};
+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_},
},
- views::ViewToVec,
- MaybeOptional,
- SortType,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+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_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
schema::{mod_add, user_, user_alias_1},
source::{
moderator::ModAdd,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+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_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
schema::{mod_ban, user_, user_alias_1},
source::{
moderator::ModBan,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+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},
post::Post,
user::{UserSafe, User_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+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,
post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+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_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+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},
post::Post,
user::{UserSafe, User_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+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},
post::Post,
user::{UserSafe, User_},
},
- views::ViewToVec,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
-use crate::{
- limit_and_offset,
+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_report::PostReport,
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
},
- views::ViewToVec,
- MaybeOptional,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, PartialEq, Serialize, Clone)]
functions::hot_rank,
fuzzy_search,
limit_and_offset,
+ views::ViewToVec,
+ ListingType,
+ MaybeOptional,
+ SortType,
+ ToSafe,
+};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
schema::{
community,
community_follower,
post::{Post, PostRead, PostSaved},
user::{UserSafe, User_},
},
- views::ViewToVec,
- ListingType,
- MaybeOptional,
- SortType,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, PartialEq, Serialize, Clone)]
mod tests {
use crate::{
aggregates::post_aggregates::PostAggregates,
- source::{community::*, post::*, user::*},
tests::establish_unpooled_connection,
views::post_view::{PostQueryBuilder, PostView},
Crud,
Likeable,
*,
};
+ use lemmy_db_schema::source::{community::*, post::*, user::*};
#[test]
fn test_crud() {
-use crate::{
- limit_and_offset,
+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::{
private_message::PrivateMessage,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
- views::ViewToVec,
- MaybeOptional,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, PartialEq, Serialize, Clone)]
-use crate::{
- aggregates::site_aggregates::SiteAggregates,
+use crate::{aggregates::site_aggregates::SiteAggregates, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
schema::{site, site_aggregates, user_},
source::{
site::Site,
user::{UserSafe, User_},
},
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
aggregates::comment_aggregates::CommentAggregates,
functions::hot_rank,
limit_and_offset,
+ views::ViewToVec,
+ MaybeOptional,
+ SortType,
+ ToSafe,
+};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
schema::{
comment,
comment_aggregates,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
user_mention::UserMention,
},
- views::ViewToVec,
- MaybeOptional,
- SortType,
- ToSafe,
};
-use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, PartialEq, Serialize, Clone)]
aggregates::user_aggregates::UserAggregates,
fuzzy_search,
limit_and_offset,
- schema::{user_, user_aggregates},
- source::user::{UserSafe, User_},
views::ViewToVec,
MaybeOptional,
SortType,
ToSafe,
};
use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::{
+ schema::{user_, user_aggregates},
+ source::user::{UserSafe, User_},
+};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
--- /dev/null
+[package]
+name = "lemmy_db_schema"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
+chrono = { version = "0.4.19", features = ["serde"] }
+serde = { version = "1.0.118", features = ["derive"] }
+serde_json = { version = "1.0.60", features = ["preserve_order"] }
+log = "0.4.11"
+url = { version = "2.2.0", features = ["serde"] }
--- /dev/null
+#[macro_use]
+extern crate diesel;
+
+use chrono::NaiveDateTime;
+
+pub mod schema;
+pub mod source;
+
+// TODO: can probably move this back to lemmy_db
+pub fn naive_now() -> NaiveDateTime {
+ chrono::prelude::Utc::now().naive_utc()
+}
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+use crate::{
+ schema::{comment, comment_alias_1, comment_like, comment_saved},
+ source::post::Post,
+};
+use serde::Serialize;
+use url::{ParseError, Url};
+
+// WITH RECURSIVE MyTree AS (
+// SELECT * FROM comment WHERE parent_id IS NULL
+// UNION ALL
+// SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
+// )
+// SELECT * FROM MyTree;
+
+#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
+#[belongs_to(Post)]
+#[table_name = "comment"]
+pub struct Comment {
+ pub id: i32,
+ pub creator_id: i32,
+ pub post_id: i32,
+ pub parent_id: Option<i32>,
+ pub content: String,
+ pub removed: bool,
+ pub read: bool, // Whether the recipient has read the comment or not
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub deleted: bool,
+ pub ap_id: String,
+ pub local: bool,
+}
+
+#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
+#[belongs_to(Post)]
+#[table_name = "comment_alias_1"]
+pub struct CommentAlias1 {
+ pub id: i32,
+ pub creator_id: i32,
+ pub post_id: i32,
+ pub parent_id: Option<i32>,
+ pub content: String,
+ pub removed: bool,
+ pub read: bool, // Whether the recipient has read the comment or not
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub deleted: bool,
+ pub ap_id: String,
+ pub local: bool,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "comment"]
+pub struct CommentForm {
+ pub creator_id: i32,
+ pub post_id: i32,
+ pub parent_id: Option<i32>,
+ pub content: String,
+ pub removed: Option<bool>,
+ pub read: Option<bool>,
+ pub published: Option<chrono::NaiveDateTime>,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub deleted: Option<bool>,
+ pub ap_id: Option<String>,
+ pub local: bool,
+}
+
+impl CommentForm {
+ pub fn get_ap_id(&self) -> Result<Url, ParseError> {
+ Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
+ }
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
+#[belongs_to(Comment)]
+#[table_name = "comment_like"]
+pub struct CommentLike {
+ pub id: i32,
+ pub user_id: i32,
+ pub comment_id: i32,
+ pub post_id: i32, // TODO this is redundant
+ pub score: i16,
+ pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "comment_like"]
+pub struct CommentLikeForm {
+ pub user_id: i32,
+ pub comment_id: i32,
+ pub post_id: i32, // TODO this is redundant
+ pub score: i16,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Comment)]
+#[table_name = "comment_saved"]
+pub struct CommentSaved {
+ pub id: i32,
+ pub comment_id: i32,
+ pub user_id: i32,
+ pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "comment_saved"]
+pub struct CommentSavedForm {
+ pub comment_id: i32,
+ pub user_id: i32,
+}
--- /dev/null
+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,
+}
--- /dev/null
+use crate::schema::{community, community_follower, community_moderator, community_user_ban};
+use serde::Serialize;
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "community"]
+pub struct Community {
+ pub id: i32,
+ pub name: String,
+ pub title: String,
+ pub description: Option<String>,
+ pub category_id: i32,
+ pub creator_id: i32,
+ pub removed: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub deleted: bool,
+ pub nsfw: bool,
+ pub actor_id: String,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: chrono::NaiveDateTime,
+ pub icon: Option<String>,
+ pub banner: Option<String>,
+}
+
+/// A safe representation of community, without the sensitive info
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "community"]
+pub struct CommunitySafe {
+ pub id: i32,
+ pub name: String,
+ pub title: String,
+ pub description: Option<String>,
+ pub category_id: i32,
+ pub creator_id: i32,
+ pub removed: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub deleted: bool,
+ pub nsfw: bool,
+ pub actor_id: String,
+ pub local: bool,
+ pub icon: Option<String>,
+ pub banner: Option<String>,
+}
+
+#[derive(Insertable, AsChangeset, Debug)]
+#[table_name = "community"]
+pub struct CommunityForm {
+ pub name: String,
+ pub title: String,
+ pub description: Option<String>,
+ pub category_id: i32,
+ pub creator_id: i32,
+ pub removed: Option<bool>,
+ pub published: Option<chrono::NaiveDateTime>,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub deleted: Option<bool>,
+ pub nsfw: bool,
+ pub actor_id: Option<String>,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: Option<chrono::NaiveDateTime>,
+ pub icon: Option<Option<String>>,
+ pub banner: Option<Option<String>>,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Community)]
+#[table_name = "community_moderator"]
+pub struct CommunityModerator {
+ pub id: i32,
+ pub community_id: i32,
+ pub user_id: i32,
+ pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "community_moderator"]
+pub struct CommunityModeratorForm {
+ pub community_id: i32,
+ pub user_id: i32,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Community)]
+#[table_name = "community_user_ban"]
+pub struct CommunityUserBan {
+ pub id: i32,
+ pub community_id: i32,
+ pub user_id: i32,
+ pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "community_user_ban"]
+pub struct CommunityUserBanForm {
+ pub community_id: i32,
+ pub user_id: i32,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Community)]
+#[table_name = "community_follower"]
+pub struct CommunityFollower {
+ pub id: i32,
+ pub community_id: i32,
+ pub user_id: i32,
+ pub published: chrono::NaiveDateTime,
+ pub pending: Option<bool>,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "community_follower"]
+pub struct CommunityFollowerForm {
+ pub community_id: i32,
+ pub user_id: i32,
+ pub pending: bool,
+}
--- /dev/null
+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;
--- /dev/null
+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>,
+}
--- /dev/null
+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,
+}
--- /dev/null
+use crate::schema::{post, post_like, post_read, post_saved};
+use serde::Serialize;
+use url::{ParseError, Url};
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "post"]
+pub struct Post {
+ pub id: i32,
+ pub name: String,
+ pub url: Option<String>,
+ pub body: Option<String>,
+ pub creator_id: i32,
+ pub community_id: i32,
+ pub removed: bool,
+ pub locked: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub deleted: bool,
+ pub nsfw: bool,
+ pub stickied: bool,
+ pub embed_title: Option<String>,
+ pub embed_description: Option<String>,
+ pub embed_html: Option<String>,
+ pub thumbnail_url: Option<String>,
+ pub ap_id: String,
+ pub local: bool,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "post"]
+pub struct PostForm {
+ pub name: String,
+ pub url: Option<String>,
+ pub body: Option<String>,
+ pub creator_id: i32,
+ pub community_id: i32,
+ pub removed: Option<bool>,
+ pub locked: Option<bool>,
+ pub published: Option<chrono::NaiveDateTime>,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub deleted: Option<bool>,
+ pub nsfw: bool,
+ pub stickied: Option<bool>,
+ pub embed_title: Option<String>,
+ pub embed_description: Option<String>,
+ pub embed_html: Option<String>,
+ pub thumbnail_url: Option<String>,
+ pub ap_id: Option<String>,
+ pub local: bool,
+}
+
+impl PostForm {
+ pub fn get_ap_id(&self) -> Result<Url, ParseError> {
+ Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
+ }
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Post)]
+#[table_name = "post_like"]
+pub struct PostLike {
+ pub id: i32,
+ pub post_id: i32,
+ pub user_id: i32,
+ pub score: i16,
+ pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "post_like"]
+pub struct PostLikeForm {
+ pub post_id: i32,
+ pub user_id: i32,
+ pub score: i16,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Post)]
+#[table_name = "post_saved"]
+pub struct PostSaved {
+ pub id: i32,
+ pub post_id: i32,
+ pub user_id: i32,
+ pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "post_saved"]
+pub struct PostSavedForm {
+ pub post_id: i32,
+ pub user_id: i32,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Post)]
+#[table_name = "post_read"]
+pub struct PostRead {
+ pub id: i32,
+
+ pub post_id: i32,
+
+ pub user_id: i32,
+
+ pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "post_read"]
+pub struct PostReadForm {
+ pub post_id: i32,
+
+ pub user_id: i32,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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>>,
+}
--- /dev/null
+use crate::schema::{user_, user_alias_1, user_alias_2};
+use serde::Serialize;
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_"]
+pub struct User_ {
+ pub id: i32,
+ pub name: String,
+ pub preferred_username: Option<String>,
+ pub password_encrypted: String,
+ pub email: Option<String>,
+ pub avatar: Option<String>,
+ pub admin: bool,
+ pub banned: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub show_nsfw: bool,
+ pub theme: String,
+ pub default_sort_type: i16,
+ pub default_listing_type: i16,
+ pub lang: String,
+ pub show_avatars: bool,
+ pub send_notifications_to_email: bool,
+ pub matrix_user_id: Option<String>,
+ pub actor_id: String,
+ pub bio: Option<String>,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: chrono::NaiveDateTime,
+ pub banner: Option<String>,
+ pub deleted: bool,
+}
+
+/// A safe representation of user, without the sensitive info
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_"]
+pub struct UserSafe {
+ pub id: i32,
+ pub name: String,
+ pub preferred_username: Option<String>,
+ pub avatar: Option<String>,
+ pub admin: bool,
+ pub banned: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub matrix_user_id: Option<String>,
+ pub actor_id: String,
+ pub bio: Option<String>,
+ pub local: bool,
+ pub banner: Option<String>,
+ pub deleted: bool,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_alias_1"]
+pub struct UserAlias1 {
+ pub id: i32,
+ pub name: String,
+ pub preferred_username: Option<String>,
+ pub password_encrypted: String,
+ pub email: Option<String>,
+ pub avatar: Option<String>,
+ pub admin: bool,
+ pub banned: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub show_nsfw: bool,
+ pub theme: String,
+ pub default_sort_type: i16,
+ pub default_listing_type: i16,
+ pub lang: String,
+ pub show_avatars: bool,
+ pub send_notifications_to_email: bool,
+ pub matrix_user_id: Option<String>,
+ pub actor_id: String,
+ pub bio: Option<String>,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: chrono::NaiveDateTime,
+ pub banner: Option<String>,
+ pub deleted: bool,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_alias_1"]
+pub struct UserSafeAlias1 {
+ pub id: i32,
+ pub name: String,
+ pub preferred_username: Option<String>,
+ pub avatar: Option<String>,
+ pub admin: bool,
+ pub banned: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub matrix_user_id: Option<String>,
+ pub actor_id: String,
+ pub bio: Option<String>,
+ pub local: bool,
+ pub banner: Option<String>,
+ pub deleted: bool,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_alias_2"]
+pub struct UserAlias2 {
+ pub id: i32,
+ pub name: String,
+ pub preferred_username: Option<String>,
+ pub password_encrypted: String,
+ pub email: Option<String>,
+ pub avatar: Option<String>,
+ pub admin: bool,
+ pub banned: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub show_nsfw: bool,
+ pub theme: String,
+ pub default_sort_type: i16,
+ pub default_listing_type: i16,
+ pub lang: String,
+ pub show_avatars: bool,
+ pub send_notifications_to_email: bool,
+ pub matrix_user_id: Option<String>,
+ pub actor_id: String,
+ pub bio: Option<String>,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: chrono::NaiveDateTime,
+ pub banner: Option<String>,
+ pub deleted: bool,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_alias_2"]
+pub struct UserSafeAlias2 {
+ pub id: i32,
+ pub name: String,
+ pub preferred_username: Option<String>,
+ pub avatar: Option<String>,
+ pub admin: bool,
+ pub banned: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub matrix_user_id: Option<String>,
+ pub actor_id: String,
+ pub bio: Option<String>,
+ pub local: bool,
+ pub banner: Option<String>,
+ pub deleted: bool,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "user_"]
+pub struct UserForm {
+ pub name: String,
+ pub preferred_username: Option<Option<String>>,
+ pub password_encrypted: String,
+ pub admin: bool,
+ pub banned: Option<bool>,
+ pub email: Option<Option<String>>,
+ pub avatar: Option<Option<String>>,
+ pub published: Option<chrono::NaiveDateTime>,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub show_nsfw: bool,
+ pub theme: String,
+ pub default_sort_type: i16,
+ pub default_listing_type: i16,
+ pub lang: String,
+ pub show_avatars: bool,
+ pub send_notifications_to_email: bool,
+ pub matrix_user_id: Option<Option<String>>,
+ pub actor_id: Option<String>,
+ pub bio: Option<Option<String>>,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: Option<chrono::NaiveDateTime>,
+ pub banner: Option<Option<String>>,
+}
--- /dev/null
+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>,
+}
[dependencies]
lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_utils = { path = "../lemmy_utils" }
serde = { version = "1.0.118", features = ["derive"] }
log = "0.4.11"
pub mod user;
use diesel::PgConnection;
-use lemmy_db::{
- source::{
- comment::Comment,
- post::Post,
- user::User_,
- user_mention::{UserMention, UserMentionForm},
- },
- Crud,
- DbPool,
+use lemmy_db::{source::user::User, Crud, DbPool};
+use lemmy_db_schema::source::{
+ comment::Comment,
+ post::Post,
+ user::User_,
+ user_mention::{UserMention, UserMentionForm},
};
use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
use log::error;
-use lemmy_db::{
- source::{category::*, user::*},
- views::{
- comment_view::CommentView,
- community::community_view::CommunityView,
- moderator::{
- mod_add_community_view::ModAddCommunityView,
- mod_add_view::ModAddView,
- mod_ban_from_community_view::ModBanFromCommunityView,
- mod_ban_view::ModBanView,
- mod_lock_post_view::ModLockPostView,
- mod_remove_comment_view::ModRemoveCommentView,
- mod_remove_community_view::ModRemoveCommunityView,
- mod_remove_post_view::ModRemovePostView,
- mod_sticky_post_view::ModStickyPostView,
- },
- post_view::PostView,
- site_view::SiteView,
- user_view::UserViewSafe,
+use lemmy_db::views::{
+ comment_view::CommentView,
+ community::community_view::CommunityView,
+ moderator::{
+ mod_add_community_view::ModAddCommunityView,
+ mod_add_view::ModAddView,
+ mod_ban_from_community_view::ModBanFromCommunityView,
+ mod_ban_view::ModBanView,
+ mod_lock_post_view::ModLockPostView,
+ mod_remove_comment_view::ModRemoveCommentView,
+ mod_remove_community_view::ModRemoveCommunityView,
+ mod_remove_post_view::ModRemovePostView,
+ mod_sticky_post_view::ModStickyPostView,
},
+ post_view::PostView,
+ site_view::SiteView,
+ user_view::UserViewSafe,
};
+use lemmy_db_schema::source::{category::*, user::User_};
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
lemmy_utils = { path = "../lemmy_utils" }
lemmy_structs = { path = "../lemmy_structs" }
lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
reqwest = { version = "0.10.10", features = ["json"] }
log = "0.4.11"
messages::*,
};
use actix::{Actor, Context, Handler, ResponseFuture};
-use lemmy_db::naive_now;
+use lemmy_db_schema::naive_now;
use log::{error, info};
use rand::Rng;
use serde::Serialize;
*,
};
use lemmy_db::{
+ source::{comment::Comment_, post::Post_, private_message::PrivateMessage_},
+ Crud,
+};
+use lemmy_db_schema::{
naive_now,
source::{
comment::Comment,
private_message::PrivateMessage,
user::{UserForm, User_},
},
- Crud,
};
use lemmy_utils::{
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
}
fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
- use lemmy_db::schema::user_::dsl::*;
+ use lemmy_db_schema::schema::user_::dsl::*;
info!("Running user_updates_2020_04_02");
}
fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
- use lemmy_db::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::*;
info!("Running community_updates_2020_04_02");
}
fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
- use lemmy_db::schema::post::dsl::*;
+ use lemmy_db_schema::schema::post::dsl::*;
info!("Running post_updates_2020_04_03");
}
fn comment_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
- use lemmy_db::schema::comment::dsl::*;
+ use lemmy_db_schema::schema::comment::dsl::*;
info!("Running comment_updates_2020_04_03");
}
fn private_message_updates_2020_05_05(conn: &PgConnection) -> Result<(), LemmyError> {
- use lemmy_db::schema::private_message::dsl::*;
+ use lemmy_db_schema::schema::private_message::dsl::*;
info!("Running private_message_updates_2020_05_05");
}
fn post_thumbnail_url_updates_2020_07_27(conn: &PgConnection) -> Result<(), LemmyError> {
- use lemmy_db::schema::post::dsl::*;
+ use lemmy_db_schema::schema::post::dsl::*;
info!("Running post_thumbnail_url_updates_2020_07_27");
use diesel::PgConnection;
use lemmy_api::claims::Claims;
use lemmy_db::{
- source::{community::Community, user::User_},
+ source::{community::Community_, user::User},
views::{
comment_view::{CommentQueryBuilder, CommentView},
post_view::{PostQueryBuilder, PostView},
ListingType,
SortType,
};
+use lemmy_db_schema::source::{community::Community, user::User_};
use lemmy_structs::blocking;
use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError};
use lemmy_websocket::LemmyContext;
use actix_web::{error::ErrorBadRequest, web::Query, *};
use anyhow::anyhow;
-use lemmy_db::source::{community::Community, user::User_};
+use lemmy_db::source::{community::Community_, user::User};
+use lemmy_db_schema::source::{community::Community, user::User_};
use lemmy_structs::{blocking, WebFingerLink, WebFingerResponse};
use lemmy_utils::{
settings::Settings,
user_inbox::user_inbox,
},
};
-use lemmy_db::{
- source::{
- community::{Community, CommunityForm},
- user::{User_, *},
- },
- Crud,
- ListingType,
- SortType,
+use lemmy_db::{Crud, ListingType, SortType};
+use lemmy_db_schema::source::{
+ community::{Community, CommunityForm},
+ user::{UserForm, User_},
};
use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit};
use lemmy_utils::{apub::generate_actor_keypair, settings::Settings};