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
This commit is contained in:
dullbananas 2023-08-31 06:26:10 -07:00 committed by GitHub
parent bd3f39973f
commit 15930cbf4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 155 additions and 916 deletions

View file

@ -182,13 +182,6 @@ pub trait Reportable {
Self: Sized; Self: Sized;
} }
pub trait JoinView {
type JoinTuple;
fn from_tuple(tuple: Self::JoinTuple) -> Self
where
Self: Sized;
}
#[async_trait] #[async_trait]
pub trait ApubActor { pub trait ApubActor {
async fn read_from_apub_id( async fn read_from_apub_id(

View file

@ -2,7 +2,6 @@ use crate::{
diesel::Connection, diesel::Connection,
diesel_migrations::MigrationHarness, diesel_migrations::MigrationHarness,
newtypes::DbUrl, newtypes::DbUrl,
traits::JoinView,
CommentSortType, CommentSortType,
PersonSortType, PersonSortType,
SortType, SortType,
@ -430,33 +429,13 @@ pub fn now() -> AsExprOf<diesel::dsl::now, diesel::sql_types::Timestamptz> {
pub type ResultFuture<'a, T> = BoxFuture<'a, Result<T, DieselError>>; pub type ResultFuture<'a, T> = BoxFuture<'a, Result<T, DieselError>>;
pub trait ReadFn<'a, T: JoinView, Args>: pub trait ReadFn<'a, T, Args>: Fn(DbConn<'a>, Args) -> ResultFuture<'a, T> {}
Fn(DbConn<'a>, Args) -> ResultFuture<'a, <T as JoinView>::JoinTuple>
{
}
impl< impl<'a, T, Args, F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, T>> ReadFn<'a, T, Args> for F {}
'a,
T: JoinView,
Args,
F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, <T as JoinView>::JoinTuple>,
> ReadFn<'a, T, Args> for F
{
}
pub trait ListFn<'a, T: JoinView, Args>: pub trait ListFn<'a, T, Args>: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec<T>> {}
Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec<<T as JoinView>::JoinTuple>>
{
}
impl< impl<'a, T, Args, F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec<T>>> ListFn<'a, T, Args> for F {}
'a,
T: JoinView,
Args,
F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec<<T as JoinView>::JoinTuple>>,
> 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 /// 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<RF, LF> { pub struct Queries<RF, LF> {
@ -471,11 +450,8 @@ impl Queries<(), ()> {
list_fn: LF2, list_fn: LF2,
) -> Queries<impl ReadFn<'a, RT, RA>, impl ListFn<'a, LT, LA>> ) -> Queries<impl ReadFn<'a, RT, RA>, impl ListFn<'a, LT, LA>>
where where
RFut: Future<Output = Result<<RT as JoinView>::JoinTuple, DieselError>> + Sized + Send + 'a, RFut: Future<Output = Result<RT, DieselError>> + Sized + Send + 'a,
LFut: LFut: Future<Output = Result<Vec<LT>, DieselError>> + Sized + Send + 'a,
Future<Output = Result<Vec<<LT as JoinView>::JoinTuple>, DieselError>> + Sized + Send + 'a,
RT: JoinView,
LT: JoinView,
RF2: Fn(DbConn<'a>, RA) -> RFut, RF2: Fn(DbConn<'a>, RA) -> RFut,
LF2: Fn(DbConn<'a>, LA) -> LFut, LF2: Fn(DbConn<'a>, LA) -> LFut,
{ {
@ -493,12 +469,10 @@ impl<RF, LF> Queries<RF, LF> {
args: Args, args: Args,
) -> Result<T, DieselError> ) -> Result<T, DieselError>
where where
T: JoinView,
RF: ReadFn<'a, T, Args>, RF: ReadFn<'a, T, Args>,
{ {
let conn = get_conn(pool).await?; let conn = get_conn(pool).await?;
let res = (self.read_fn)(conn, args).await?; (self.read_fn)(conn, args).await
Ok(T::from_tuple(res))
} }
pub async fn list<'a, T, Args>( pub async fn list<'a, T, Args>(
@ -507,12 +481,10 @@ impl<RF, LF> Queries<RF, LF> {
args: Args, args: Args,
) -> Result<Vec<T>, DieselError> ) -> Result<Vec<T>, DieselError>
where where
T: JoinView,
LF: ListFn<'a, T, Args>, LF: ListFn<'a, T, Args>,
{ {
let conn = get_conn(pool).await?; let conn = get_conn(pool).await?;
let res = (self.list_fn)(conn, args).await?; (self.list_fn)(conn, args).await
Ok(res.into_iter().map(T::from_tuple).collect())
} }
} }

View file

@ -11,7 +11,6 @@ use diesel::{
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::CommentAggregates,
aliases, aliases,
newtypes::{CommentReportId, CommunityId, PersonId}, newtypes::{CommentReportId, CommunityId, PersonId},
schema::{ schema::{
@ -25,14 +24,6 @@ use lemmy_db_schema::{
person, person,
post, 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}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
}; };
@ -89,7 +80,7 @@ fn queries<'a>() -> Queries<
), ),
) )
.select(selection) .select(selection)
.first::<<CommentReportView as JoinView>::JoinTuple>(&mut conn) .first::<CommentReportView>(&mut conn)
.await .await
}; };
@ -135,12 +126,10 @@ fn queries<'a>() -> Queries<
.and(community_moderator::person_id.eq(user.person.id)), .and(community_moderator::person_id.eq(user.person.id)),
), ),
) )
.load::<<CommentReportView as JoinView>::JoinTuple>(&mut conn) .load::<CommentReportView>(&mut conn)
.await .await
} else { } else {
query query.load::<CommentReportView>(&mut conn).await
.load::<<CommentReportView as JoinView>::JoinTuple>(&mut conn)
.await
} }
}; };
@ -220,36 +209,6 @@ impl CommentReportQuery {
} }
} }
impl JoinView for CommentReportView {
type JoinTuple = (
CommentReport,
Comment,
Post,
Community,
Person,
Person,
CommentAggregates,
bool,
Option<i16>,
Option<Person>,
);
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)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]

