From 158f7f0cd9a07392fb1f457ac43c8d7c57e4190d Mon Sep 17 00:00:00 2001 From: dull b Date: Sat, 29 Jul 2023 01:55:40 +0000 Subject: [PATCH] CommunityPersonBanAdditionalInfo (partial) --- crates/db_schema/src/impls/community.rs | 13 +++++++++++++ crates/db_schema/src/source/community.rs | 10 ++++++++++ crates/db_views/src/comment_report_view.rs | 4 ++-- crates/db_views/src/comment_view.rs | 4 ++-- crates/db_views/src/post_report_view.rs | 4 ++-- crates/db_views/src/post_view.rs | 4 ++-- crates/db_views_actor/src/comment_reply_view.rs | 4 ++-- crates/db_views_actor/src/person_mention_view.rs | 4 ++-- 8 files changed, 35 insertions(+), 12 deletions(-) diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index 258e41504..032bce202 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -11,6 +11,7 @@ use crate::{ CommunityModerator, CommunityModeratorForm, CommunityPersonBan, + CommunityPersonBanAdditionalInfo, CommunityPersonBanForm, CommunityUpdateForm, }, @@ -214,6 +215,18 @@ impl Bannable for CommunityPersonBan { } } +impl CommunityPersonBanAdditionalInfo { + pub fn into_full(self, community_id: CommunityId, person_id: PersonId) -> CommunityPersonBan { + CommunityPersonBan { + id: self.id, + published: self.published, + expires: self.expires, + community_id, + person_id, + } + } +} + impl CommunityFollower { pub fn to_subscribed_type(follower: &Option) -> SubscribedType { match follower { diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index 64b30b2a8..6d8ba50be 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -162,6 +162,16 @@ pub struct CommunityPersonBan { pub expires: Option, } +#[derive(PartialEq, Eq, Debug)] +#[cfg_attr(feature = "full", derive(Queryable, Selectable))] +#[cfg_attr(feature = "full", diesel(table_name = community_person_ban))] +/// Like `CommunityPersonBan` but without `community_id` and `person_id`, which are usually already known +pub struct CommunityPersonBanAdditionalInfo { + pub id: i32, + pub published: chrono::NaiveDateTime, + pub expires: Option, +} + #[derive(Clone)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))] diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 3ee3934b5..505a01797 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -72,7 +72,7 @@ fn queries<'a>() -> Queries< person::all_columns, aliases::person1.fields(person::all_columns), CommentAggregatesNotInComment::as_select(), - community_person_ban::all_columns.nullable(), + CommunityPersonBanAdditionalInfo::as_select().nullable(), comment_like::score.nullable(), aliases::person2.fields(person::all_columns).nullable(), ); @@ -229,7 +229,7 @@ impl JoinView for CommentReportView { Person, Person, CommentAggregatesNotInComment, - Option, + Option, Option, Option, ); diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index f126bfd2a..4f1b15f0e 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -48,7 +48,7 @@ type CommentViewTuple = ( Post, Community, CommentAggregatesNotInComment, - Option, + Option, Option, Option, Option, @@ -110,7 +110,7 @@ fn queries<'a>() -> Queries< post::all_columns, community::all_columns, CommentAggregatesNotInComment::as_select(), - community_person_ban::all_columns.nullable(), + CommunityPersonBanAdditionalInfo::as_select().nullable(), community_follower::all_columns.nullable(), comment_saved::all_columns.nullable(), person_block::all_columns.nullable(), diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 2d31fd0b2..b1ac4142c 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -40,7 +40,7 @@ type PostReportViewTuple = ( Community, Person, Person, - Option, + Option, Option, PostAggregatesNotInPost, Option, @@ -81,7 +81,7 @@ fn queries<'a>() -> Queries< community::all_columns, person::all_columns, aliases::person1.fields(person::all_columns), - community_person_ban::all_columns.nullable(), + CommunityPersonBanAdditionalInfo::as_select().nullable(), post_like::score.nullable(), PostAggregatesNotInPost::as_select(), aliases::person2.fields(person::all_columns.nullable()), diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 519463265..33870eff6 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -51,7 +51,7 @@ type PostViewTuple = ( Post, Person, Community, - Option, + Option, PostAggregatesNotInPost, Option, Option, @@ -137,7 +137,7 @@ fn queries<'a>() -> Queries< post::all_columns, person::all_columns, community::all_columns, - community_person_ban::all_columns.nullable(), + CommunityPersonBanAdditionalInfo::as_select().nullable(), PostAggregatesNotInPost::as_select(), community_follower::all_columns.nullable(), post_saved::all_columns.nullable(), diff --git a/crates/db_views_actor/src/comment_reply_view.rs b/crates/db_views_actor/src/comment_reply_view.rs index 3c2ce07fc..6d993dbf2 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -48,7 +48,7 @@ type CommentReplyViewTuple = ( Community, Person, CommentAggregatesNotInComment, - Option, + Option, Option, Option, Option, @@ -113,7 +113,7 @@ fn queries<'a>() -> Queries< community::all_columns, aliases::person1.fields(person::all_columns), CommentAggregatesNotInComment::as_select(), - community_person_ban::all_columns.nullable(), + CommunityPersonBanAdditionalInfo::as_select().nullable(), community_follower::all_columns.nullable(), comment_saved::all_columns.nullable(), person_block::all_columns.nullable(), diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 08dc9c092..1b5145c02 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -49,7 +49,7 @@ type PersonMentionViewTuple = ( Community, Person, CommentAggregatesNotInComment, - Option, + Option, Option, Option, Option, @@ -109,7 +109,7 @@ fn queries<'a>() -> Queries< community::all_columns, aliases::person1.fields(person::all_columns), CommentAggregatesNotInComment::as_select(), - community_person_ban::all_columns.nullable(), + CommunityPersonBanAdditionalInfo::as_select().nullable(), community_follower::all_columns.nullable(), comment_saved::all_columns.nullable(), person_block::all_columns.nullable(),