From 0aaacdddaa09dc9f2e1db3af1dcdee6c789cfc14 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 8 Jan 2024 23:30:16 -0500 Subject: [PATCH] reusable type --- crates/service/web/storyteller_web/src/api_doc.rs | 3 ++- .../src/http_server/common_responses/mod.rs | 5 +++-- .../common_responses/simple_entity_stats.rs | 10 ++++++++++ .../list_user_bookmarks_for_user_handler.rs | 13 +++---------- 4 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 crates/service/web/storyteller_web/src/http_server/common_responses/simple_entity_stats.rs diff --git a/crates/service/web/storyteller_web/src/api_doc.rs b/crates/service/web/storyteller_web/src/api_doc.rs index 6e4b5f66ad..5096c96da6 100644 --- a/crates/service/web/storyteller_web/src/api_doc.rs +++ b/crates/service/web/storyteller_web/src/api_doc.rs @@ -18,6 +18,7 @@ use tokens::tokens::users::*; use crate::http_server::common_responses::media_file_social_meta_lite::MediaFileSocialMetaLight; use crate::http_server::common_responses::pagination_cursors::PaginationCursors; use crate::http_server::common_responses::pagination_page::PaginationPage; +use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats; use crate::http_server::common_responses::user_details_lite::{DefaultAvatarInfo, UserDetailsLight}; use crate::http_server::endpoints::media_files::get_media_file::*; use crate::http_server::endpoints::media_files::list_featured_media_files::*; @@ -87,6 +88,7 @@ use crate::http_server::web_utils::response_success_helpers::*; MediaFileSocialMetaLight, PaginationCursors, PaginationPage, + SimpleEntityStats, SimpleGenericJsonSuccess, UserDetailsLight, Visibility, @@ -105,7 +107,6 @@ use crate::http_server::web_utils::response_success_helpers::*; ListAvailableWeightsQuery,ListAvailableWeightsSuccessResponse,ModelWeightForList, ListWeightsByUserError,ListWeightsByUserSuccessResponse,ListWeightsByUserPathInfo,Weight, WeightsData,MediaFileData, - BookmarkListStats, BatchGetUserRatingQueryParams,BatchGetUserRatingResponse,BatchGetUserRatingError,RatingRow, BatchGetUserBookmarksQueryParams,BatchGetUserBookmarksResponse,BatchGetUserBookmarksError,BookmarkRow, ListFeaturedMediaFilesSuccessResponse,MediaFile, ListFeaturedMediaFilesError, diff --git a/crates/service/web/storyteller_web/src/http_server/common_responses/mod.rs b/crates/service/web/storyteller_web/src/http_server/common_responses/mod.rs index f22f30d692..6febed7bcc 100644 --- a/crates/service/web/storyteller_web/src/http_server/common_responses/mod.rs +++ b/crates/service/web/storyteller_web/src/http_server/common_responses/mod.rs @@ -1,4 +1,5 @@ +pub mod media_file_social_meta_lite; pub mod pagination_cursors; pub mod pagination_page; -pub mod user_details_lite; -pub mod media_file_social_meta_lite; \ No newline at end of file +pub mod simple_entity_stats; +pub mod user_details_lite; \ No newline at end of file diff --git a/crates/service/web/storyteller_web/src/http_server/common_responses/simple_entity_stats.rs b/crates/service/web/storyteller_web/src/http_server/common_responses/simple_entity_stats.rs new file mode 100644 index 0000000000..6b48ec13b3 --- /dev/null +++ b/crates/service/web/storyteller_web/src/http_server/common_responses/simple_entity_stats.rs @@ -0,0 +1,10 @@ +use utoipa::ToSchema; + +/// Simple stats that can be attached to any entity +#[derive(Serialize, ToSchema)] +pub struct SimpleEntityStats { + /// Number of positive ratings (or "likes") for this item + pub positive_rating_count: u32, + /// Number of bookmarks for this item + pub bookmark_count: u32, +} diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/user_bookmarks/list_user_bookmarks_for_user_handler.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/user_bookmarks/list_user_bookmarks_for_user_handler.rs index 88aba735a2..efa4bac0a1 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/user_bookmarks/list_user_bookmarks_for_user_handler.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/user_bookmarks/list_user_bookmarks_for_user_handler.rs @@ -23,6 +23,7 @@ use mysql_queries::queries::user_bookmarks::list_user_bookmarks::{list_user_book use tokens::tokens::user_bookmarks::UserBookmarkToken; use crate::http_server::common_responses::pagination_page::PaginationPage; +use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats; use crate::http_server::common_responses::user_details_lite::UserDetailsLight; use crate::http_server::web_utils::response_error_helpers::to_simple_json_error; use crate::server_state::ServerState; @@ -92,7 +93,7 @@ pub struct UserBookmarkDetailsForUserList { /// This is only populated if the item is a model weight. pub maybe_weight_data: Option, - pub stats: BookmarkListStats, + pub stats: SimpleEntityStats, } #[derive(Serialize, ToSchema)] @@ -122,14 +123,6 @@ pub struct WeightsData { pub maybe_creator: Option, } -#[derive(Serialize, ToSchema)] -pub struct BookmarkListStats { - /// Number of positive ratings (or "likes") for this item - pub positive_rating_count: u32, - /// Number of bookmarks for this item - pub bookmark_count: u32, -} - #[derive(Debug, ToSchema)] pub enum ListUserBookmarksForUserError { ServerError, @@ -272,7 +265,7 @@ pub async fn list_user_bookmarks_for_user_handler( // first-class system before handling the backfill here. maybe_thumbnail_url: None, - stats: BookmarkListStats { + stats: SimpleEntityStats { positive_rating_count: user_bookmark.maybe_ratings_positive_count.unwrap_or(0), bookmark_count: user_bookmark.maybe_bookmark_count.unwrap_or(0), },