View file

@ -12,7 +12,6 @@ use diesel::{
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use diesel_ltree::{nlevel, subpath, Ltree, LtreeExtensions}; use diesel_ltree::{nlevel, subpath, Ltree, LtreeExtensions};
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::CommentAggregates,
newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId}, newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId},
schema::{ schema::{
comment, comment,
@ -29,32 +28,12 @@ use lemmy_db_schema::{
person_block, person_block,
post, post,
}, },
source::{ source::community::CommunityFollower,
comment::Comment,
community::{Community, CommunityFollower},
person::Person,
post::Post,
},
traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType, CommentSortType,
ListingType, ListingType,
SubscribedType,
}; };
type CommentViewTuple = (
Comment,
Person,
Post,
Community,
CommentAggregates,
bool,
SubscribedType,
bool,
bool,
Option<i16>,
);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, CommentView, (CommentId, Option<PersonId>)>, impl ReadFn<'a, CommentView, (CommentId, Option<PersonId>)>,
impl ListFn<'a, CommentView, CommentQuery<'a>>, impl ListFn<'a, CommentView, CommentQuery<'a>>,
@ -129,7 +108,7 @@ fn queries<'a>() -> Queries<
(comment_id, my_person_id): (CommentId, Option<PersonId>)| async move { (comment_id, my_person_id): (CommentId, Option<PersonId>)| async move {
all_joins(comment::table.find(comment_id).into_boxed(), my_person_id) all_joins(comment::table.find(comment_id).into_boxed(), my_person_id)
.select(selection) .select(selection)
.first::<CommentViewTuple>(&mut conn) .first::<CommentView>(&mut conn)
.await .await
}; };
@ -296,7 +275,7 @@ fn queries<'a>() -> Queries<
query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.load::<CommentViewTuple>(&mut conn) .load::<CommentView>(&mut conn)
.await .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)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]
#![allow(clippy::indexing_slicing)] #![allow(clippy::indexing_slicing)]
use crate::{ use crate::{
comment_view::{ comment_view::{CommentQuery, CommentSortType, CommentView, DbPool},
Comment,
CommentQuery,
CommentSortType,
CommentView,
Community,
DbPool,
Person,
Post,
},
structs::LocalUserView, structs::LocalUserView,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -386,14 +338,14 @@ mod tests {
newtypes::LanguageId, newtypes::LanguageId,
source::{ source::{
actor_language::LocalUserLanguage, actor_language::LocalUserLanguage,
comment::{CommentInsertForm, CommentLike, CommentLikeForm}, comment::{Comment, CommentInsertForm, CommentLike, CommentLikeForm},
community::CommunityInsertForm, community::{Community, CommunityInsertForm},
instance::Instance, instance::Instance,
language::Language, language::Language,
local_user::{LocalUser, LocalUserInsertForm}, local_user::{LocalUser, LocalUserInsertForm},
person::PersonInsertForm, person::{Person, PersonInsertForm},
person_block::{PersonBlock, PersonBlockForm}, person_block::{PersonBlock, PersonBlockForm},
post::PostInsertForm, post::{Post, PostInsertForm},
}, },
traits::{Blockable, Crud, Likeable}, traits::{Blockable, Crud, Likeable},
utils::build_db_pool_for_tests, utils::build_db_pool_for_tests,

View file

@ -3,18 +3,13 @@ use actix_web::{dev::Payload, FromRequest, HttpMessage, HttpRequest};
use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, QueryDsl}; use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::PersonAggregates,
newtypes::{LocalUserId, PersonId}, newtypes::{LocalUserId, PersonId},
schema::{local_user, person, person_aggregates}, schema::{local_user, person, person_aggregates},
source::{local_user::LocalUser, person::Person},
traits::JoinView,
utils::{functions::lower, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{functions::lower, DbConn, DbPool, ListFn, Queries, ReadFn},
}; };
use lemmy_utils::error::{LemmyError, LemmyErrorType}; use lemmy_utils::error::{LemmyError, LemmyErrorType};
use std::future::{ready, Ready}; use std::future::{ready, Ready};
type LocalUserViewTuple = (LocalUser, Person, PersonAggregates);
enum ReadBy<'a> { enum ReadBy<'a> {
Id(LocalUserId), Id(LocalUserId),
Person(PersonId), Person(PersonId),
@ -56,7 +51,7 @@ fn queries<'a>(
query query
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
.select(selection) .select(selection)
.first::<LocalUserViewTuple>(&mut conn) .first::<LocalUserView>(&mut conn)
.await .await
}; };
@ -69,7 +64,7 @@ fn queries<'a>(
.inner_join(person::table) .inner_join(person::table)
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
.select(selection) .select(selection)
.load::<LocalUserViewTuple>(&mut conn) .load::<LocalUserView>(&mut conn)
.await .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 { impl FromRequest for LocalUserView {
type Error = LemmyError; type Error = LemmyError;
type Future = Ready<Result<Self, Self::Error>>; type Future = Ready<Result<Self, Self::Error>>;

View file

@ -10,7 +10,6 @@ use diesel::{
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::PostAggregates,
aliases, aliases,
newtypes::{CommunityId, PersonId, PostReportId}, newtypes::{CommunityId, PersonId, PostReportId},
schema::{ schema::{
@ -23,23 +22,9 @@ use lemmy_db_schema::{
post_like, post_like,
post_report, 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}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
}; };
type PostReportViewTuple = (
PostReport,
Post,
Community,
Person,
Person,
bool,
Option<i16>,
PostAggregates,
Option<Person>,
);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, PostReportView, (PostReportId, PersonId)>, impl ReadFn<'a, PostReportView, (PostReportId, PersonId)>,
impl ListFn<'a, PostReportView, (PostReportQuery, &'a LocalUserView)>, impl ListFn<'a, PostReportView, (PostReportQuery, &'a LocalUserView)>,
@ -87,7 +72,7 @@ fn queries<'a>() -> Queries<
post_report::table.find(report_id).into_boxed(), post_report::table.find(report_id).into_boxed(),
my_person_id, my_person_id,
) )
.first::<PostReportViewTuple>(&mut conn) .first::<PostReportView>(&mut conn)
.await .await
}; };
@ -119,10 +104,10 @@ fn queries<'a>() -> Queries<
.and(community_moderator::person_id.eq(user.person.id)), .and(community_moderator::person_id.eq(user.person.id)),
), ),
) )
.load::<PostReportViewTuple>(&mut conn) .load::<PostReportView>(&mut conn)
.await .await
} else { } else {
query.load::<PostReportViewTuple>(&mut conn).await query.load::<PostReportView>(&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)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]

