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;
}
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(

View file

@ -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<diesel::dsl::now, diesel::sql_types::Timestamptz> {
pub type ResultFuture<'a, T> = BoxFuture<'a, Result<T, DieselError>>;
pub trait ReadFn<'a, T: JoinView, Args>:
Fn(DbConn<'a>, Args) -> ResultFuture<'a, <T as JoinView>::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, <T as JoinView>::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<<T as JoinView>::JoinTuple>>
{
}
pub trait ListFn<'a, T, Args>: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec<T>> {}
impl<
'a,
T: JoinView,
Args,
F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec<<T as JoinView>::JoinTuple>>,
> ListFn<'a, T, Args> for F
{
}
impl<'a, T, Args, F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec<T>>> 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<RF, LF> {
@ -471,11 +450,8 @@ impl Queries<(), ()> {
list_fn: LF2,
) -> Queries<impl ReadFn<'a, RT, RA>, impl ListFn<'a, LT, LA>>
where
RFut: Future<Output = Result<<RT as JoinView>::JoinTuple, DieselError>> + Sized + Send + 'a,
LFut:
Future<Output = Result<Vec<<LT as JoinView>::JoinTuple>, DieselError>> + Sized + Send + 'a,
RT: JoinView,
LT: JoinView,
RFut: Future<Output = Result<RT, DieselError>> + Sized + Send + 'a,
LFut: Future<Output = Result<Vec<LT>, DieselError>> + Sized + Send + 'a,
RF2: Fn(DbConn<'a>, RA) -> RFut,
LF2: Fn(DbConn<'a>, LA) -> LFut,
{
@ -493,12 +469,10 @@ impl<RF, LF> Queries<RF, LF> {
args: Args,
) -> Result<T, DieselError>
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<RF, LF> Queries<RF, LF> {
args: Args,
) -> Result<Vec<T>, 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
}
}

View file

@ -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::<<CommentReportView as JoinView>::JoinTuple>(&mut conn)
.first::<CommentReportView>(&mut conn)
.await
};
@ -135,12 +126,10 @@ fn queries<'a>() -> Queries<
.and(community_moderator::person_id.eq(user.person.id)),
),
)
.load::<<CommentReportView as JoinView>::JoinTuple>(&mut conn)
.load::<CommentReportView>(&mut conn)
.await
} else {
query
.load::<<CommentReportView as JoinView>::JoinTuple>(&mut conn)
.await
query.load::<CommentReportView>(&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)]
mod tests {
#![allow(clippy::unwrap_used)]

View file

@ -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<i16>,
);
fn queries<'a>() -> Queries<
impl ReadFn<'a, CommentView, (CommentId, Option<PersonId>)>,
impl ListFn<'a, CommentView, CommentQuery<'a>>,
@ -129,7 +108,7 @@ fn queries<'a>() -> Queries<
(comment_id, my_person_id): (CommentId, Option<PersonId>)| async move {
all_joins(comment::table.find(comment_id).into_boxed(), my_person_id)
.select(selection)
.first::<CommentViewTuple>(&mut conn)
.first::<CommentView>(&mut conn)
.await
};
@ -296,7 +275,7 @@ fn queries<'a>() -> Queries<
query
.limit(limit)
.offset(offset)
.load::<CommentViewTuple>(&mut conn)
.load::<CommentView>(&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,

View file

@ -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::<LocalUserViewTuple>(&mut conn)
.first::<LocalUserView>(&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::<LocalUserViewTuple>(&mut conn)
.load::<LocalUserView>(&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<Result<Self, Self::Error>>;

View file

@ -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<i16>,
PostAggregates,
Option<Person>,
);
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::<PostReportViewTuple>(&mut conn)
.first::<PostReportView>(&mut conn)
.await
};
@ -119,10 +104,10 @@ fn queries<'a>() -> Queries<
.and(community_moderator::person_id.eq(user.person.id)),
),
)
.load::<PostReportViewTuple>(&mut conn)
.load::<PostReportView>(&mut conn)
.await
} 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)]
mod tests {
#![allow(clippy::unwrap_used)]

View file

@ -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<i16>,
i64,
);
sql_function!(fn coalesce(x: sql_types::Nullable<sql_types::BigInt>, y: sql_types::BigInt) -> sql_types::BigInt);
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 {
@ -395,7 +374,7 @@ fn queries<'a>() -> Queries<
debug!("Post View Query: {:?}", debug_query::<Pg, _>(&query));
query.load::<PostViewTuple>(&mut conn).await
query.load::<PostView>(&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)]

