Move community to lemmy_db_schema

This commit is contained in:
Felix Ableitner 2020-12-21 13:28:12 +01:00
parent f842bbff8d
commit a7e231b35b
52 changed files with 73369 additions and 335 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

24104
cargo-timing.html Normal file

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,13 @@ use anyhow::Context;
use lemmy_apub::ActorType;
use lemmy_db::{
diesel_option_overwrite,
source::{comment::Comment_, community::*, moderator::*, post::Post_, site::*},
source::{
comment::Comment_,
community::{CommunityModerator_, Community_},
moderator::*,
post::Post_,
site::*,
},
views::{
comment_view::CommentQueryBuilder,
community::{
@ -30,7 +36,7 @@ use lemmy_db::{
};
use lemmy_db_schema::{
naive_now,
source::{comment::Comment, post::Post},
source::{comment::Comment, community::*, post::Post},
};
use lemmy_structs::{blocking, community::*};
use lemmy_utils::{

View file

@ -1,12 +1,16 @@
use crate::claims::Claims;
use actix_web::{web, web::Data};
use lemmy_db::{
source::community::{Community, CommunityModerator},
source::community::{CommunityModerator_, Community_},
views::community::community_user_ban_view::CommunityUserBanView,
Crud,
DbPool,
};
use lemmy_db_schema::source::{post::Post, user::User_};
use lemmy_db_schema::source::{
community::{Community, CommunityModerator},
post::Post,
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};

View file

@ -18,7 +18,7 @@ use lemmy_db::{
diesel_option_overwrite,
source::{
comment::Comment_,
community::*,
community::Community_,
moderator::*,
password_reset_request::*,
post::Post_,
@ -49,7 +49,7 @@ use lemmy_db::{
};
use lemmy_db_schema::{
naive_now,
source::{comment::Comment, post::Post, user::*},
source::{comment::Comment, community::*, post::Post, user::*},
};
use lemmy_structs::{blocking, send_email_to_user, user::*};
use lemmy_utils::{

View file

@ -5,10 +5,11 @@ use activitystreams::{
};
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};

View file

@ -26,8 +26,8 @@ use activitystreams::{
};
use anyhow::anyhow;
use itertools::Itertools;
use lemmy_db::{source::community::Community, Crud, DbPool};
use lemmy_db_schema::source::{comment::Comment, post::Post, user::User_};
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},

View file

@ -23,11 +23,8 @@ use activitystreams::{
};
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;

View file

@ -21,8 +21,8 @@ use activitystreams::{
prelude::*,
public,
};
use lemmy_db::{source::community::Community, Crud};
use lemmy_db_schema::source::{post::Post, user::User_};
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;

View file

@ -13,13 +13,11 @@ use activitystreams::{
base::{AnyBase, BaseExt, ExtendsExt},
object::ObjectExt,
};
use lemmy_db::{
source::community::{Community, CommunityFollower, CommunityFollowerForm},
ApubObject,
DbPool,
Followable,
use lemmy_db::{ApubObject, DbPool, Followable};
use lemmy_db_schema::source::{
community::{Community, CommunityFollower, CommunityFollowerForm},
user::User_,
};
use lemmy_db_schema::source::user::User_;
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;

View file

@ -19,8 +19,8 @@ use background_jobs::{
WorkerConfig,
};
use itertools::Itertools;
use lemmy_db::{source::community::Community, DbPool};
use lemmy_db_schema::source::user::User_;
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};

View file

@ -13,10 +13,7 @@ use anyhow::{anyhow, Context};
use chrono::NaiveDateTime;
use diesel::result::Error::NotFound;
use lemmy_db::{
source::{
community::{Community, CommunityModerator, CommunityModeratorForm},
user::User,
},
source::user::User,
views::{
comment_view::CommentView,
community::community_view::CommunityView,
@ -30,7 +27,12 @@ use lemmy_db::{
};
use lemmy_db_schema::{
naive_now,
source::{comment::Comment, post::Post, user::User_},
source::{
comment::Comment,
community::{Community, CommunityModerator, CommunityModeratorForm},
post::Post,
user::User_,
},
};
use lemmy_structs::{blocking, site::SearchResponse};
use lemmy_utils::{

View file

@ -10,10 +10,10 @@ use activitystreams::{
};
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::post::Post;
use lemmy_db_schema::source::{community::Community, post::Post};
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;

View file

@ -27,13 +27,16 @@ use activitystreams::{
use actix_web::{web, HttpRequest, HttpResponse};
use anyhow::{anyhow, Context};
use lemmy_db::{
source::community::{Community, CommunityFollower, CommunityFollowerForm},
source::community::Community_,
views::community::community_user_ban_view::CommunityUserBanView,
ApubObject,
DbPool,
Followable,
};
use lemmy_db_schema::source::user::User_;
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;

View file

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

View file

@ -15,7 +15,8 @@ use crate::{
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;

View file

@ -49,15 +49,14 @@ 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,
},
source::{private_message::PrivateMessage, user::User},
ApubObject,
Followable,
};
use lemmy_db_schema::source::user::User_;
use lemmy_db_schema::source::{
community::{Community, CommunityFollower},
user::User_,
};
use lemmy_structs::blocking;
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext;

View file

@ -23,9 +23,10 @@ use activitystreams::{
prelude::*,
};
use anyhow::{anyhow, Context};
use lemmy_db::{source::community::Community, Crud, DbPool};
use lemmy_db::{Crud, DbPool};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::Community,
post::Post,
user::User_,
};

View file

@ -22,12 +22,11 @@ use activitystreams::{
};
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_db_schema::naive_now;
use lemmy_structs::blocking;
use lemmy_utils::{
location_info,

View file

@ -20,8 +20,9 @@ use activitystreams::{
};
use activitystreams_ext::Ext1;
use anyhow::Context;
use lemmy_db::{source::community::Community, Crud, DbPool};
use lemmy_db::{Crud, DbPool};
use lemmy_db_schema::source::{
community::Community,
post::{Post, PostForm},
user::User_,
};

View file

@ -24,7 +24,6 @@ impl CommunityAggregates {
mod tests {
use crate::{
aggregates::community_aggregates::CommunityAggregates,
source::community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
tests::establish_unpooled_connection,
Crud,
Followable,
@ -33,6 +32,7 @@ mod tests {
};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
post::{Post, PostForm},
user::{UserForm, User_},
};

View file

@ -26,7 +26,6 @@ impl PostAggregates {
mod tests {
use crate::{
aggregates::post_aggregates::PostAggregates,
source::community::{Community, CommunityForm},
tests::establish_unpooled_connection,
Crud,
Likeable,
@ -35,6 +34,7 @@ mod tests {
};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
};

View file

@ -22,7 +22,6 @@ impl SiteAggregates {
mod tests {
use crate::{
aggregates::site_aggregates::SiteAggregates,
source::community::{Community, CommunityForm},
tests::establish_unpooled_connection,
Crud,
ListingType,
@ -30,6 +29,7 @@ mod tests {
};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
post::{Post, PostForm},
user::{UserForm, User_},
};

View file

@ -25,7 +25,6 @@ impl UserAggregates {
mod tests {
use crate::{
aggregates::user_aggregates::UserAggregates,
source::community::{Community, CommunityForm},
tests::establish_unpooled_connection,
Crud,
Likeable,
@ -34,6 +33,7 @@ mod tests {
};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
};

View file

@ -205,7 +205,6 @@ impl Saveable<CommentSavedForm> for CommentSaved {
#[cfg(test)]
mod tests {
use crate::{
source::community::*,
tests::establish_unpooled_connection,
Crud,
Likeable,
@ -215,6 +214,7 @@ mod tests {
};
use lemmy_db_schema::source::{
comment::*,
community::{Community, CommunityForm},
post::*,
user::{UserForm, User_},
};

View file

@ -9,57 +9,22 @@ use crate::{
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{
naive_now,
schema::{community, community_follower, community_moderator, community_user_ban},
source::community::{
Community,
CommunityFollower,
CommunityFollowerForm,
CommunityForm,
CommunityModerator,
CommunityModeratorForm,
CommunityUserBan,
CommunityUserBanForm,
},
};
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>,
}
mod safe_type {
use crate::{source::community::Community, ToSafe};
use lemmy_db_schema::schema::community::columns::*;
use lemmy_db_schema::schema::community::*;
type Columns = (
id,
name,
@ -102,28 +67,6 @@ mod safe_type {
}
}
#[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 lemmy_db_schema::schema::community::dsl::*;
@ -173,8 +116,35 @@ impl ApubObject<CommunityForm> for Community {
}
}
impl Community {
pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Self, Error> {
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))
@ -182,44 +152,44 @@ impl Community {
.first::<Self>(conn)
}
pub fn update_deleted(
fn update_deleted(
conn: &PgConnection,
community_id: i32,
new_deleted: bool,
) -> Result<Self, Error> {
) -> 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> {
) -> 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> {
) -> 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> {
) -> 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())))
@ -237,35 +207,18 @@ impl Community {
Ok(mods_and_admins)
}
pub fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
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,
@ -291,13 +244,21 @@ impl Joinable<CommunityModeratorForm> for CommunityModerator {
}
}
impl CommunityModerator {
pub fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result<usize, Error> {
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> {
@ -309,23 +270,6 @@ impl CommunityModerator {
}
}
#[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,
@ -351,25 +295,6 @@ impl Bannable<CommunityUserBanForm> for CommunityUserBan {
}
}
#[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,
@ -421,8 +346,16 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
#[cfg(test)]
mod tests {
use crate::{source::community::*, tests::establish_unpooled_connection, ListingType, SortType};
use lemmy_db_schema::source::user::*;
use crate::{
tests::establish_unpooled_connection,
Bannable,
Crud,
Followable,
Joinable,
ListingType,
SortType,
};
use lemmy_db_schema::source::{community::*, user::*};
#[test]
fn test_crud() {

View file

@ -391,12 +391,13 @@ impl Crud<ModAddForm> for ModAdd {
#[cfg(test)]
mod tests {
use crate::{
source::{community::*, moderator::*},
source::moderator::*,
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
use lemmy_db_schema::source::{comment::*, post::*, user::*};
use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
// use Crud;
#[test]

View file

@ -231,13 +231,11 @@ impl Readable<PostReadForm> for PostRead {
#[cfg(test)]
mod tests {
use crate::{
source::{community::*, post::*},
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::*,
};
use lemmy_db_schema::source::user::*;
#[test]
fn test_crud() {

View file

@ -79,12 +79,18 @@ impl UserMention {
#[cfg(test)]
mod tests {
use crate::{
source::{community::*, user_mention::*},
source::user_mention::*,
tests::establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
use lemmy_db_schema::source::{comment::*, post::*, user::*};
use lemmy_db_schema::source::{
comment::*,
community::{Community, CommunityForm},
post::*,
user::*,
};
#[test]
fn test_crud() {

View file

@ -1,9 +1,6 @@
use crate::{
limit_and_offset,
source::{
comment_report::CommentReport,
community::{Community, CommunitySafe},
},
source::comment_report::CommentReport,
views::ViewToVec,
MaybeOptional,
ToSafe,
@ -13,6 +10,7 @@ use lemmy_db_schema::{
schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2},
source::{
comment::Comment,
community::{Community, CommunitySafe},
post::Post,
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
},

View file

@ -3,7 +3,6 @@ use crate::{
functions::hot_rank,
fuzzy_search,
limit_and_offset,
source::community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
views::ViewToVec,
ListingType,
MaybeOptional,
@ -27,6 +26,7 @@ use lemmy_db_schema::{
},
source::{
comment::{Comment, CommentAlias1, CommentSaved},
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
@ -409,15 +409,8 @@ impl ViewToVec for CommentView {
#[cfg(test)]
mod tests {
use crate::{
source::community::*,
tests::establish_unpooled_connection,
views::comment_view::*,
Crud,
Likeable,
*,
};
use lemmy_db_schema::source::{comment::*, post::*, user::*};
use crate::{tests::establish_unpooled_connection, views::comment_view::*, Crud, Likeable, *};
use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
#[test]
fn test_crud() {

View file

@ -1,12 +1,11 @@
use crate::{
source::community::{Community, CommunitySafe},
views::ViewToVec,
ToSafe,
};
use crate::{views::ViewToVec, ToSafe};
use diesel::{result::Error, *};
use lemmy_db_schema::{
schema::{community, community_follower, user_},
source::user::{UserSafe, User_},
source::{
community::{Community, CommunitySafe},
user::{UserSafe, User_},
},
};
use serde::Serialize;

View file

@ -1,12 +1,11 @@
use crate::{
source::community::{Community, CommunitySafe},
views::ViewToVec,
ToSafe,
};
use crate::{views::ViewToVec, ToSafe};
use diesel::{result::Error, *};
use lemmy_db_schema::{
schema::{community, community_moderator, user_},
source::user::{UserSafe, User_},
source::{
community::{Community, CommunitySafe},
user::{UserSafe, User_},
},
};
use serde::Serialize;

View file

@ -1,11 +1,11 @@
use crate::{
source::community::{Community, CommunitySafe},
ToSafe,
};
use crate::ToSafe;
use diesel::{result::Error, *};
use lemmy_db_schema::{
schema::{community, community_user_ban, user_},
source::user::{UserSafe, User_},
source::{
community::{Community, CommunitySafe},
user::{UserSafe, User_},
},
};
use serde::Serialize;

View file

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

View file

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

View file

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

View file

@ -1,16 +1,9 @@
use crate::{
limit_and_offset,
source::{
community::{Community, CommunitySafe},
moderator::ModLockPost,
},
views::ViewToVec,
ToSafe,
};
use crate::{limit_and_offset, source::moderator::ModLockPost, 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_},
},

View file

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

View file

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

View file

@ -1,16 +1,9 @@
use crate::{
limit_and_offset,
source::{
community::{Community, CommunitySafe},
moderator::ModRemovePost,
},
views::ViewToVec,
ToSafe,
};
use crate::{limit_and_offset, source::moderator::ModRemovePost, 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_},
},

View file

@ -1,16 +1,9 @@
use crate::{
limit_and_offset,
source::{
community::{Community, CommunitySafe},
moderator::ModStickyPost,
},
views::ViewToVec,
ToSafe,
};
use crate::{limit_and_offset, source::moderator::ModStickyPost, 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_},
},

View file

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

View file

@ -3,7 +3,6 @@ use crate::{
functions::hot_rank,
fuzzy_search,
limit_and_offset,
source::community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
views::ViewToVec,
ListingType,
MaybeOptional,
@ -24,6 +23,7 @@ use lemmy_db_schema::{
user_,
},
source::{
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
post::{Post, PostRead, PostSaved},
user::{UserSafe, User_},
},
@ -408,14 +408,13 @@ impl ViewToVec for PostView {
mod tests {
use crate::{
aggregates::post_aggregates::PostAggregates,
source::community::*,
tests::establish_unpooled_connection,
views::post_view::{PostQueryBuilder, PostView},
Crud,
Likeable,
*,
};
use lemmy_db_schema::source::{post::*, user::*};
use lemmy_db_schema::source::{community::*, post::*, user::*};
#[test]
fn test_crud() {

View file

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

View file

@ -0,0 +1,121 @@
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,
}

View file

@ -1,3 +1,4 @@
pub mod comment;
pub mod community;
pub mod post;
pub mod user;

View file

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

View file

@ -4,7 +4,7 @@ use chrono::{DateTime, NaiveDateTime, Utc};
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},
@ -14,7 +14,7 @@ use lemmy_db::{
ListingType,
SortType,
};
use lemmy_db_schema::source::user::User_;
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;

View file

@ -1,7 +1,7 @@
use actix_web::{error::ErrorBadRequest, web::Query, *};
use anyhow::anyhow;
use lemmy_db::source::{community::Community, user::User};
use lemmy_db_schema::source::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,

View file

@ -28,13 +28,11 @@ use lemmy_apub::{
user_inbox::user_inbox,
},
};
use lemmy_db::{
source::community::{Community, CommunityForm},
Crud,
ListingType,
SortType,
use lemmy_db::{Crud, ListingType, SortType};
use lemmy_db_schema::source::{
community::{Community, CommunityForm},
user::{UserForm, User_},
};
use lemmy_db_schema::source::user::{UserForm, User_};
use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit};
use lemmy_utils::{apub::generate_actor_keypair, settings::Settings};
use lemmy_websocket::{chat_server::ChatServer, LemmyContext};