View file

@ -16,7 +16,6 @@ use diesel::{
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::PostAggregates,
newtypes::{CommunityId, LocalUserId, PersonId, PostId}, newtypes::{CommunityId, LocalUserId, PersonId, PostId},
schema::{ schema::{
community, community,
@ -34,33 +33,13 @@ use lemmy_db_schema::{
post_read, post_read,
post_saved, post_saved,
}, },
source::{ source::community::CommunityFollower,
community::{Community, CommunityFollower},
person::Person,
post::Post,
},
traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
ListingType, ListingType,
SortType, SortType,
SubscribedType,
}; };
use tracing::debug; use tracing::debug;
type PostViewTuple = (
Post,
Person,
Community,
bool,
PostAggregates,
SubscribedType,
bool,
bool,
bool,
Option<i16>,
i64,
);
sql_function!(fn coalesce(x: sql_types::Nullable<sql_types::BigInt>, y: sql_types::BigInt) -> sql_types::BigInt); sql_function!(fn coalesce(x: sql_types::Nullable<sql_types::BigInt>, y: sql_types::BigInt) -> sql_types::BigInt);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
@ -182,7 +161,7 @@ fn queries<'a>() -> Queries<
); );
} }
query.first::<PostViewTuple>(&mut conn).await query.first::<PostView>(&mut conn).await
}; };
let list = move |mut conn: DbConn<'a>, options: PostQuery<'a>| async move { 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::<Pg, _>(&query)); debug!("Post View Query: {:?}", debug_query::<Pg, _>(&query));
query.load::<PostViewTuple>(&mut conn).await query.load::<PostView>(&mut conn).await
}; };
Queries::new(read, list) 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)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]

View file

@ -12,23 +12,9 @@ use lemmy_db_schema::{
aliases, aliases,
newtypes::PrivateMessageReportId, newtypes::PrivateMessageReportId,
schema::{person, private_message, private_message_report}, 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}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
}; };
type PrivateMessageReportViewTuple = (
PrivateMessageReport,
PrivateMessage,
Person,
Person,
Option<Person>,
);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, PrivateMessageReportView, PrivateMessageReportId>, impl ReadFn<'a, PrivateMessageReportView, PrivateMessageReportId>,
impl ListFn<'a, PrivateMessageReportView, PrivateMessageReportQuery>, 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 { let read = move |mut conn: DbConn<'a>, report_id: PrivateMessageReportId| async move {
all_joins(private_message_report::table.find(report_id).into_boxed()) all_joins(private_message_report::table.find(report_id).into_boxed())
.first::<PrivateMessageReportViewTuple>(&mut conn) .first::<PrivateMessageReportView>(&mut conn)
.await .await
}; };
@ -73,7 +59,7 @@ fn queries<'a>() -> Queries<
.order_by(private_message::published.desc()) .order_by(private_message::published.desc())
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.load::<PrivateMessageReportViewTuple>(&mut conn) .load::<PrivateMessageReportView>(&mut conn)
.await .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)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]

View file

@ -13,14 +13,10 @@ use lemmy_db_schema::{
aliases, aliases,
newtypes::{PersonId, PrivateMessageId}, newtypes::{PersonId, PrivateMessageId},
schema::{person, private_message}, schema::{person, private_message},
source::{person::Person, private_message::PrivateMessage},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
}; };
use tracing::debug; use tracing::debug;
type PrivateMessageViewTuple = (PrivateMessage, Person, Person);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, PrivateMessageView, PrivateMessageId>, impl ReadFn<'a, PrivateMessageView, PrivateMessageId>,
impl ListFn<'a, PrivateMessageView, (PrivateMessageQuery, PersonId)>, 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()) all_joins(private_message::table.find(private_message_id).into_boxed())
.order_by(private_message::published.desc()) .order_by(private_message::published.desc())
.select(selection) .select(selection)
.first::<PrivateMessageViewTuple>(&mut conn) .first::<PrivateMessageView>(&mut conn)
.await .await
}; };
@ -88,7 +84,7 @@ fn queries<'a>() -> Queries<
debug_query::<Pg, _>(&query) debug_query::<Pg, _>(&query)
); );
query.load::<PrivateMessageViewTuple>(&mut conn).await query.load::<PrivateMessageView>(&mut conn).await
}; };
Queries::new(read, list) 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)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]

View file

@ -12,18 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aliases, aliases,
schema::{local_user, person, registration_application}, 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}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
}; };
type RegistrationApplicationViewTuple =
(RegistrationApplication, LocalUser, Person, Option<Person>);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, RegistrationApplicationView, i32>, impl ReadFn<'a, RegistrationApplicationView, i32>,
impl ListFn<'a, RegistrationApplicationView, RegistrationApplicationQuery>, impl ListFn<'a, RegistrationApplicationView, RegistrationApplicationQuery>,
@ -51,7 +42,7 @@ fn queries<'a>() -> Queries<
.find(registration_application_id) .find(registration_application_id)
.into_boxed(), .into_boxed(),
) )
.first::<RegistrationApplicationViewTuple>(&mut conn) .first::<RegistrationApplicationView>(&mut conn)
.await .await
}; };
@ -73,9 +64,7 @@ fn queries<'a>() -> Queries<
.offset(offset) .offset(offset)
.order_by(registration_application::published.desc()); .order_by(registration_application::published.desc());
query query.load::<RegistrationApplicationView>(&mut conn).await
.load::<RegistrationApplicationViewTuple>(&mut conn)
.await
}; };
Queries::new(read, list) 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)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]

