Include saved date in api responses (fixes #5184) (#5384)

* Include saved date in api responses (fixes #5184)

* ts optional attr
This commit is contained in:
Nutomic 2025-02-04 15:14:37 +00:00 committed by GitHub
parent 9daf70d8d9
commit e31823171c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 24 additions and 21 deletions

View file

@ -312,7 +312,7 @@ impl PersonContentCombinedQuery {
post_aggregates::comments.nullable() - post_actions::read_comments_amount.nullable(),
post_aggregates::comments,
),
post_actions::saved.nullable().is_not_null(),
post_actions::saved.nullable(),
post_actions::read.nullable().is_not_null(),
post_actions::hidden.nullable().is_not_null(),
post_actions::like_score.nullable(),
@ -321,7 +321,7 @@ impl PersonContentCombinedQuery {
// Comment-specific
comment::all_columns.nullable(),
comment_aggregates::all_columns.nullable(),
comment_actions::saved.nullable().is_not_null(),
comment_actions::saved.nullable(),
comment_actions::like_score.nullable(),
// Shared
post::all_columns,

View file

@ -109,7 +109,7 @@ impl PersonSavedCombinedQuery {
post_aggregates::comments.nullable() - post_actions::read_comments_amount.nullable(),
post_aggregates::comments,
),
post_actions::saved.nullable().is_not_null(),
post_actions::saved.nullable(),
post_actions::read.nullable().is_not_null(),
post_actions::hidden.nullable().is_not_null(),
post_actions::like_score.nullable(),
@ -118,7 +118,7 @@ impl PersonSavedCombinedQuery {
// Comment-specific
comment::all_columns.nullable(),
comment_aggregates::all_columns.nullable(),
comment_actions::saved.nullable().is_not_null(),
comment_actions::saved.nullable(),
comment_actions::like_score.nullable(),
// Shared
post::all_columns,

View file

@ -255,7 +255,7 @@ impl SearchCombinedQuery {
post_aggregates::comments,
)
.nullable(),
post_actions::saved.nullable().is_not_null(),
post_actions::saved.nullable(),
post_actions::read.nullable().is_not_null(),
post_actions::hidden.nullable().is_not_null(),
post_actions::like_score.nullable(),
@ -264,7 +264,7 @@ impl SearchCombinedQuery {
// Comment-specific
comment::all_columns.nullable(),
comment_aggregates::all_columns.nullable(),
comment_actions::saved.nullable().is_not_null(),
comment_actions::saved.nullable(),
comment_actions::like_score.nullable(),
// Community-specific
community::all_columns.nullable(),

View file

@ -135,7 +135,7 @@ impl CommentView {
creator_is_moderator: self.creator_is_moderator,
creator_is_admin: self.creator_is_admin,
subscribed: self.subscribed,
saved: self.saved,
saved: self.saved.is_some(),
creator_blocked: self.creator_blocked,
my_vote: self.my_vote,
}
@ -894,7 +894,7 @@ mod tests {
creator_is_admin: true,
my_vote: None,
subscribed: SubscribedType::NotSubscribed,
saved: false,
saved: None,
creator_blocked: false,
comment: Comment {
id: data.inserted_comment_0.id,

View file

@ -164,7 +164,7 @@ impl PostView {
Self::creator_is_admin(),
post_aggregates::all_columns,
CommunityFollower::select_subscribed_type(),
post_actions::saved.nullable().is_not_null(),
post_actions::saved.nullable(),
post_actions::read.nullable().is_not_null(),
post_actions::hidden.nullable().is_not_null(),
person_actions::blocked.nullable().is_not_null(),
@ -411,7 +411,7 @@ impl<'a> PostQuery<'a> {
PostView::creator_is_admin(),
post_aggregates::all_columns,
CommunityFollower::select_subscribed_type(),
post_actions::saved.nullable().is_not_null(),
post_actions::saved.nullable(),
post_actions::read.nullable().is_not_null(),
post_actions::hidden.nullable().is_not_null(),
person_actions::blocked.nullable().is_not_null(),
@ -1917,7 +1917,7 @@ mod tests {
subscribed: SubscribedType::NotSubscribed,
read: false,
hidden: false,
saved: false,
saved: None,
creator_blocked: false,
tags: PostTags::default(),
})

View file

@ -1,3 +1,4 @@
use chrono::{DateTime, Utc};
#[cfg(feature = "full")]
use diesel::{
deserialize::FromSqlRow,
@ -174,13 +175,14 @@ pub struct CommentView {
)
)]
pub subscribed: SubscribedType,
#[cfg_attr(feature = "full", ts(optional))]
#[cfg_attr(feature = "full",
diesel(
select_expression =
comment_actions::saved.nullable().is_not_null()
comment_actions::saved.nullable()
)
)]
pub saved: bool,
pub saved: Option<DateTime<Utc>>,
#[cfg_attr(feature = "full",
diesel(
select_expression =
@ -324,7 +326,8 @@ pub struct PostView {
pub creator_is_admin: bool,
pub counts: PostAggregates,
pub subscribed: SubscribedType,
pub saved: bool,
#[cfg_attr(feature = "full", ts(optional))]
pub saved: Option<DateTime<Utc>>,
pub read: bool,
pub hidden: bool,
pub creator_blocked: bool,
@ -477,11 +480,11 @@ pub enum ReportCombinedView {
#[cfg_attr(feature = "full", derive(Queryable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
/// A combined person_content view
pub struct PersonContentCombinedViewInternal {
pub(crate) struct PersonContentCombinedViewInternal {
// Post-specific
pub post_counts: PostAggregates,
pub post_unread_comments: i64,
pub post_saved: bool,
pub post_saved: Option<DateTime<Utc>>,
pub post_read: bool,
pub post_hidden: bool,
pub my_post_vote: Option<i16>,
@ -490,7 +493,7 @@ pub struct PersonContentCombinedViewInternal {
// Comment-specific
pub comment: Option<Comment>,
pub comment_counts: Option<CommentAggregates>,
pub comment_saved: bool,
pub comment_saved: Option<DateTime<Utc>>,
pub my_comment_vote: Option<i16>,
// Shared
pub post: Post,
@ -1026,7 +1029,7 @@ pub struct ModlogCombinedPaginationCursor(pub String);
#[cfg_attr(feature = "full", derive(Queryable, Selectable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
/// A combined modlog view
pub struct ModlogCombinedViewInternal {
pub(crate) struct ModlogCombinedViewInternal {
// Specific
#[cfg_attr(feature = "full", diesel(embed))]
pub admin_allow_instance: Option<AdminAllowInstance>,
@ -1120,12 +1123,12 @@ pub struct SearchCombinedPaginationCursor(pub String);
#[cfg_attr(feature = "full", derive(Queryable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
/// A combined search view
pub struct SearchCombinedViewInternal {
pub(crate) struct SearchCombinedViewInternal {
// Post-specific
pub post: Option<Post>,
pub post_counts: Option<PostAggregates>,
pub post_unread_comments: Option<i64>,
pub post_saved: bool,
pub post_saved: Option<DateTime<Utc>>,
pub post_read: bool,
pub post_hidden: bool,
pub my_post_vote: Option<i16>,
@ -1134,7 +1137,7 @@ pub struct SearchCombinedViewInternal {
// // Comment-specific
pub comment: Option<Comment>,
pub comment_counts: Option<CommentAggregates>,
pub comment_saved: bool,
pub comment_saved: Option<DateTime<Utc>>,
pub my_comment_vote: Option<i16>,
// // Community-specific
pub community: Option<Community>,