From a70b94d7cb5e54556131f0db3a9802f11e82ca58 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 8 Aug 2024 16:20:42 -0400 Subject: [PATCH] add "is_featured" to get weight --- .../queries/model_weights/get/get_weight.rs | 21 +++++++++++++++++++ .../endpoints/weights/get_weight_handler.rs | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/lib/mysql_queries/src/queries/model_weights/get/get_weight.rs b/crates/lib/mysql_queries/src/queries/model_weights/get/get_weight.rs index ec21145669..66a1123887 100644 --- a/crates/lib/mysql_queries/src/queries/model_weights/get/get_weight.rs +++ b/crates/lib/mysql_queries/src/queries/model_weights/get/get_weight.rs @@ -10,6 +10,8 @@ use enums::common::visibility::Visibility; use errors::AnyhowResult; use tokens::tokens::{model_weights::ModelWeightToken, users::UserToken}; +use crate::helpers::boolean_converters::i64_to_bool; + // Notes ensure that Enums have sqlx::Type // 'weights_type: enums::by_table::model_weights::weights_types::WeightsType' use this to map // Retrieved Model Weight can be constrained to the fields that are needed @@ -49,6 +51,8 @@ pub struct RetrievedModelWeight { pub maybe_ratings_negative_count: Option, pub maybe_bookmark_count: Option, + pub is_featured: bool, + pub version: i32, pub created_at: DateTime, pub updated_at: DateTime, @@ -117,6 +121,7 @@ pub async fn get_weights_by_token_with_connection( maybe_ratings_positive_count: record.maybe_ratings_positive_count, maybe_ratings_negative_count: record.maybe_ratings_negative_count, maybe_bookmark_count: record.maybe_bookmark_count, + is_featured: i64_to_bool(record.is_featured), version: record.version, created_at: record.created_at, updated_at: record.updated_at, @@ -167,11 +172,14 @@ async fn select_include_deleted( entity_stats.ratings_negative_count as maybe_ratings_negative_count, entity_stats.bookmark_count as maybe_bookmark_count, + featured_items.entity_token IS NOT NULL AS is_featured, + wt.version, wt.created_at, wt.updated_at, wt.user_deleted_at, wt.mod_deleted_at + FROM model_weights as wt JOIN users ON users.token = wt.creator_user_token @@ -180,6 +188,10 @@ async fn select_include_deleted( LEFT OUTER JOIN entity_stats ON entity_stats.entity_type = "model_weight" AND entity_stats.entity_token = wt.token + LEFT OUTER JOIN featured_items + ON featured_items.entity_type = "model_weight" + AND featured_items.entity_token = wt.token + AND featured_items.deleted_at IS NULL WHERE wt.token = ? "#, @@ -230,11 +242,14 @@ async fn select_without_deleted( entity_stats.ratings_negative_count as maybe_ratings_negative_count, entity_stats.bookmark_count as maybe_bookmark_count, + featured_items.entity_token IS NOT NULL AS is_featured, + wt.version, wt.created_at, wt.updated_at, wt.user_deleted_at, wt.mod_deleted_at + FROM model_weights as wt JOIN users ON users.token = wt.creator_user_token @@ -243,6 +258,10 @@ async fn select_without_deleted( LEFT OUTER JOIN entity_stats ON entity_stats.entity_type = "model_weight" AND entity_stats.entity_token = wt.token + LEFT OUTER JOIN featured_items + ON featured_items.entity_type = "model_weight" + AND featured_items.entity_token = wt.token + AND featured_items.deleted_at IS NULL WHERE wt.token = ? AND wt.user_deleted_at IS NULL @@ -287,6 +306,8 @@ pub struct RawWeight { pub maybe_ratings_negative_count: Option, pub maybe_bookmark_count: Option, + pub is_featured: i64, + pub version: i32, pub created_at: DateTime, pub updated_at: DateTime, diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/get_weight_handler.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/get_weight_handler.rs index 8937d17719..0f33e678b9 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/weights/get_weight_handler.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/weights/get_weight_handler.rs @@ -50,6 +50,9 @@ pub struct GetWeightResponse { #[deprecated(note="switch to CoverImageDetails")] maybe_cover_image_public_bucket_path: Option, + /// Whether the weight is featured by staff (the featured_items API) or not. + is_featured: bool, + /// Statistics about the weights stats: SimpleEntityStats, @@ -196,13 +199,14 @@ pub async fn get_weight_handler( creator_set_visibility: weight.creator_set_visibility, file_size_bytes: weight.file_size_bytes, file_checksum_sha2: weight.file_checksum_sha2, + is_featured: weight.is_featured, stats: SimpleEntityStats { positive_rating_count: weight.maybe_ratings_positive_count.unwrap_or(0), bookmark_count: weight.maybe_bookmark_count.unwrap_or(0), }, version: weight.version, created_at: weight.created_at, - updated_at: weight.updated_at + updated_at: weight.updated_at, }; let body = serde_json::to_string(&response)