View file

@ -2,16 +2,14 @@ use crate::structs::SiteView;
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl}; use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::SiteAggregates,
schema::{local_site, local_site_rate_limit, site, site_aggregates}, 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}, utils::{get_conn, DbPool},
}; };
impl SiteView { impl SiteView {
pub async fn read_local(pool: &mut DbPool<'_>) -> Result<Self, Error> { pub async fn read_local(pool: &mut DbPool<'_>) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?; 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::table)
.inner_join( .inner_join(
local_site_rate_limit::table.on(local_site::id.eq(local_site_rate_limit::local_site_id)), 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, local_site_rate_limit::all_columns,
site_aggregates::all_columns, site_aggregates::all_columns,
)) ))
.first::<(Site, LocalSite, LocalSiteRateLimit, SiteAggregates)>(conn) .first::<SiteView>(conn)
.await?; .await?;
site.private_key = None; res.site.private_key = None;
Ok(SiteView { Ok(res)
site,
local_site,
local_site_rate_limit,
counts,
})
} }
} }

View file

@ -1,3 +1,5 @@
#[cfg(feature = "full")]
use diesel::Queryable;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates}, aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates},
source::{ source::{
@ -26,7 +28,7 @@ use ts_rs::TS;
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// A comment report view. /// A comment report view.
pub struct CommentReportView { pub struct CommentReportView {
@ -44,7 +46,7 @@ pub struct CommentReportView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// A comment view. /// A comment view.
pub struct CommentView { pub struct CommentView {
@ -61,7 +63,7 @@ pub struct CommentView {
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// A local user view. /// A local user view.
pub struct LocalUserView { pub struct LocalUserView {
@ -72,7 +74,7 @@ pub struct LocalUserView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// A post report view. /// A post report view.
pub struct PostReportView { pub struct PostReportView {
@ -89,7 +91,7 @@ pub struct PostReportView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// A post view. /// A post view.
pub struct PostView { pub struct PostView {
@ -107,7 +109,7 @@ pub struct PostView {
} }
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// A private message view. /// A private message view.
pub struct PrivateMessageView { pub struct PrivateMessageView {
@ -118,7 +120,7 @@ pub struct PrivateMessageView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// A private message report view. /// A private message report view.
pub struct PrivateMessageReportView { pub struct PrivateMessageReportView {
@ -131,7 +133,7 @@ pub struct PrivateMessageReportView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// A registration application view. /// A registration application view.
pub struct RegistrationApplicationView { pub struct RegistrationApplicationView {
@ -142,7 +144,7 @@ pub struct RegistrationApplicationView {
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// A site view. /// A site view.
pub struct SiteView { pub struct SiteView {

View file

@ -10,7 +10,6 @@ use diesel::{
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::CommentAggregates,
aliases, aliases,
newtypes::{CommentReplyId, PersonId}, newtypes::{CommentReplyId, PersonId},
schema::{ schema::{
@ -26,34 +25,11 @@ use lemmy_db_schema::{
person_block, person_block,
post, post,
}, },
source::{ source::community::CommunityFollower,
comment::Comment,
comment_reply::CommentReply,
community::{Community, CommunityFollower},
person::Person,
post::Post,
},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType, CommentSortType,
SubscribedType,
}; };
type CommentReplyViewTuple = (
CommentReply,
Comment,
Person,
Post,
Community,
Person,
CommentAggregates,
bool,
SubscribedType,
bool,
bool,
Option<i16>,
);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, CommentReplyView, (CommentReplyId, Option<PersonId>)>, impl ReadFn<'a, CommentReplyView, (CommentReplyId, Option<PersonId>)>,
impl ListFn<'a, CommentReplyView, CommentReplyQuery>, impl ListFn<'a, CommentReplyView, CommentReplyQuery>,
@ -127,7 +103,7 @@ fn queries<'a>() -> Queries<
comment_reply::table.find(comment_reply_id).into_boxed(), comment_reply::table.find(comment_reply_id).into_boxed(),
my_person_id, my_person_id,
) )
.first::<CommentReplyViewTuple>(&mut conn) .first::<CommentReplyView>(&mut conn)
.await .await
}; };
@ -161,7 +137,7 @@ fn queries<'a>() -> Queries<
query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.load::<CommentReplyViewTuple>(&mut conn) .load::<CommentReplyView>(&mut conn)
.await .await
}; };
@ -214,23 +190,3 @@ impl CommentReplyQuery {
queries().list(pool, self).await 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,
}
}
}

View file

@ -4,17 +4,13 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{community, community_block, person}, schema::{community, community_block, person},
source::{community::Community, person::Person},
traits::JoinView,
utils::{get_conn, DbPool}, utils::{get_conn, DbPool},
}; };
type CommunityBlockViewTuple = (Person, Community);
impl CommunityBlockView { impl CommunityBlockView {
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> { pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let res = community_block::table community_block::table
.inner_join(person::table) .inner_join(person::table)
.inner_join(community::table) .inner_join(community::table)
.select((person::all_columns, community::all_columns)) .select((person::all_columns, community::all_columns))
@ -22,19 +18,7 @@ impl CommunityBlockView {
.filter(community::deleted.eq(false)) .filter(community::deleted.eq(false))
.filter(community::removed.eq(false)) .filter(community::removed.eq(false))
.order_by(community_block::published) .order_by(community_block::published)
.load::<CommunityBlockViewTuple>(conn) .load::<CommunityBlockView>(conn)
.await?; .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,
}
} }
} }

View file

@ -10,13 +10,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{CommunityId, DbUrl, PersonId}, newtypes::{CommunityId, DbUrl, PersonId},
schema::{community, community_follower, person}, schema::{community, community_follower, person},
source::{community::Community, person::Person},
traits::JoinView,
utils::{get_conn, DbPool}, utils::{get_conn, DbPool},
}; };
type CommunityFollowerViewTuple = (Community, Person);
sql_function!(fn coalesce(x: diesel::sql_types::Nullable<diesel::sql_types::Text>, y: diesel::sql_types::Text) -> diesel::sql_types::Text); sql_function!(fn coalesce(x: diesel::sql_types::Nullable<diesel::sql_types::Text>, y: diesel::sql_types::Text) -> diesel::sql_types::Text);
impl CommunityFollowerView { impl CommunityFollowerView {
@ -52,7 +48,7 @@ impl CommunityFollowerView {
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> { pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let res = community_follower::table community_follower::table
.inner_join(community::table) .inner_join(community::table)
.inner_join(person::table) .inner_join(person::table)
.select((community::all_columns, person::all_columns)) .select((community::all_columns, person::all_columns))
@ -60,19 +56,7 @@ impl CommunityFollowerView {
.filter(community::deleted.eq(false)) .filter(community::deleted.eq(false))
.filter(community::removed.eq(false)) .filter(community::removed.eq(false))
.order_by(community::title) .order_by(community::title)
.load::<CommunityFollowerViewTuple>(conn) .load::<CommunityFollowerView>(conn)
.await?; .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,
}
} }
} }

View file

@ -4,13 +4,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{CommunityId, PersonId}, newtypes::{CommunityId, PersonId},
schema::{community, community_moderator, person}, schema::{community, community_moderator, person},
source::{community::Community, person::Person},
traits::JoinView,
utils::{get_conn, DbPool}, utils::{get_conn, DbPool},
}; };
type CommunityModeratorViewTuple = (Community, Person);
impl CommunityModeratorView { impl CommunityModeratorView {
pub async fn is_community_moderator( pub async fn is_community_moderator(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
@ -36,38 +32,34 @@ impl CommunityModeratorView {
community_id: CommunityId, community_id: CommunityId,
) -> Result<Vec<Self>, Error> { ) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let res = community_moderator::table community_moderator::table
.inner_join(community::table) .inner_join(community::table)
.inner_join(person::table) .inner_join(person::table)
.filter(community_moderator::community_id.eq(community_id)) .filter(community_moderator::community_id.eq(community_id))
.select((community::all_columns, person::all_columns)) .select((community::all_columns, person::all_columns))
.order_by(community_moderator::published) .order_by(community_moderator::published)
.load::<CommunityModeratorViewTuple>(conn) .load::<CommunityModeratorView>(conn)
.await?; .await
Ok(res.into_iter().map(Self::from_tuple).collect())
} }
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> { pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let res = community_moderator::table community_moderator::table
.inner_join(community::table) .inner_join(community::table)
.inner_join(person::table) .inner_join(person::table)
.filter(community_moderator::person_id.eq(person_id)) .filter(community_moderator::person_id.eq(person_id))
.filter(community::deleted.eq(false)) .filter(community::deleted.eq(false))
.filter(community::removed.eq(false)) .filter(community::removed.eq(false))
.select((community::all_columns, person::all_columns)) .select((community::all_columns, person::all_columns))
.load::<CommunityModeratorViewTuple>(conn) .load::<CommunityModeratorView>(conn)
.await?; .await
Ok(res.into_iter().map(Self::from_tuple).collect())
} }
/// Finds all communities first mods / creators /// Finds all communities first mods / creators
/// Ideally this should be a group by, but diesel doesn't support it yet /// 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<Vec<Self>, Error> { pub async fn get_community_first_mods(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let res = community_moderator::table community_moderator::table
.inner_join(community::table) .inner_join(community::table)
.inner_join(person::table) .inner_join(person::table)
.select((community::all_columns, person::all_columns)) .select((community::all_columns, person::all_columns))
@ -78,19 +70,7 @@ impl CommunityModeratorView {
community_moderator::community_id, community_moderator::community_id,
community_moderator::person_id, community_moderator::person_id,
)) ))
.load::<CommunityModeratorViewTuple>(conn) .load::<CommunityModeratorView>(conn)
.await?; .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,
}
} }
} }

