X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fdb_views%2Fsrc%2Fpost_report_view.rs;h=50b35b1c258bbce2db25ac04c501937c7af90371;hb=92568956353f21649ed9aff68b42699c9d036f30;hp=19822c795ae426bb8b4754d358f58730a84977d3;hpb=8cb5939f5048c3eab293884923d4c3d5fcc08e2f;p=lemmy.git diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 19822c79..50b35b1c 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -30,7 +30,6 @@ use lemmy_db_schema::{ traits::JoinView, utils::{get_conn, limit_and_offset, DbPool}, }; -use typed_builder::TypedBuilder; type PostReportViewTuple = ( PostReport, @@ -49,7 +48,7 @@ impl PostReportView { /// /// * `report_id` - the report id to obtain pub async fn read( - pool: &DbPool, + pool: &mut DbPool<'_>, report_id: PostReportId, my_person_id: PersonId, ) -> Result { @@ -121,7 +120,7 @@ impl PostReportView { /// returns the current unresolved post report count for the communities you mod pub async fn get_report_count( - pool: &DbPool, + pool: &mut DbPool<'_>, my_person_id: PersonId, admin: bool, community_id: Option, @@ -159,24 +158,21 @@ impl PostReportView { } } -#[derive(TypedBuilder)] -#[builder(field_defaults(default))] -pub struct PostReportQuery<'a> { - #[builder(!default)] - pool: &'a DbPool, - #[builder(!default)] - my_person_id: PersonId, - #[builder(!default)] - admin: bool, - community_id: Option, - page: Option, - limit: Option, - unresolved_only: Option, +#[derive(Default)] +pub struct PostReportQuery { + pub community_id: Option, + pub page: Option, + pub limit: Option, + pub unresolved_only: Option, } -impl<'a> PostReportQuery<'a> { - pub async fn list(self) -> Result, Error> { - let conn = &mut get_conn(self.pool).await?; +impl PostReportQuery { + pub async fn list( + self, + pool: &mut DbPool<'_>, + my_person: &Person, + ) -> Result, Error> { + let conn = &mut get_conn(pool).await?; let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); let mut query = post_report::table @@ -195,7 +191,7 @@ impl<'a> PostReportQuery<'a> { post_like::table.on( post::id .eq(post_like::post_id) - .and(post_like::person_id.eq(self.my_person_id)), + .and(post_like::person_id.eq(my_person.id)), ), ) .inner_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id))) @@ -231,13 +227,13 @@ impl<'a> PostReportQuery<'a> { .offset(offset); // If its not an admin, get only the ones you mod - let res = if !self.admin { + let res = if !my_person.admin { query .inner_join( community_moderator::table.on( community_moderator::community_id .eq(post::community_id) - .and(community_moderator::person_id.eq(self.my_person_id)), + .and(community_moderator::person_id.eq(my_person.id)), ), ) .load::(conn) @@ -269,6 +265,9 @@ impl JoinView for PostReportView { #[cfg(test)] mod tests { + #![allow(clippy::unwrap_used)] + #![allow(clippy::indexing_slicing)] + use crate::post_report_view::{PostReportQuery, PostReportView}; use lemmy_db_schema::{ aggregates::structs::PostAggregates, @@ -288,6 +287,7 @@ mod tests { #[serial] async fn test_crud() { let pool = &build_db_pool_for_tests().await; + let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()) .await @@ -505,12 +505,8 @@ mod tests { }; // Do a batch read of timmys reports - let reports = PostReportQuery::builder() - .pool(pool) - .my_person_id(inserted_timmy.id) - .admin(false) - .build() - .list() + let reports = PostReportQuery::default() + .list(pool, &inserted_timmy) .await .unwrap(); @@ -579,15 +575,13 @@ mod tests { // Do a batch read of timmys reports // It should only show saras, which is unresolved - let reports_after_resolve = PostReportQuery::builder() - .pool(pool) - .my_person_id(inserted_timmy.id) - .admin(false) - .unresolved_only(Some(true)) - .build() - .list() - .await - .unwrap(); + let reports_after_resolve = PostReportQuery { + unresolved_only: (Some(true)), + ..Default::default() + } + .list(pool, &inserted_timmy) + .await + .unwrap(); assert_eq!(reports_after_resolve[0], expected_sara_report_view); // Make sure the counts are correct