View file

@ -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<Person>,
);
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::<PrivateMessageReportViewTuple>(&mut conn)
.first::<PrivateMessageReportView>(&mut conn)
.await
};
@ -73,7 +59,7 @@ fn queries<'a>() -> Queries<
.order_by(private_message::published.desc())
.limit(limit)
.offset(offset)
.load::<PrivateMessageReportViewTuple>(&mut conn)
.load::<PrivateMessageReportView>(&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)]

View file

@ -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::<PrivateMessageViewTuple>(&mut conn)
.first::<PrivateMessageView>(&mut conn)
.await
};
@ -88,7 +84,7 @@ fn queries<'a>() -> Queries<
debug_query::<Pg, _>(&query)
);
query.load::<PrivateMessageViewTuple>(&mut conn).await
query.load::<PrivateMessageView>(&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)]

View file

@ -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<Person>);
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::<RegistrationApplicationViewTuple>(&mut conn)
.first::<RegistrationApplicationView>(&mut conn)
.await
};
@ -73,9 +64,7 @@ fn queries<'a>() -> Queries<
.offset(offset)
.order_by(registration_application::published.desc());
query
.load::<RegistrationApplicationViewTuple>(&mut conn)
.await
query.load::<RegistrationApplicationView>(&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)]

View file

@ -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<Self, Error> {
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::<SiteView>(conn)
.await?;
site.private_key = None;
Ok(SiteView {
site,
local_site,
local_site_rate_limit,
counts,
})
res.site.private_key = None;
Ok(res)
}
}

View file

@ -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 {

View file

@ -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<i16>,
);
fn queries<'a>() -> Queries<
impl ReadFn<'a, CommentReplyView, (CommentReplyId, Option<PersonId>)>,
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::<CommentReplyViewTuple>(&mut conn)
.first::<CommentReplyView>(&mut conn)
.await
};
@ -161,7 +137,7 @@ fn queries<'a>() -> Queries<
query
.limit(limit)
.offset(offset)
.load::<CommentReplyViewTuple>(&mut conn)
.load::<CommentReplyView>(&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,
}
}
}

View file

@ -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<Vec<Self>, 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::<CommunityBlockViewTuple>(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::<CommunityBlockView>(conn)
.await
}
}

View file

@ -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<diesel::sql_types::Text>, 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<Vec<Self>, 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::<CommunityFollowerViewTuple>(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::<CommunityFollowerView>(conn)
.await
}
}

View file

@ -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<Vec<Self>, 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::<CommunityModeratorViewTuple>(conn)
.await?;
Ok(res.into_iter().map(Self::from_tuple).collect())
.load::<CommunityModeratorView>(conn)
.await
}
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, 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::<CommunityModeratorViewTuple>(conn)
.await?;
Ok(res.into_iter().map(Self::from_tuple).collect())
.load::<CommunityModeratorView>(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<Vec<Self>, 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::<CommunityModeratorViewTuple>(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::<CommunityModeratorView>(conn)
.await
}
}

View file

@ -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<Self, Error> {
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::<CommunityPersonBanView>(conn)
.await
}
}

View file

@ -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<PersonId>, 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::<CommunityViewTuple>(&mut conn).await
query.first::<CommunityView>(&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::<CommunityViewTuple>(&mut conn)
.load::<CommunityView>(&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,
}
}
}