View file

@ -4,7 +4,6 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{CommunityId, PersonId}, newtypes::{CommunityId, PersonId},
schema::{community, community_person_ban, person}, schema::{community, community_person_ban, person},
source::{community::Community, person::Person},
utils::{get_conn, DbPool}, utils::{get_conn, DbPool},
}; };
@ -15,16 +14,14 @@ impl CommunityPersonBanView {
from_community_id: CommunityId, from_community_id: CommunityId,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let (community, person) = community_person_ban::table community_person_ban::table
.inner_join(community::table) .inner_join(community::table)
.inner_join(person::table) .inner_join(person::table)
.select((community::all_columns, person::all_columns)) .select((community::all_columns, person::all_columns))
.filter(community_person_ban::community_id.eq(from_community_id)) .filter(community_person_ban::community_id.eq(from_community_id))
.filter(community_person_ban::person_id.eq(from_person_id)) .filter(community_person_ban::person_id.eq(from_person_id))
.order_by(community_person_ban::published) .order_by(community_person_ban::published)
.first::<(Community, Person)>(conn) .first::<CommunityPersonBanView>(conn)
.await?; .await
Ok(CommunityPersonBanView { community, person })
} }
} }

View file

@ -11,22 +11,14 @@ use diesel::{
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::CommunityAggregates,
newtypes::{CommunityId, PersonId}, newtypes::{CommunityId, PersonId},
schema::{community, community_aggregates, community_block, community_follower, local_user}, schema::{community, community_aggregates, community_block, community_follower, local_user},
source::{ source::{community::CommunityFollower, local_user::LocalUser},
community::{Community, CommunityFollower},
local_user::LocalUser,
},
traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
ListingType, ListingType,
SortType, SortType,
SubscribedType,
}; };
type CommunityViewTuple = (Community, CommunityAggregates, SubscribedType, bool);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, CommunityView, (CommunityId, Option<PersonId>, bool)>, impl ReadFn<'a, CommunityView, (CommunityId, Option<PersonId>, bool)>,
impl ListFn<'a, CommunityView, CommunityQuery<'a>>, impl ListFn<'a, CommunityView, CommunityQuery<'a>>,
@ -55,9 +47,9 @@ fn queries<'a>() -> Queries<
let selection = ( let selection = (
community::all_columns, community::all_columns,
community_aggregates::all_columns,
CommunityFollower::select_subscribed_type(), CommunityFollower::select_subscribed_type(),
community_block::id.nullable().is_not_null(), community_block::id.nullable().is_not_null(),
community_aggregates::all_columns,
); );
let not_removed_or_deleted = community::removed let not_removed_or_deleted = community::removed
@ -81,7 +73,7 @@ fn queries<'a>() -> Queries<
query = query.filter(not_removed_or_deleted); query = query.filter(not_removed_or_deleted);
} }
query.first::<CommunityViewTuple>(&mut conn).await query.first::<CommunityView>(&mut conn).await
}; };
let list = move |mut conn: DbConn<'a>, options: CommunityQuery<'a>| async move { let list = move |mut conn: DbConn<'a>, options: CommunityQuery<'a>| async move {
@ -154,7 +146,7 @@ fn queries<'a>() -> Queries<
query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.load::<CommunityViewTuple>(&mut conn) .load::<CommunityView>(&mut conn)
.await .await
}; };
@ -205,15 +197,3 @@ impl<'a> CommunityQuery<'a> {
queries().list(pool, self).await 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,
}
}
}

