From 15930cbf4d5e96dfb62a2406bbb171710fa7529f Mon Sep 17 00:00:00 2001 From: dullbananas Date: Thu, 31 Aug 2023 06:26:10 -0700 Subject: [PATCH] Use Queryable instead of JoinView (#3917) * Update utils.rs * Update traits.rs * Update comment_report_view.rs * Update comment_view.rs * Update local_user_view.rs * Update post_report_view.rs * Update post_view.rs * Update private_message_report_view.rs * Update private_message_view.rs * Update registration_application_view.rs * Update site_view.rs * Update structs.rs * Update comment_reply_view.rs * Update community_block_view.rs * Update community_follower_view.rs * Update community_moderator_view.rs * Update community_person_ban_view.rs * Update community_person_ban_view.rs * Update community_view.rs * Update person_block_view.rs * Update person_mention_view.rs * Update person_view.rs * Update structs.rs * Update admin_purge_comment_view.rs * Update admin_purge_community_view.rs * Update admin_purge_person_view.rs * Update admin_purge_post_view.rs * Update mod_add_community_view.rs * Update mod_add_view.rs * Update mod_ban_from_community_view.rs * Update mod_ban_view.rs * Update mod_feature_post_view.rs * Update mod_hide_community_view.rs * Update mod_lock_post_view.rs * Update mod_remove_comment_view.rs * Update mod_remove_community_view.rs * Update mod_remove_post_view.rs * Update mod_transfer_community_view.rs * Update structs.rs * Update utils.rs * Update private_message_view.rs * Update comment_report_view.rs * Update registration_application_view.rs * Update utils.rs * fix * fix db_views * fix * Update comment_view.rs --- crates/db_schema/src/traits.rs | 7 -- crates/db_schema/src/utils.rs | 44 +++---------- crates/db_views/src/comment_report_view.rs | 47 +------------- crates/db_views/src/comment_view.rs | 64 +++---------------- crates/db_views/src/local_user_view.rs | 20 +----- crates/db_views/src/post_report_view.rs | 38 +---------- crates/db_views/src/post_view.rs | 46 +------------ .../src/private_message_report_view.rs | 31 +-------- crates/db_views/src/private_message_view.rs | 19 +----- .../src/registration_application_view.rs | 27 +------- crates/db_views/src/site_view.rs | 15 ++--- crates/db_views/src/structs.rs | 20 +++--- .../db_views_actor/src/comment_reply_view.rs | 50 +-------------- .../src/community_block_view.rs | 22 +------ .../src/community_follower_view.rs | 22 +------ .../src/community_moderator_view.rs | 38 +++-------- .../src/community_person_ban_view.rs | 9 +-- crates/db_views_actor/src/community_view.rs | 28 ++------ .../db_views_actor/src/person_block_view.rs | 22 +------ .../db_views_actor/src/person_mention_view.rs | 50 +-------------- crates/db_views_actor/src/person_view.rs | 19 +----- crates/db_views_actor/src/structs.rs | 19 +++--- .../src/admin_purge_comment_view.rs | 24 +------ .../src/admin_purge_community_view.rs | 23 +------ .../src/admin_purge_person_view.rs | 23 +------ .../src/admin_purge_post_view.rs | 24 +------ .../src/mod_add_community_view.rs | 25 +------- crates/db_views_moderator/src/mod_add_view.rs | 24 +------ .../src/mod_ban_from_community_view.rs | 25 +------- crates/db_views_moderator/src/mod_ban_view.rs | 24 +------ .../src/mod_feature_post_view.rs | 25 +------- .../src/mod_hide_community_view.rs | 24 +------ .../src/mod_lock_post_view.rs | 25 +------- .../src/mod_remove_comment_view.rs | 40 +----------- .../src/mod_remove_community_view.rs | 24 +------ .../src/mod_remove_post_view.rs | 25 +------- .../src/mod_transfer_community_view.rs | 25 +------- crates/db_views_moderator/src/structs.rs | 34 +++++----- 38 files changed, 155 insertions(+), 916 deletions(-) diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index cb128339b..4441923c1 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -182,13 +182,6 @@ pub trait Reportable { Self: Sized; } -pub trait JoinView { - type JoinTuple; - fn from_tuple(tuple: Self::JoinTuple) -> Self - where - Self: Sized; -} - #[async_trait] pub trait ApubActor { async fn read_from_apub_id( diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 2fbfec6c6..eea05b4b4 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -2,7 +2,6 @@ use crate::{ diesel::Connection, diesel_migrations::MigrationHarness, newtypes::DbUrl, - traits::JoinView, CommentSortType, PersonSortType, SortType, @@ -430,33 +429,13 @@ pub fn now() -> AsExprOf { pub type ResultFuture<'a, T> = BoxFuture<'a, Result>; -pub trait ReadFn<'a, T: JoinView, Args>: - Fn(DbConn<'a>, Args) -> ResultFuture<'a, ::JoinTuple> -{ -} +pub trait ReadFn<'a, T, Args>: Fn(DbConn<'a>, Args) -> ResultFuture<'a, T> {} -impl< - 'a, - T: JoinView, - Args, - F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, ::JoinTuple>, - > ReadFn<'a, T, Args> for F -{ -} +impl<'a, T, Args, F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, T>> ReadFn<'a, T, Args> for F {} -pub trait ListFn<'a, T: JoinView, Args>: - Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec<::JoinTuple>> -{ -} +pub trait ListFn<'a, T, Args>: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec> {} -impl< - 'a, - T: JoinView, - Args, - F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec<::JoinTuple>>, - > ListFn<'a, T, Args> for F -{ -} +impl<'a, T, Args, F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec>> ListFn<'a, T, Args> for F {} /// Allows read and list functions to capture a shared closure that has an inferred return type, which is useful for join logic pub struct Queries { @@ -471,11 +450,8 @@ impl Queries<(), ()> { list_fn: LF2, ) -> Queries, impl ListFn<'a, LT, LA>> where - RFut: Future::JoinTuple, DieselError>> + Sized + Send + 'a, - LFut: - Future::JoinTuple>, DieselError>> + Sized + Send + 'a, - RT: JoinView, - LT: JoinView, + RFut: Future> + Sized + Send + 'a, + LFut: Future, DieselError>> + Sized + Send + 'a, RF2: Fn(DbConn<'a>, RA) -> RFut, LF2: Fn(DbConn<'a>, LA) -> LFut, { @@ -493,12 +469,10 @@ impl Queries { args: Args, ) -> Result where - T: JoinView, RF: ReadFn<'a, T, Args>, { let conn = get_conn(pool).await?; - let res = (self.read_fn)(conn, args).await?; - Ok(T::from_tuple(res)) + (self.read_fn)(conn, args).await } pub async fn list<'a, T, Args>( @@ -507,12 +481,10 @@ impl Queries { args: Args, ) -> Result, DieselError> where - T: JoinView, LF: ListFn<'a, T, Args>, { let conn = get_conn(pool).await?; - let res = (self.list_fn)(conn, args).await?; - Ok(res.into_iter().map(T::from_tuple).collect()) + (self.list_fn)(conn, args).await } } diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index c8f4e3e41..99832d8b5 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -11,7 +11,6 @@ use diesel::{ }; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ - aggregates::structs::CommentAggregates, aliases, newtypes::{CommentReportId, CommunityId, PersonId}, schema::{ @@ -25,14 +24,6 @@ use lemmy_db_schema::{ person, post, }, - source::{ - comment::Comment, - comment_report::CommentReport, - community::Community, - person::Person, - post::Post, - }, - traits::JoinView, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, }; @@ -89,7 +80,7 @@ fn queries<'a>() -> Queries< ), ) .select(selection) - .first::<::JoinTuple>(&mut conn) + .first::(&mut conn) .await }; @@ -135,12 +126,10 @@ fn queries<'a>() -> Queries< .and(community_moderator::person_id.eq(user.person.id)), ), ) - .load::<::JoinTuple>(&mut conn) + .load::(&mut conn) .await } else { - query - .load::<::JoinTuple>(&mut conn) - .await + query.load::(&mut conn).await } }; @@ -220,36 +209,6 @@ impl CommentReportQuery { } } -impl JoinView for CommentReportView { - type JoinTuple = ( - CommentReport, - Comment, - Post, - Community, - Person, - Person, - CommentAggregates, - bool, - Option, - Option, - ); - - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - comment_report: a.0, - comment: a.1, - post: a.2, - community: a.3, - creator: a.4, - comment_creator: a.5, - counts: a.6, - creator_banned_from_community: a.7, - my_vote: a.8, - resolver: a.9, - } - } -} - #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 713b8ed27..0288bfd0f 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -12,7 +12,6 @@ use diesel::{ use diesel_async::RunQueryDsl; use diesel_ltree::{nlevel, subpath, Ltree, LtreeExtensions}; use lemmy_db_schema::{ - aggregates::structs::CommentAggregates, newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId}, schema::{ comment, @@ -29,32 +28,12 @@ use lemmy_db_schema::{ person_block, post, }, - source::{ - comment::Comment, - community::{Community, CommunityFollower}, - person::Person, - post::Post, - }, - traits::JoinView, + source::community::CommunityFollower, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, CommentSortType, ListingType, - SubscribedType, }; -type CommentViewTuple = ( - Comment, - Person, - Post, - Community, - CommentAggregates, - bool, - SubscribedType, - bool, - bool, - Option, -); - fn queries<'a>() -> Queries< impl ReadFn<'a, CommentView, (CommentId, Option)>, impl ListFn<'a, CommentView, CommentQuery<'a>>, @@ -129,7 +108,7 @@ fn queries<'a>() -> Queries< (comment_id, my_person_id): (CommentId, Option)| async move { all_joins(comment::table.find(comment_id).into_boxed(), my_person_id) .select(selection) - .first::(&mut conn) + .first::(&mut conn) .await }; @@ -296,7 +275,7 @@ fn queries<'a>() -> Queries< query .limit(limit) .offset(offset) - .load::(&mut conn) + .load::(&mut conn) .await }; @@ -344,40 +323,13 @@ impl<'a> CommentQuery<'a> { } } -impl JoinView for CommentView { - type JoinTuple = CommentViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - comment: a.0, - creator: a.1, - post: a.2, - community: a.3, - counts: a.4, - creator_banned_from_community: a.5, - subscribed: a.6, - saved: a.7, - creator_blocked: a.8, - my_vote: a.9, - } - } -} - #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] #![allow(clippy::indexing_slicing)] use crate::{ - comment_view::{ - Comment, - CommentQuery, - CommentSortType, - CommentView, - Community, - DbPool, - Person, - Post, - }, + comment_view::{CommentQuery, CommentSortType, CommentView, DbPool}, structs::LocalUserView, }; use lemmy_db_schema::{ @@ -386,14 +338,14 @@ mod tests { newtypes::LanguageId, source::{ actor_language::LocalUserLanguage, - comment::{CommentInsertForm, CommentLike, CommentLikeForm}, - community::CommunityInsertForm, + comment::{Comment, CommentInsertForm, CommentLike, CommentLikeForm}, + community::{Community, CommunityInsertForm}, instance::Instance, language::Language, local_user::{LocalUser, LocalUserInsertForm}, - person::PersonInsertForm, + person::{Person, PersonInsertForm}, person_block::{PersonBlock, PersonBlockForm}, - post::PostInsertForm, + post::{Post, PostInsertForm}, }, traits::{Blockable, Crud, Likeable}, utils::build_db_pool_for_tests, diff --git a/crates/db_views/src/local_user_view.rs b/crates/db_views/src/local_user_view.rs index 21acad7cb..dd0e3631b 100644 --- a/crates/db_views/src/local_user_view.rs +++ b/crates/db_views/src/local_user_view.rs @@ -3,18 +3,13 @@ use actix_web::{dev::Payload, FromRequest, HttpMessage, HttpRequest}; use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, QueryDsl}; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ - aggregates::structs::PersonAggregates, newtypes::{LocalUserId, PersonId}, schema::{local_user, person, person_aggregates}, - source::{local_user::LocalUser, person::Person}, - traits::JoinView, utils::{functions::lower, DbConn, DbPool, ListFn, Queries, ReadFn}, }; use lemmy_utils::error::{LemmyError, LemmyErrorType}; use std::future::{ready, Ready}; -type LocalUserViewTuple = (LocalUser, Person, PersonAggregates); - enum ReadBy<'a> { Id(LocalUserId), Person(PersonId), @@ -56,7 +51,7 @@ fn queries<'a>( query .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) .select(selection) - .first::(&mut conn) + .first::(&mut conn) .await }; @@ -69,7 +64,7 @@ fn queries<'a>( .inner_join(person::table) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) .select(selection) - .load::(&mut conn) + .load::(&mut conn) .await } } @@ -109,17 +104,6 @@ impl LocalUserView { } } -impl JoinView for LocalUserView { - type JoinTuple = LocalUserViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - local_user: a.0, - person: a.1, - counts: a.2, - } - } -} - impl FromRequest for LocalUserView { type Error = LemmyError; type Future = Ready>; diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index da264a79c..1ab436935 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -10,7 +10,6 @@ use diesel::{ }; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ - aggregates::structs::PostAggregates, aliases, newtypes::{CommunityId, PersonId, PostReportId}, schema::{ @@ -23,23 +22,9 @@ use lemmy_db_schema::{ post_like, post_report, }, - source::{community::Community, person::Person, post::Post, post_report::PostReport}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, }; -type PostReportViewTuple = ( - PostReport, - Post, - Community, - Person, - Person, - bool, - Option, - PostAggregates, - Option, -); - fn queries<'a>() -> Queries< impl ReadFn<'a, PostReportView, (PostReportId, PersonId)>, impl ListFn<'a, PostReportView, (PostReportQuery, &'a LocalUserView)>, @@ -87,7 +72,7 @@ fn queries<'a>() -> Queries< post_report::table.find(report_id).into_boxed(), my_person_id, ) - .first::(&mut conn) + .first::(&mut conn) .await }; @@ -119,10 +104,10 @@ fn queries<'a>() -> Queries< .and(community_moderator::person_id.eq(user.person.id)), ), ) - .load::(&mut conn) + .load::(&mut conn) .await } else { - query.load::(&mut conn).await + query.load::(&mut conn).await } }; @@ -199,23 +184,6 @@ impl PostReportQuery { } } -impl JoinView for PostReportView { - type JoinTuple = PostReportViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - post_report: a.0, - post: a.1, - community: a.2, - creator: a.3, - post_creator: a.4, - creator_banned_from_community: a.5, - my_vote: a.6, - counts: a.7, - resolver: a.8, - } - } -} - #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 4bd0501ab..8050d3f5e 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -16,7 +16,6 @@ use diesel::{ }; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ - aggregates::structs::PostAggregates, newtypes::{CommunityId, LocalUserId, PersonId, PostId}, schema::{ community, @@ -34,33 +33,13 @@ use lemmy_db_schema::{ post_read, post_saved, }, - source::{ - community::{Community, CommunityFollower}, - person::Person, - post::Post, - }, - traits::JoinView, + source::community::CommunityFollower, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, ListingType, SortType, - SubscribedType, }; use tracing::debug; -type PostViewTuple = ( - Post, - Person, - Community, - bool, - PostAggregates, - SubscribedType, - bool, - bool, - bool, - Option, - i64, -); - sql_function!(fn coalesce(x: sql_types::Nullable, y: sql_types::BigInt) -> sql_types::BigInt); fn queries<'a>() -> Queries< @@ -182,7 +161,7 @@ fn queries<'a>() -> Queries< ); } - query.first::(&mut conn).await + query.first::(&mut conn).await }; let list = move |mut conn: DbConn<'a>, options: PostQuery<'a>| async move { @@ -395,7 +374,7 @@ fn queries<'a>() -> Queries< debug!("Post View Query: {:?}", debug_query::(&query)); - query.load::(&mut conn).await + query.load::(&mut conn).await }; Queries::new(read, list) @@ -446,25 +425,6 @@ impl<'a> PostQuery<'a> { } } -impl JoinView for PostView { - type JoinTuple = PostViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - post: a.0, - creator: a.1, - community: a.2, - creator_banned_from_community: a.3, - counts: a.4, - subscribed: a.5, - saved: a.6, - read: a.7, - creator_blocked: a.8, - my_vote: a.9, - unread_comments: a.10, - } - } -} - #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] diff --git a/crates/db_views/src/private_message_report_view.rs b/crates/db_views/src/private_message_report_view.rs index f1dfa3f48..878d79edb 100644 --- a/crates/db_views/src/private_message_report_view.rs +++ b/crates/db_views/src/private_message_report_view.rs @@ -12,23 +12,9 @@ use lemmy_db_schema::{ aliases, newtypes::PrivateMessageReportId, schema::{person, private_message, private_message_report}, - source::{ - person::Person, - private_message::PrivateMessage, - private_message_report::PrivateMessageReport, - }, - traits::JoinView, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, }; -type PrivateMessageReportViewTuple = ( - PrivateMessageReport, - PrivateMessage, - Person, - Person, - Option, -); - fn queries<'a>() -> Queries< impl ReadFn<'a, PrivateMessageReportView, PrivateMessageReportId>, impl ListFn<'a, PrivateMessageReportView, PrivateMessageReportQuery>, @@ -56,7 +42,7 @@ fn queries<'a>() -> Queries< let read = move |mut conn: DbConn<'a>, report_id: PrivateMessageReportId| async move { all_joins(private_message_report::table.find(report_id).into_boxed()) - .first::(&mut conn) + .first::(&mut conn) .await }; @@ -73,7 +59,7 @@ fn queries<'a>() -> Queries< .order_by(private_message::published.desc()) .limit(limit) .offset(offset) - .load::(&mut conn) + .load::(&mut conn) .await }; @@ -119,19 +105,6 @@ impl PrivateMessageReportQuery { } } -impl JoinView for PrivateMessageReportView { - type JoinTuple = PrivateMessageReportViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - private_message_report: a.0, - private_message: a.1, - private_message_creator: a.2, - creator: a.3, - resolver: a.4, - } - } -} - #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] diff --git a/crates/db_views/src/private_message_view.rs b/crates/db_views/src/private_message_view.rs index c1eeabab8..b8628ecc5 100644 --- a/crates/db_views/src/private_message_view.rs +++ b/crates/db_views/src/private_message_view.rs @@ -13,14 +13,10 @@ use lemmy_db_schema::{ aliases, newtypes::{PersonId, PrivateMessageId}, schema::{person, private_message}, - source::{person::Person, private_message::PrivateMessage}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, }; use tracing::debug; -type PrivateMessageViewTuple = (PrivateMessage, Person, Person); - fn queries<'a>() -> Queries< impl ReadFn<'a, PrivateMessageView, PrivateMessageId>, impl ListFn<'a, PrivateMessageView, (PrivateMessageQuery, PersonId)>, @@ -43,7 +39,7 @@ fn queries<'a>() -> Queries< all_joins(private_message::table.find(private_message_id).into_boxed()) .order_by(private_message::published.desc()) .select(selection) - .first::(&mut conn) + .first::(&mut conn) .await }; @@ -88,7 +84,7 @@ fn queries<'a>() -> Queries< debug_query::(&query) ); - query.load::(&mut conn).await + query.load::(&mut conn).await }; Queries::new(read, list) @@ -137,17 +133,6 @@ impl PrivateMessageQuery { } } -impl JoinView for PrivateMessageView { - type JoinTuple = PrivateMessageViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - private_message: a.0, - creator: a.1, - recipient: a.2, - } - } -} - #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index 03898d7f9..19e300ac7 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -12,18 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ aliases, schema::{local_user, person, registration_application}, - source::{ - local_user::LocalUser, - person::Person, - registration_application::RegistrationApplication, - }, - traits::JoinView, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, }; -type RegistrationApplicationViewTuple = - (RegistrationApplication, LocalUser, Person, Option); - fn queries<'a>() -> Queries< impl ReadFn<'a, RegistrationApplicationView, i32>, impl ListFn<'a, RegistrationApplicationView, RegistrationApplicationQuery>, @@ -51,7 +42,7 @@ fn queries<'a>() -> Queries< .find(registration_application_id) .into_boxed(), ) - .first::(&mut conn) + .first::(&mut conn) .await }; @@ -73,9 +64,7 @@ fn queries<'a>() -> Queries< .offset(offset) .order_by(registration_application::published.desc()); - query - .load::(&mut conn) - .await + query.load::(&mut conn).await }; Queries::new(read, list) @@ -135,18 +124,6 @@ impl RegistrationApplicationQuery { } } -impl JoinView for RegistrationApplicationView { - type JoinTuple = RegistrationApplicationViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - registration_application: a.0, - creator_local_user: a.1, - creator: a.2, - admin: a.3, - } - } -} - #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] diff --git a/crates/db_views/src/site_view.rs b/crates/db_views/src/site_view.rs index f80666bad..17819fdd7 100644 --- a/crates/db_views/src/site_view.rs +++ b/crates/db_views/src/site_view.rs @@ -2,16 +2,14 @@ use crate::structs::SiteView; use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl}; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ - aggregates::structs::SiteAggregates, schema::{local_site, local_site_rate_limit, site, site_aggregates}, - source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::Site}, utils::{get_conn, DbPool}, }; impl SiteView { pub async fn read_local(pool: &mut DbPool<'_>) -> Result { let conn = &mut get_conn(pool).await?; - let (mut site, local_site, local_site_rate_limit, counts) = site::table + let mut res = site::table .inner_join(local_site::table) .inner_join( local_site_rate_limit::table.on(local_site::id.eq(local_site_rate_limit::local_site_id)), @@ -23,15 +21,10 @@ impl SiteView { local_site_rate_limit::all_columns, site_aggregates::all_columns, )) - .first::<(Site, LocalSite, LocalSiteRateLimit, SiteAggregates)>(conn) + .first::(conn) .await?; - site.private_key = None; - Ok(SiteView { - site, - local_site, - local_site_rate_limit, - counts, - }) + res.site.private_key = None; + Ok(res) } } diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index 536dd3597..6ac69de03 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "full")] +use diesel::Queryable; use lemmy_db_schema::{ aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates}, source::{ @@ -26,7 +28,7 @@ use ts_rs::TS; #[skip_serializing_none] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A comment report view. pub struct CommentReportView { @@ -44,7 +46,7 @@ pub struct CommentReportView { #[skip_serializing_none] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A comment view. pub struct CommentView { @@ -61,7 +63,7 @@ pub struct CommentView { } #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A local user view. pub struct LocalUserView { @@ -72,7 +74,7 @@ pub struct LocalUserView { #[skip_serializing_none] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A post report view. pub struct PostReportView { @@ -89,7 +91,7 @@ pub struct PostReportView { #[skip_serializing_none] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A post view. pub struct PostView { @@ -107,7 +109,7 @@ pub struct PostView { } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A private message view. pub struct PrivateMessageView { @@ -118,7 +120,7 @@ pub struct PrivateMessageView { #[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A private message report view. pub struct PrivateMessageReportView { @@ -131,7 +133,7 @@ pub struct PrivateMessageReportView { #[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A registration application view. pub struct RegistrationApplicationView { @@ -142,7 +144,7 @@ pub struct RegistrationApplicationView { } #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A site view. pub struct SiteView { diff --git a/crates/db_views_actor/src/comment_reply_view.rs b/crates/db_views_actor/src/comment_reply_view.rs index 97d5b31eb..a97ad96fb 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -10,7 +10,6 @@ use diesel::{ }; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ - aggregates::structs::CommentAggregates, aliases, newtypes::{CommentReplyId, PersonId}, schema::{ @@ -26,34 +25,11 @@ use lemmy_db_schema::{ person_block, post, }, - source::{ - comment::Comment, - comment_reply::CommentReply, - community::{Community, CommunityFollower}, - person::Person, - post::Post, - }, - traits::JoinView, + source::community::CommunityFollower, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, CommentSortType, - SubscribedType, }; -type CommentReplyViewTuple = ( - CommentReply, - Comment, - Person, - Post, - Community, - Person, - CommentAggregates, - bool, - SubscribedType, - bool, - bool, - Option, -); - fn queries<'a>() -> Queries< impl ReadFn<'a, CommentReplyView, (CommentReplyId, Option)>, impl ListFn<'a, CommentReplyView, CommentReplyQuery>, @@ -127,7 +103,7 @@ fn queries<'a>() -> Queries< comment_reply::table.find(comment_reply_id).into_boxed(), my_person_id, ) - .first::(&mut conn) + .first::(&mut conn) .await }; @@ -161,7 +137,7 @@ fn queries<'a>() -> Queries< query .limit(limit) .offset(offset) - .load::(&mut conn) + .load::(&mut conn) .await }; @@ -214,23 +190,3 @@ impl CommentReplyQuery { queries().list(pool, self).await } } - -impl JoinView for CommentReplyView { - type JoinTuple = CommentReplyViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - comment_reply: a.0, - comment: a.1, - creator: a.2, - post: a.3, - community: a.4, - recipient: a.5, - counts: a.6, - creator_banned_from_community: a.7, - subscribed: a.8, - saved: a.9, - creator_blocked: a.10, - my_vote: a.11, - } - } -} diff --git a/crates/db_views_actor/src/community_block_view.rs b/crates/db_views_actor/src/community_block_view.rs index 5c8903d9c..c7d3d1836 100644 --- a/crates/db_views_actor/src/community_block_view.rs +++ b/crates/db_views_actor/src/community_block_view.rs @@ -4,17 +4,13 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{community, community_block, person}, - source::{community::Community, person::Person}, - traits::JoinView, utils::{get_conn, DbPool}, }; -type CommunityBlockViewTuple = (Person, Community); - impl CommunityBlockView { pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result, Error> { let conn = &mut get_conn(pool).await?; - let res = community_block::table + community_block::table .inner_join(person::table) .inner_join(community::table) .select((person::all_columns, community::all_columns)) @@ -22,19 +18,7 @@ impl CommunityBlockView { .filter(community::deleted.eq(false)) .filter(community::removed.eq(false)) .order_by(community_block::published) - .load::(conn) - .await?; - - Ok(res.into_iter().map(Self::from_tuple).collect()) - } -} - -impl JoinView for CommunityBlockView { - type JoinTuple = CommunityBlockViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - person: a.0, - community: a.1, - } + .load::(conn) + .await } } diff --git a/crates/db_views_actor/src/community_follower_view.rs b/crates/db_views_actor/src/community_follower_view.rs index c30503878..7e8b24af3 100644 --- a/crates/db_views_actor/src/community_follower_view.rs +++ b/crates/db_views_actor/src/community_follower_view.rs @@ -10,13 +10,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::{CommunityId, DbUrl, PersonId}, schema::{community, community_follower, person}, - source::{community::Community, person::Person}, - traits::JoinView, utils::{get_conn, DbPool}, }; -type CommunityFollowerViewTuple = (Community, Person); - sql_function!(fn coalesce(x: diesel::sql_types::Nullable, y: diesel::sql_types::Text) -> diesel::sql_types::Text); impl CommunityFollowerView { @@ -52,7 +48,7 @@ impl CommunityFollowerView { pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result, Error> { let conn = &mut get_conn(pool).await?; - let res = community_follower::table + community_follower::table .inner_join(community::table) .inner_join(person::table) .select((community::all_columns, person::all_columns)) @@ -60,19 +56,7 @@ impl CommunityFollowerView { .filter(community::deleted.eq(false)) .filter(community::removed.eq(false)) .order_by(community::title) - .load::(conn) - .await?; - - Ok(res.into_iter().map(Self::from_tuple).collect()) - } -} - -impl JoinView for CommunityFollowerView { - type JoinTuple = CommunityFollowerViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - community: a.0, - follower: a.1, - } + .load::(conn) + .await } } diff --git a/crates/db_views_actor/src/community_moderator_view.rs b/crates/db_views_actor/src/community_moderator_view.rs index 2725565f1..63e711225 100644 --- a/crates/db_views_actor/src/community_moderator_view.rs +++ b/crates/db_views_actor/src/community_moderator_view.rs @@ -4,13 +4,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::{CommunityId, PersonId}, schema::{community, community_moderator, person}, - source::{community::Community, person::Person}, - traits::JoinView, utils::{get_conn, DbPool}, }; -type CommunityModeratorViewTuple = (Community, Person); - impl CommunityModeratorView { pub async fn is_community_moderator( pool: &mut DbPool<'_>, @@ -36,38 +32,34 @@ impl CommunityModeratorView { community_id: CommunityId, ) -> Result, Error> { let conn = &mut get_conn(pool).await?; - let res = community_moderator::table + community_moderator::table .inner_join(community::table) .inner_join(person::table) .filter(community_moderator::community_id.eq(community_id)) .select((community::all_columns, person::all_columns)) .order_by(community_moderator::published) - .load::(conn) - .await?; - - Ok(res.into_iter().map(Self::from_tuple).collect()) + .load::(conn) + .await } pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result, Error> { let conn = &mut get_conn(pool).await?; - let res = community_moderator::table + community_moderator::table .inner_join(community::table) .inner_join(person::table) .filter(community_moderator::person_id.eq(person_id)) .filter(community::deleted.eq(false)) .filter(community::removed.eq(false)) .select((community::all_columns, person::all_columns)) - .load::(conn) - .await?; - - Ok(res.into_iter().map(Self::from_tuple).collect()) + .load::(conn) + .await } /// Finds all communities first mods / creators /// Ideally this should be a group by, but diesel doesn't support it yet pub async fn get_community_first_mods(pool: &mut DbPool<'_>) -> Result, Error> { let conn = &mut get_conn(pool).await?; - let res = community_moderator::table + community_moderator::table .inner_join(community::table) .inner_join(person::table) .select((community::all_columns, person::all_columns)) @@ -78,19 +70,7 @@ impl CommunityModeratorView { community_moderator::community_id, community_moderator::person_id, )) - .load::(conn) - .await?; - - Ok(res.into_iter().map(Self::from_tuple).collect()) - } -} - -impl JoinView for CommunityModeratorView { - type JoinTuple = CommunityModeratorViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - community: a.0, - moderator: a.1, - } + .load::(conn) + .await } } diff --git a/crates/db_views_actor/src/community_person_ban_view.rs b/crates/db_views_actor/src/community_person_ban_view.rs index 705b4bf77..ba0b4cd7f 100644 --- a/crates/db_views_actor/src/community_person_ban_view.rs +++ b/crates/db_views_actor/src/community_person_ban_view.rs @@ -4,7 +4,6 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::{CommunityId, PersonId}, schema::{community, community_person_ban, person}, - source::{community::Community, person::Person}, utils::{get_conn, DbPool}, }; @@ -15,16 +14,14 @@ impl CommunityPersonBanView { from_community_id: CommunityId, ) -> Result { let conn = &mut get_conn(pool).await?; - let (community, person) = community_person_ban::table + community_person_ban::table .inner_join(community::table) .inner_join(person::table) .select((community::all_columns, person::all_columns)) .filter(community_person_ban::community_id.eq(from_community_id)) .filter(community_person_ban::person_id.eq(from_person_id)) .order_by(community_person_ban::published) - .first::<(Community, Person)>(conn) - .await?; - - Ok(CommunityPersonBanView { community, person }) + .first::(conn) + .await } } diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 96c2e5891..7970183dc 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -11,22 +11,14 @@ use diesel::{ }; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ - aggregates::structs::CommunityAggregates, newtypes::{CommunityId, PersonId}, schema::{community, community_aggregates, community_block, community_follower, local_user}, - source::{ - community::{Community, CommunityFollower}, - local_user::LocalUser, - }, - traits::JoinView, + source::{community::CommunityFollower, local_user::LocalUser}, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, ListingType, SortType, - SubscribedType, }; -type CommunityViewTuple = (Community, CommunityAggregates, SubscribedType, bool); - fn queries<'a>() -> Queries< impl ReadFn<'a, CommunityView, (CommunityId, Option, bool)>, impl ListFn<'a, CommunityView, CommunityQuery<'a>>, @@ -55,9 +47,9 @@ fn queries<'a>() -> Queries< let selection = ( community::all_columns, - community_aggregates::all_columns, CommunityFollower::select_subscribed_type(), community_block::id.nullable().is_not_null(), + community_aggregates::all_columns, ); let not_removed_or_deleted = community::removed @@ -81,7 +73,7 @@ fn queries<'a>() -> Queries< query = query.filter(not_removed_or_deleted); } - query.first::(&mut conn).await + query.first::(&mut conn).await }; let list = move |mut conn: DbConn<'a>, options: CommunityQuery<'a>| async move { @@ -154,7 +146,7 @@ fn queries<'a>() -> Queries< query .limit(limit) .offset(offset) - .load::(&mut conn) + .load::(&mut conn) .await }; @@ -205,15 +197,3 @@ impl<'a> CommunityQuery<'a> { queries().list(pool, self).await } } - -impl JoinView for CommunityView { - type JoinTuple = CommunityViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - community: a.0, - counts: a.1, - subscribed: a.2, - blocked: a.3, - } - } -} diff --git a/crates/db_views_actor/src/person_block_view.rs b/crates/db_views_actor/src/person_block_view.rs index b317740da..5f028acd8 100644 --- a/crates/db_views_actor/src/person_block_view.rs +++ b/crates/db_views_actor/src/person_block_view.rs @@ -4,19 +4,15 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{person, person_block}, - source::person::Person, - traits::JoinView, utils::{get_conn, DbPool}, }; -type PersonBlockViewTuple = (Person, Person); - impl PersonBlockView { pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result, Error> { let conn = &mut get_conn(pool).await?; let target_person_alias = diesel::alias!(person as person1); - let res = person_block::table + person_block::table .inner_join(person::table.on(person_block::person_id.eq(person::id))) .inner_join( target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))), @@ -28,19 +24,7 @@ impl PersonBlockView { .filter(person_block::person_id.eq(person_id)) .filter(target_person_alias.field(person::deleted).eq(false)) .order_by(person_block::published) - .load::(conn) - .await?; - - Ok(res.into_iter().map(Self::from_tuple).collect()) - } -} - -impl JoinView for PersonBlockView { - type JoinTuple = PersonBlockViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - person: a.0, - target: a.1, - } + .load::(conn) + .await } } diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 1a5544302..8d04f9820 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -11,7 +11,6 @@ use diesel::{ }; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ - aggregates::structs::CommentAggregates, aliases, newtypes::{PersonId, PersonMentionId}, schema::{ @@ -27,34 +26,11 @@ use lemmy_db_schema::{ person_mention, post, }, - source::{ - comment::Comment, - community::{Community, CommunityFollower}, - person::Person, - person_mention::PersonMention, - post::Post, - }, - traits::JoinView, + source::community::CommunityFollower, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, CommentSortType, - SubscribedType, }; -type PersonMentionViewTuple = ( - PersonMention, - Comment, - Person, - Post, - Community, - Person, - CommentAggregates, - bool, - SubscribedType, - bool, - bool, - Option, -); - fn queries<'a>() -> Queries< impl ReadFn<'a, PersonMentionView, (PersonMentionId, Option)>, impl ListFn<'a, PersonMentionView, PersonMentionQuery>, @@ -130,7 +106,7 @@ fn queries<'a>() -> Queries< ), ) .select(selection) - .first::(&mut conn) + .first::(&mut conn) .await }; @@ -177,7 +153,7 @@ fn queries<'a>() -> Queries< query .limit(limit) .offset(offset) - .load::(&mut conn) + .load::(&mut conn) .await }; @@ -231,23 +207,3 @@ impl PersonMentionQuery { queries().list(pool, self).await } } - -impl JoinView for PersonMentionView { - type JoinTuple = PersonMentionViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - person_mention: a.0, - comment: a.1, - creator: a.2, - post: a.3, - community: a.4, - recipient: a.5, - counts: a.6, - creator_banned_from_community: a.7, - subscribed: a.8, - saved: a.9, - creator_blocked: a.10, - my_vote: a.11, - } - } -} diff --git a/crates/db_views_actor/src/person_view.rs b/crates/db_views_actor/src/person_view.rs index 493aab27a..042b04767 100644 --- a/crates/db_views_actor/src/person_view.rs +++ b/crates/db_views_actor/src/person_view.rs @@ -10,18 +10,13 @@ use diesel::{ }; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ - aggregates::structs::PersonAggregates, newtypes::PersonId, schema, schema::{local_user, person, person_aggregates}, - source::person::Person, - traits::JoinView, utils::{fuzzy_search, get_conn, limit_and_offset, now, DbConn, DbPool, ListFn, Queries, ReadFn}, PersonSortType, }; -type PersonViewTuple = (Person, PersonAggregates); - enum ListMode { Admins, Banned, @@ -39,7 +34,7 @@ fn queries<'a>( let read = move |mut conn: DbConn<'a>, person_id: PersonId| async move { all_joins(person::table.find(person_id).into_boxed()) - .first::(&mut conn) + .first::(&mut conn) .await }; @@ -84,7 +79,7 @@ fn queries<'a>( query = query.limit(limit).offset(offset); } } - query.load::(&mut conn).await + query.load::(&mut conn).await }; Queries::new(read, list) @@ -132,13 +127,3 @@ impl PersonQuery { queries().list(pool, ListMode::Query(self)).await } } - -impl JoinView for PersonView { - type JoinTuple = PersonViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - person: a.0, - counts: a.1, - } - } -} diff --git a/crates/db_views_actor/src/structs.rs b/crates/db_views_actor/src/structs.rs index 35391776b..3728bb02c 100644 --- a/crates/db_views_actor/src/structs.rs +++ b/crates/db_views_actor/src/structs.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "full")] +use diesel::Queryable; use lemmy_db_schema::{ aggregates::structs::{CommentAggregates, CommunityAggregates, PersonAggregates}, source::{ @@ -16,7 +18,7 @@ use serde_with::skip_serializing_none; use ts_rs::TS; #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A community block. pub struct CommunityBlockView { @@ -25,7 +27,7 @@ pub struct CommunityBlockView { } #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A community follower. pub struct CommunityFollowerView { @@ -34,7 +36,7 @@ pub struct CommunityFollowerView { } #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A community moderator. pub struct CommunityModeratorView { @@ -43,6 +45,7 @@ pub struct CommunityModeratorView { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(Queryable))] /// A community person ban. pub struct CommunityPersonBanView { pub community: Community, @@ -50,7 +53,7 @@ pub struct CommunityPersonBanView { } #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A community view. pub struct CommunityView { @@ -61,7 +64,7 @@ pub struct CommunityView { } #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A person block. pub struct PersonBlockView { @@ -71,7 +74,7 @@ pub struct PersonBlockView { #[skip_serializing_none] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A person mention view. pub struct PersonMentionView { @@ -91,7 +94,7 @@ pub struct PersonMentionView { #[skip_serializing_none] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A comment reply view. pub struct CommentReplyView { @@ -110,7 +113,7 @@ pub struct CommentReplyView { } #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// A person view. pub struct PersonView { diff --git a/crates/db_views_moderator/src/admin_purge_comment_view.rs b/crates/db_views_moderator/src/admin_purge_comment_view.rs index ccfc2892a..f62fe0f22 100644 --- a/crates/db_views_moderator/src/admin_purge_comment_view.rs +++ b/crates/db_views_moderator/src/admin_purge_comment_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{admin_purge_comment, person, post}, - source::{moderator::AdminPurgeComment, person::Person, post::Post}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option, Post); - impl AdminPurgeCommentView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -46,25 +42,11 @@ impl AdminPurgeCommentView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(admin_purge_comment::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for AdminPurgeCommentView { - type JoinTuple = AdminPurgeCommentViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - admin_purge_comment: a.0, - admin: a.1, - post: a.2, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/admin_purge_community_view.rs b/crates/db_views_moderator/src/admin_purge_community_view.rs index 20c4ae357..23967ee3b 100644 --- a/crates/db_views_moderator/src/admin_purge_community_view.rs +++ b/crates/db_views_moderator/src/admin_purge_community_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{admin_purge_community, person}, - source::{moderator::AdminPurgeCommunity, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option); - impl AdminPurgeCommunityView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -44,24 +40,11 @@ impl AdminPurgeCommunityView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(admin_purge_community::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for AdminPurgeCommunityView { - type JoinTuple = AdminPurgeCommunityViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - admin_purge_community: a.0, - admin: a.1, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/admin_purge_person_view.rs b/crates/db_views_moderator/src/admin_purge_person_view.rs index f29947aec..097785d25 100644 --- a/crates/db_views_moderator/src/admin_purge_person_view.rs +++ b/crates/db_views_moderator/src/admin_purge_person_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{admin_purge_person, person}, - source::{moderator::AdminPurgePerson, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type AdminPurgePersonViewTuple = (AdminPurgePerson, Option); - impl AdminPurgePersonView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -44,24 +40,11 @@ impl AdminPurgePersonView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(admin_purge_person::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for AdminPurgePersonView { - type JoinTuple = AdminPurgePersonViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - admin_purge_person: a.0, - admin: a.1, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/admin_purge_post_view.rs b/crates/db_views_moderator/src/admin_purge_post_view.rs index 8dc3940cf..8f5eb3a14 100644 --- a/crates/db_views_moderator/src/admin_purge_post_view.rs +++ b/crates/db_views_moderator/src/admin_purge_post_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{admin_purge_post, community, person}, - source::{community::Community, moderator::AdminPurgePost, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type AdminPurgePostViewTuple = (AdminPurgePost, Option, Community); - impl AdminPurgePostView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -46,25 +42,11 @@ impl AdminPurgePostView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(admin_purge_post::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for AdminPurgePostView { - type JoinTuple = AdminPurgePostViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - admin_purge_post: a.0, - admin: a.1, - community: a.2, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_add_community_view.rs b/crates/db_views_moderator/src/mod_add_community_view.rs index c1166b6dd..f96a9b80b 100644 --- a/crates/db_views_moderator/src/mod_add_community_view.rs +++ b/crates/db_views_moderator/src/mod_add_community_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{community, mod_add_community, person}, - source::{community::Community, moderator::ModAddCommunity, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModAddCommunityViewTuple = (ModAddCommunity, Option, Community, Person); - impl ModAddCommunityView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -58,26 +54,11 @@ impl ModAddCommunityView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_add_community::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModAddCommunityView { - type JoinTuple = ModAddCommunityViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_add_community: a.0, - moderator: a.1, - community: a.2, - modded_person: a.3, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_add_view.rs b/crates/db_views_moderator/src/mod_add_view.rs index 7094db123..28fb0a2b6 100644 --- a/crates/db_views_moderator/src/mod_add_view.rs +++ b/crates/db_views_moderator/src/mod_add_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{mod_add, person}, - source::{moderator::ModAdd, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModAddViewTuple = (ModAdd, Option, Person); - impl ModAddView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -50,25 +46,11 @@ impl ModAddView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_add::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModAddView { - type JoinTuple = ModAddViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_add: a.0, - moderator: a.1, - modded_person: a.2, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_ban_from_community_view.rs b/crates/db_views_moderator/src/mod_ban_from_community_view.rs index ceed974bd..02f18099c 100644 --- a/crates/db_views_moderator/src/mod_ban_from_community_view.rs +++ b/crates/db_views_moderator/src/mod_ban_from_community_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{community, mod_ban_from_community, person}, - source::{community::Community, moderator::ModBanFromCommunity, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option, Community, Person); - impl ModBanFromCommunityView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -60,26 +56,11 @@ impl ModBanFromCommunityView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_ban_from_community::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModBanFromCommunityView { - type JoinTuple = ModBanFromCommunityViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_ban_from_community: a.0, - moderator: a.1, - community: a.2, - banned_person: a.3, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_ban_view.rs b/crates/db_views_moderator/src/mod_ban_view.rs index 835804e67..94ac360db 100644 --- a/crates/db_views_moderator/src/mod_ban_view.rs +++ b/crates/db_views_moderator/src/mod_ban_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{mod_ban, person}, - source::{moderator::ModBan, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModBanViewTuple = (ModBan, Option, Person); - impl ModBanView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -50,25 +46,11 @@ impl ModBanView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_ban::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModBanView { - type JoinTuple = ModBanViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_ban: a.0, - moderator: a.1, - banned_person: a.2, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_feature_post_view.rs b/crates/db_views_moderator/src/mod_feature_post_view.rs index 16a645f2c..324816178 100644 --- a/crates/db_views_moderator/src/mod_feature_post_view.rs +++ b/crates/db_views_moderator/src/mod_feature_post_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{community, mod_feature_post, person, post}, - source::{community::Community, moderator::ModFeaturePost, person::Person, post::Post}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModFeaturePostViewTuple = (ModFeaturePost, Option, Post, Community); - impl ModFeaturePostView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -57,26 +53,11 @@ impl ModFeaturePostView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_feature_post::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModFeaturePostView { - type JoinTuple = ModFeaturePostViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_feature_post: a.0, - moderator: a.1, - post: a.2, - community: a.3, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_hide_community_view.rs b/crates/db_views_moderator/src/mod_hide_community_view.rs index 66de2a9de..36b549814 100644 --- a/crates/db_views_moderator/src/mod_hide_community_view.rs +++ b/crates/db_views_moderator/src/mod_hide_community_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{community, mod_hide_community, person}, - source::{community::Community, moderator::ModHideCommunity, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModHideCommunityViewTuple = (ModHideCommunity, Option, Community); - impl ModHideCommunityView { // Pass in mod_id as admin_id because only admins can do this action pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { @@ -51,25 +47,11 @@ impl ModHideCommunityView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_hide_community::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModHideCommunityView { - type JoinTuple = ModHideCommunityViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_hide_community: a.0, - admin: a.1, - community: a.2, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_lock_post_view.rs b/crates/db_views_moderator/src/mod_lock_post_view.rs index b970a3f6c..7351b4f29 100644 --- a/crates/db_views_moderator/src/mod_lock_post_view.rs +++ b/crates/db_views_moderator/src/mod_lock_post_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{community, mod_lock_post, person, post}, - source::{community::Community, moderator::ModLockPost, person::Person, post::Post}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModLockPostViewTuple = (ModLockPost, Option, Post, Community); - impl ModLockPostView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -58,26 +54,11 @@ impl ModLockPostView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_lock_post::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModLockPostView { - type JoinTuple = ModLockPostViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_lock_post: a.0, - moderator: a.1, - post: a.2, - community: a.3, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_remove_comment_view.rs b/crates/db_views_moderator/src/mod_remove_comment_view.rs index 946e0eb37..9b8a71a7b 100644 --- a/crates/db_views_moderator/src/mod_remove_comment_view.rs +++ b/crates/db_views_moderator/src/mod_remove_comment_view.rs @@ -12,26 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{comment, community, mod_remove_comment, person, post}, - source::{ - comment::Comment, - community::Community, - moderator::ModRemoveComment, - person::Person, - post::Post, - }, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModRemoveCommentViewTuple = ( - ModRemoveComment, - Option, - Comment, - Person, - Post, - Community, -); - impl ModRemoveCommentView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -73,28 +56,11 @@ impl ModRemoveCommentView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_remove_comment::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModRemoveCommentView { - type JoinTuple = ModRemoveCommentViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_remove_comment: a.0, - moderator: a.1, - comment: a.2, - commenter: a.3, - post: a.4, - community: a.5, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_remove_community_view.rs b/crates/db_views_moderator/src/mod_remove_community_view.rs index c9ca4ce1a..2bc92acc8 100644 --- a/crates/db_views_moderator/src/mod_remove_community_view.rs +++ b/crates/db_views_moderator/src/mod_remove_community_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{community, mod_remove_community, person}, - source::{community::Community, moderator::ModRemoveCommunity, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModRemoveCommunityTuple = (ModRemoveCommunity, Option, Community); - impl ModRemoveCommunityView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -45,25 +41,11 @@ impl ModRemoveCommunityView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_remove_community::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModRemoveCommunityView { - type JoinTuple = ModRemoveCommunityTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_remove_community: a.0, - moderator: a.1, - community: a.2, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_remove_post_view.rs b/crates/db_views_moderator/src/mod_remove_post_view.rs index 74cd3c489..60469088c 100644 --- a/crates/db_views_moderator/src/mod_remove_post_view.rs +++ b/crates/db_views_moderator/src/mod_remove_post_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{community, mod_remove_post, person, post}, - source::{community::Community, moderator::ModRemovePost, person::Person, post::Post}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModRemovePostViewTuple = (ModRemovePost, Option, Post, Community); - impl ModRemovePostView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -58,26 +54,11 @@ impl ModRemovePostView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_remove_post::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModRemovePostView { - type JoinTuple = ModRemovePostViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_remove_post: a.0, - moderator: a.1, - post: a.2, - community: a.3, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/mod_transfer_community_view.rs b/crates/db_views_moderator/src/mod_transfer_community_view.rs index d84ed87da..3d48b0f67 100644 --- a/crates/db_views_moderator/src/mod_transfer_community_view.rs +++ b/crates/db_views_moderator/src/mod_transfer_community_view.rs @@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::PersonId, schema::{community, mod_transfer_community, person}, - source::{community::Community, moderator::ModTransferCommunity, person::Person}, - traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -type ModTransferCommunityViewTuple = (ModTransferCommunity, Option, Community, Person); - impl ModTransferCommunityView { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -60,26 +56,11 @@ impl ModTransferCommunityView { let (limit, offset) = limit_and_offset(params.page, params.limit)?; - let res = query + query .limit(limit) .offset(offset) .order_by(mod_transfer_community::when_.desc()) - .load::(conn) - .await?; - - let results = res.into_iter().map(Self::from_tuple).collect(); - Ok(results) - } -} - -impl JoinView for ModTransferCommunityView { - type JoinTuple = ModTransferCommunityViewTuple; - fn from_tuple(a: Self::JoinTuple) -> Self { - Self { - mod_transfer_community: a.0, - moderator: a.1, - community: a.2, - modded_person: a.3, - } + .load::(conn) + .await } } diff --git a/crates/db_views_moderator/src/structs.rs b/crates/db_views_moderator/src/structs.rs index 0fa70e2a7..549b38796 100644 --- a/crates/db_views_moderator/src/structs.rs +++ b/crates/db_views_moderator/src/structs.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "full")] +use diesel::Queryable; use lemmy_db_schema::{ newtypes::{CommunityId, PersonId}, source::{ @@ -31,7 +33,7 @@ use ts_rs::TS; #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When someone is added as a community moderator. pub struct ModAddCommunityView { @@ -43,7 +45,7 @@ pub struct ModAddCommunityView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When someone is added as a site moderator. pub struct ModAddView { @@ -54,7 +56,7 @@ pub struct ModAddView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When someone is banned from a community. pub struct ModBanFromCommunityView { @@ -66,7 +68,7 @@ pub struct ModBanFromCommunityView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When someone is banned from the site. pub struct ModBanView { @@ -77,7 +79,7 @@ pub struct ModBanView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When a community is hidden from public view. pub struct ModHideCommunityView { @@ -88,7 +90,7 @@ pub struct ModHideCommunityView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When a moderator locks a post (prevents new comments being made). pub struct ModLockPostView { @@ -100,7 +102,7 @@ pub struct ModLockPostView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When a moderator removes a comment. pub struct ModRemoveCommentView { @@ -114,7 +116,7 @@ pub struct ModRemoveCommentView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When a moderator removes a community. pub struct ModRemoveCommunityView { @@ -125,7 +127,7 @@ pub struct ModRemoveCommunityView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When a moderator removes a post. pub struct ModRemovePostView { @@ -137,7 +139,7 @@ pub struct ModRemovePostView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When a moderator features a post on a community (pins it to the top). pub struct ModFeaturePostView { @@ -149,7 +151,7 @@ pub struct ModFeaturePostView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When a moderator transfers a community to a new owner. pub struct ModTransferCommunityView { @@ -161,7 +163,7 @@ pub struct ModTransferCommunityView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When an admin purges a comment. pub struct AdminPurgeCommentView { @@ -172,7 +174,7 @@ pub struct AdminPurgeCommentView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When an admin purges a community. pub struct AdminPurgeCommunityView { @@ -182,7 +184,7 @@ pub struct AdminPurgeCommunityView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When an admin purges a person. pub struct AdminPurgePersonView { @@ -192,7 +194,7 @@ pub struct AdminPurgePersonView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// When an admin purges a post. pub struct AdminPurgePostView { @@ -203,7 +205,7 @@ pub struct AdminPurgePostView { #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Copy)] -#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", ts(export))] /// Querying / filtering the modlog. pub struct ModlogListParams {