View file

@ -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<Vec<Self>, 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::<PersonBlockViewTuple>(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::<PersonBlockView>(conn)
.await
}
}

View file

@ -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<i16>,
);
fn queries<'a>() -> Queries<
impl ReadFn<'a, PersonMentionView, (PersonMentionId, Option<PersonId>)>,
impl ListFn<'a, PersonMentionView, PersonMentionQuery>,
@ -130,7 +106,7 @@ fn queries<'a>() -> Queries<
),
)
.select(selection)
.first::<PersonMentionViewTuple>(&mut conn)
.first::<PersonMentionView>(&mut conn)
.await
};
@ -177,7 +153,7 @@ fn queries<'a>() -> Queries<
query
.limit(limit)
.offset(offset)
.load::<PersonMentionViewTuple>(&mut conn)
.load::<PersonMentionView>(&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,
}
}
}

View file

@ -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::<PersonViewTuple>(&mut conn)
.first::<PersonView>(&mut conn)
.await
};
@ -84,7 +79,7 @@ fn queries<'a>(
query = query.limit(limit).offset(offset);
}
}
query.load::<PersonViewTuple>(&mut conn).await
query.load::<PersonView>(&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,
}
}
}

View file

@ -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 {

View file

@ -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<Person>, Post);
impl AdminPurgeCommentView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<AdminPurgeCommentViewTuple>(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::<AdminPurgeCommentView>(conn)
.await
}
}

View file

@ -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<Person>);
impl AdminPurgeCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<AdminPurgeCommunityViewTuple>(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::<AdminPurgeCommunityView>(conn)
.await
}
}

View file

@ -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<Person>);
impl AdminPurgePersonView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<AdminPurgePersonViewTuple>(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::<AdminPurgePersonView>(conn)
.await
}
}

View file

@ -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<Person>, Community);
impl AdminPurgePostView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<AdminPurgePostViewTuple>(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::<AdminPurgePostView>(conn)
.await
}
}

View file

@ -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<Person>, Community, Person);
impl ModAddCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModAddCommunityViewTuple>(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::<ModAddCommunityView>(conn)
.await
}
}

View file

@ -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>, Person);
impl ModAddView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModAddViewTuple>(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::<ModAddView>(conn)
.await
}
}

View file

@ -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<Person>, Community, Person);
impl ModBanFromCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModBanFromCommunityViewTuple>(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::<ModBanFromCommunityView>(conn)
.await
}
}

View file

@ -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>, Person);
impl ModBanView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModBanViewTuple>(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::<ModBanView>(conn)
.await
}
}

View file

@ -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<Person>, Post, Community);
impl ModFeaturePostView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModFeaturePostViewTuple>(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::<ModFeaturePostView>(conn)
.await
}
}

View file

@ -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<Person>, 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<Vec<Self>, 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::<ModHideCommunityViewTuple>(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::<ModHideCommunityView>(conn)
.await
}
}

View file

@ -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<Person>, Post, Community);
impl ModLockPostView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModLockPostViewTuple>(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::<ModLockPostView>(conn)
.await
}
}

View file

@ -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<Person>,
Comment,
Person,
Post,
Community,
);
impl ModRemoveCommentView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModRemoveCommentViewTuple>(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::<ModRemoveCommentView>(conn)
.await
}
}

View file

@ -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<Person>, Community);
impl ModRemoveCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModRemoveCommunityTuple>(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::<ModRemoveCommunityView>(conn)
.await
}
}

View file

@ -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<Person>, Post, Community);
impl ModRemovePostView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModRemovePostViewTuple>(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::<ModRemovePostView>(conn)
.await
}
}

View file

@ -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<Person>, Community, Person);
impl ModTransferCommunityView {
pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, 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::<ModTransferCommunityViewTuple>(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::<ModTransferCommunityView>(conn)
.await
}
}

View file

@ -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 {