View file

@ -4,19 +4,15 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{person, person_block}, schema::{person, person_block},
source::person::Person,
traits::JoinView,
utils::{get_conn, DbPool}, utils::{get_conn, DbPool},
}; };
type PersonBlockViewTuple = (Person, Person);
impl PersonBlockView { impl PersonBlockView {
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> { pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let target_person_alias = diesel::alias!(person as person1); 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(person::table.on(person_block::person_id.eq(person::id)))
.inner_join( .inner_join(
target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))), 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(person_block::person_id.eq(person_id))
.filter(target_person_alias.field(person::deleted).eq(false)) .filter(target_person_alias.field(person::deleted).eq(false))
.order_by(person_block::published) .order_by(person_block::published)
.load::<PersonBlockViewTuple>(conn) .load::<PersonBlockView>(conn)
.await?; .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,
}
} }
} }

View file

@ -11,7 +11,6 @@ use diesel::{
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::CommentAggregates,
aliases, aliases,
newtypes::{PersonId, PersonMentionId}, newtypes::{PersonId, PersonMentionId},
schema::{ schema::{
@ -27,34 +26,11 @@ use lemmy_db_schema::{
person_mention, person_mention,
post, post,
}, },
source::{ source::community::CommunityFollower,
comment::Comment,
community::{Community, CommunityFollower},
person::Person,
person_mention::PersonMention,
post::Post,
},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType, CommentSortType,
SubscribedType,
}; };
type PersonMentionViewTuple = (
PersonMention,
Comment,
Person,
Post,
Community,
Person,
CommentAggregates,
bool,
SubscribedType,
bool,
bool,
Option<i16>,
);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, PersonMentionView, (PersonMentionId, Option<PersonId>)>, impl ReadFn<'a, PersonMentionView, (PersonMentionId, Option<PersonId>)>,
impl ListFn<'a, PersonMentionView, PersonMentionQuery>, impl ListFn<'a, PersonMentionView, PersonMentionQuery>,
@ -130,7 +106,7 @@ fn queries<'a>() -> Queries<
), ),
) )
.select(selection) .select(selection)
.first::<PersonMentionViewTuple>(&mut conn) .first::<PersonMentionView>(&mut conn)
.await .await
}; };
@ -177,7 +153,7 @@ fn queries<'a>() -> Queries<
query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.load::<PersonMentionViewTuple>(&mut conn) .load::<PersonMentionView>(&mut conn)
.await .await
}; };
@ -231,23 +207,3 @@ impl PersonMentionQuery {
queries().list(pool, self).await 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,
}
}
}

View file

@ -10,18 +10,13 @@ use diesel::{
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::PersonAggregates,
newtypes::PersonId, newtypes::PersonId,
schema, schema,
schema::{local_user, person, person_aggregates}, 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}, utils::{fuzzy_search, get_conn, limit_and_offset, now, DbConn, DbPool, ListFn, Queries, ReadFn},
PersonSortType, PersonSortType,
}; };
type PersonViewTuple = (Person, PersonAggregates);
enum ListMode { enum ListMode {
Admins, Admins,
Banned, Banned,
@ -39,7 +34,7 @@ fn queries<'a>(
let read = move |mut conn: DbConn<'a>, person_id: PersonId| async move { let read = move |mut conn: DbConn<'a>, person_id: PersonId| async move {
all_joins(person::table.find(person_id).into_boxed()) all_joins(person::table.find(person_id).into_boxed())
.first::<PersonViewTuple>(&mut conn) .first::<PersonView>(&mut conn)
.await .await
}; };
@ -84,7 +79,7 @@ fn queries<'a>(
query = query.limit(limit).offset(offset); query = query.limit(limit).offset(offset);
} }
} }
query.load::<PersonViewTuple>(&mut conn).await query.load::<PersonView>(&mut conn).await
}; };
Queries::new(read, list) Queries::new(read, list)
@ -132,13 +127,3 @@ impl PersonQuery {
queries().list(pool, ListMode::Query(self)).await 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,
}
}
}

View file

@ -1,3 +1,5 @@
#[cfg(feature = "full")]
use diesel::Queryable;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::{CommentAggregates, CommunityAggregates, PersonAggregates}, aggregates::structs::{CommentAggregates, CommunityAggregates, PersonAggregates},
source::{ source::{
@ -16,7 +18,7 @@ use serde_with::skip_serializing_none;
use ts_rs::TS; use ts_rs::TS;
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// A community block. /// A community block.
pub struct CommunityBlockView { pub struct CommunityBlockView {
@ -25,7 +27,7 @@ pub struct CommunityBlockView {
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// A community follower. /// A community follower.
pub struct CommunityFollowerView { pub struct CommunityFollowerView {
@ -34,7 +36,7 @@ pub struct CommunityFollowerView {
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// A community moderator. /// A community moderator.
pub struct CommunityModeratorView { pub struct CommunityModeratorView {
@ -43,6 +45,7 @@ pub struct CommunityModeratorView {
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable))]
/// A community person ban. /// A community person ban.
pub struct CommunityPersonBanView { pub struct CommunityPersonBanView {
pub community: Community, pub community: Community,
@ -50,7 +53,7 @@ pub struct CommunityPersonBanView {
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// A community view. /// A community view.
pub struct CommunityView { pub struct CommunityView {
@ -61,7 +64,7 @@ pub struct CommunityView {
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// A person block. /// A person block.
pub struct PersonBlockView { pub struct PersonBlockView {
@ -71,7 +74,7 @@ pub struct PersonBlockView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// A person mention view. /// A person mention view.
pub struct PersonMentionView { pub struct PersonMentionView {
@ -91,7 +94,7 @@ pub struct PersonMentionView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// A comment reply view. /// A comment reply view.
pub struct CommentReplyView { pub struct CommentReplyView {
@ -110,7 +113,7 @@ pub struct CommentReplyView {
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// A person view. /// A person view.
pub struct PersonView { pub struct PersonView {

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{admin_purge_comment, person, post}, schema::{admin_purge_comment, person, post},
source::{moderator::AdminPurgeComment, person::Person, post::Post},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<Person>, Post);
impl AdminPurgeCommentView { impl AdminPurgeCommentView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -46,25 +42,11 @@ impl AdminPurgeCommentView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(admin_purge_comment::when_.desc()) .order_by(admin_purge_comment::when_.desc())
.load::<AdminPurgeCommentViewTuple>(conn) .load::<AdminPurgeCommentView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{admin_purge_community, person}, schema::{admin_purge_community, person},
source::{moderator::AdminPurgeCommunity, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<Person>);
impl AdminPurgeCommunityView { impl AdminPurgeCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -44,24 +40,11 @@ impl AdminPurgeCommunityView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(admin_purge_community::when_.desc()) .order_by(admin_purge_community::when_.desc())
.load::<AdminPurgeCommunityViewTuple>(conn) .load::<AdminPurgeCommunityView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{admin_purge_person, person}, schema::{admin_purge_person, person},
source::{moderator::AdminPurgePerson, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<Person>);
impl AdminPurgePersonView { impl AdminPurgePersonView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -44,24 +40,11 @@ impl AdminPurgePersonView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(admin_purge_person::when_.desc()) .order_by(admin_purge_person::when_.desc())
.load::<AdminPurgePersonViewTuple>(conn) .load::<AdminPurgePersonView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{admin_purge_post, community, person}, schema::{admin_purge_post, community, person},
source::{community::Community, moderator::AdminPurgePost, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type AdminPurgePostViewTuple = (AdminPurgePost, Option<Person>, Community);
impl AdminPurgePostView { impl AdminPurgePostView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -46,25 +42,11 @@ impl AdminPurgePostView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(admin_purge_post::when_.desc()) .order_by(admin_purge_post::when_.desc())
.load::<AdminPurgePostViewTuple>(conn) .load::<AdminPurgePostView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{community, mod_add_community, person}, schema::{community, mod_add_community, person},
source::{community::Community, moderator::ModAddCommunity, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModAddCommunityViewTuple = (ModAddCommunity, Option<Person>, Community, Person);
impl ModAddCommunityView { impl ModAddCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -58,26 +54,11 @@ impl ModAddCommunityView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_add_community::when_.desc()) .order_by(mod_add_community::when_.desc())
.load::<ModAddCommunityViewTuple>(conn) .load::<ModAddCommunityView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{mod_add, person}, schema::{mod_add, person},
source::{moderator::ModAdd, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModAddViewTuple = (ModAdd, Option<Person>, Person);
impl ModAddView { impl ModAddView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -50,25 +46,11 @@ impl ModAddView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_add::when_.desc()) .order_by(mod_add::when_.desc())
.load::<ModAddViewTuple>(conn) .load::<ModAddView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{community, mod_ban_from_community, person}, schema::{community, mod_ban_from_community, person},
source::{community::Community, moderator::ModBanFromCommunity, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option<Person>, Community, Person);
impl ModBanFromCommunityView { impl ModBanFromCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -60,26 +56,11 @@ impl ModBanFromCommunityView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_ban_from_community::when_.desc()) .order_by(mod_ban_from_community::when_.desc())
.load::<ModBanFromCommunityViewTuple>(conn) .load::<ModBanFromCommunityView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{mod_ban, person}, schema::{mod_ban, person},
source::{moderator::ModBan, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModBanViewTuple = (ModBan, Option<Person>, Person);
impl ModBanView { impl ModBanView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -50,25 +46,11 @@ impl ModBanView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_ban::when_.desc()) .order_by(mod_ban::when_.desc())
.load::<ModBanViewTuple>(conn) .load::<ModBanView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{community, mod_feature_post, person, post}, 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}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModFeaturePostViewTuple = (ModFeaturePost, Option<Person>, Post, Community);
impl ModFeaturePostView { impl ModFeaturePostView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -57,26 +53,11 @@ impl ModFeaturePostView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_feature_post::when_.desc()) .order_by(mod_feature_post::when_.desc())
.load::<ModFeaturePostViewTuple>(conn) .load::<ModFeaturePostView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{community, mod_hide_community, person}, schema::{community, mod_hide_community, person},
source::{community::Community, moderator::ModHideCommunity, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModHideCommunityViewTuple = (ModHideCommunity, Option<Person>, Community);
impl ModHideCommunityView { impl ModHideCommunityView {
// Pass in mod_id as admin_id because only admins can do this action // Pass in mod_id as admin_id because only admins can do this action
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
@ -51,25 +47,11 @@ impl ModHideCommunityView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_hide_community::when_.desc()) .order_by(mod_hide_community::when_.desc())
.load::<ModHideCommunityViewTuple>(conn) .load::<ModHideCommunityView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{community, mod_lock_post, person, post}, 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}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModLockPostViewTuple = (ModLockPost, Option<Person>, Post, Community);
impl ModLockPostView { impl ModLockPostView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -58,26 +54,11 @@ impl ModLockPostView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_lock_post::when_.desc()) .order_by(mod_lock_post::when_.desc())
.load::<ModLockPostViewTuple>(conn) .load::<ModLockPostView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,26 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{comment, community, mod_remove_comment, person, post}, 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}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModRemoveCommentViewTuple = (
ModRemoveComment,
Option<Person>,
Comment,
Person,
Post,
Community,
);
impl ModRemoveCommentView { impl ModRemoveCommentView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -73,28 +56,11 @@ impl ModRemoveCommentView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_remove_comment::when_.desc()) .order_by(mod_remove_comment::when_.desc())
.load::<ModRemoveCommentViewTuple>(conn) .load::<ModRemoveCommentView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{community, mod_remove_community, person}, schema::{community, mod_remove_community, person},
source::{community::Community, moderator::ModRemoveCommunity, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<Person>, Community);
impl ModRemoveCommunityView { impl ModRemoveCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -45,25 +41,11 @@ impl ModRemoveCommunityView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_remove_community::when_.desc()) .order_by(mod_remove_community::when_.desc())
.load::<ModRemoveCommunityTuple>(conn) .load::<ModRemoveCommunityView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{community, mod_remove_post, person, post}, 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}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModRemovePostViewTuple = (ModRemovePost, Option<Person>, Post, Community);
impl ModRemovePostView { impl ModRemovePostView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -58,26 +54,11 @@ impl ModRemovePostView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_remove_post::when_.desc()) .order_by(mod_remove_post::when_.desc())
.load::<ModRemovePostViewTuple>(conn) .load::<ModRemovePostView>(conn)
.await?; .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,
}
} }
} }

View file

@ -12,13 +12,9 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::PersonId, newtypes::PersonId,
schema::{community, mod_transfer_community, person}, schema::{community, mod_transfer_community, person},
source::{community::Community, moderator::ModTransferCommunity, person::Person},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool}, utils::{get_conn, limit_and_offset, DbPool},
}; };
type ModTransferCommunityViewTuple = (ModTransferCommunity, Option<Person>, Community, Person);
impl ModTransferCommunityView { impl ModTransferCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> { pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
@ -60,26 +56,11 @@ impl ModTransferCommunityView {
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
let res = query query
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.order_by(mod_transfer_community::when_.desc()) .order_by(mod_transfer_community::when_.desc())
.load::<ModTransferCommunityViewTuple>(conn) .load::<ModTransferCommunityView>(conn)
.await?; .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,
}
} }
} }

View file

@ -1,3 +1,5 @@
#[cfg(feature = "full")]
use diesel::Queryable;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{CommunityId, PersonId}, newtypes::{CommunityId, PersonId},
source::{ source::{
@ -31,7 +33,7 @@ use ts_rs::TS;
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When someone is added as a community moderator. /// When someone is added as a community moderator.
pub struct ModAddCommunityView { pub struct ModAddCommunityView {
@ -43,7 +45,7 @@ pub struct ModAddCommunityView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When someone is added as a site moderator. /// When someone is added as a site moderator.
pub struct ModAddView { pub struct ModAddView {
@ -54,7 +56,7 @@ pub struct ModAddView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When someone is banned from a community. /// When someone is banned from a community.
pub struct ModBanFromCommunityView { pub struct ModBanFromCommunityView {
@ -66,7 +68,7 @@ pub struct ModBanFromCommunityView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When someone is banned from the site. /// When someone is banned from the site.
pub struct ModBanView { pub struct ModBanView {
@ -77,7 +79,7 @@ pub struct ModBanView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When a community is hidden from public view. /// When a community is hidden from public view.
pub struct ModHideCommunityView { pub struct ModHideCommunityView {
@ -88,7 +90,7 @@ pub struct ModHideCommunityView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When a moderator locks a post (prevents new comments being made). /// When a moderator locks a post (prevents new comments being made).
pub struct ModLockPostView { pub struct ModLockPostView {
@ -100,7 +102,7 @@ pub struct ModLockPostView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When a moderator removes a comment. /// When a moderator removes a comment.
pub struct ModRemoveCommentView { pub struct ModRemoveCommentView {
@ -114,7 +116,7 @@ pub struct ModRemoveCommentView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When a moderator removes a community. /// When a moderator removes a community.
pub struct ModRemoveCommunityView { pub struct ModRemoveCommunityView {
@ -125,7 +127,7 @@ pub struct ModRemoveCommunityView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When a moderator removes a post. /// When a moderator removes a post.
pub struct ModRemovePostView { pub struct ModRemovePostView {
@ -137,7 +139,7 @@ pub struct ModRemovePostView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When a moderator features a post on a community (pins it to the top). /// When a moderator features a post on a community (pins it to the top).
pub struct ModFeaturePostView { pub struct ModFeaturePostView {
@ -149,7 +151,7 @@ pub struct ModFeaturePostView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When a moderator transfers a community to a new owner. /// When a moderator transfers a community to a new owner.
pub struct ModTransferCommunityView { pub struct ModTransferCommunityView {
@ -161,7 +163,7 @@ pub struct ModTransferCommunityView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When an admin purges a comment. /// When an admin purges a comment.
pub struct AdminPurgeCommentView { pub struct AdminPurgeCommentView {
@ -172,7 +174,7 @@ pub struct AdminPurgeCommentView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When an admin purges a community. /// When an admin purges a community.
pub struct AdminPurgeCommunityView { pub struct AdminPurgeCommunityView {
@ -182,7 +184,7 @@ pub struct AdminPurgeCommunityView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When an admin purges a person. /// When an admin purges a person.
pub struct AdminPurgePersonView { pub struct AdminPurgePersonView {
@ -192,7 +194,7 @@ pub struct AdminPurgePersonView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// When an admin purges a post. /// When an admin purges a post.
pub struct AdminPurgePostView { pub struct AdminPurgePostView {
@ -203,7 +205,7 @@ pub struct AdminPurgePostView {
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy)] #[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))] #[cfg_attr(feature = "full", ts(export))]
/// Querying / filtering the modlog. /// Querying / filtering the modlog.
pub struct ModlogListParams { pub struct ModlogListParams {