mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 01:38:44 +00:00
stats on list media for user handler
This commit is contained in:
1 parent
0fae1229b6
commit
e63f4e08bf
2 files changed
+30
No files matched your search
@@ -36,6 +36,10 @@ pub struct MediaFileListItem {
|
||||
|
||||
pub creator_set_visibility: Visibility,
|
||||
|
||||
pub maybe_ratings_positive_count: Option<u32>,
|
||||
pub maybe_ratings_negative_count: Option<u32>,
|
||||
pub maybe_bookmark_count: Option<u32>,
|
||||
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -98,6 +102,9 @@ pub async fn list_media_files_for_user(args: ListMediaFileForUserArgs<'_>) -> An
|
||||
maybe_public_bucket_prefix: record.maybe_public_bucket_prefix,
|
||||
maybe_public_bucket_extension: record.maybe_public_bucket_extension,
|
||||
creator_set_visibility: record.creator_set_visibility,
|
||||
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,
|
||||
created_at: record.created_at,
|
||||
updated_at: record.updated_at,
|
||||
}
|
||||
@@ -131,6 +138,11 @@ fn select_result_fields() -> String {
|
||||
m.maybe_public_bucket_extension,
|
||||
|
||||
m.creator_set_visibility,
|
||||
|
||||
entity_stats.ratings_positive_count as maybe_ratings_positive_count,
|
||||
entity_stats.ratings_negative_count as maybe_ratings_negative_count,
|
||||
entity_stats.bookmark_count as maybe_bookmark_count,
|
||||
|
||||
m.created_at,
|
||||
m.updated_at
|
||||
"#
|
||||
@@ -163,6 +175,9 @@ SELECT
|
||||
FROM media_files AS m
|
||||
LEFT OUTER JOIN users AS u
|
||||
ON m.maybe_creator_user_token = u.token
|
||||
LEFT OUTER JOIN entity_stats
|
||||
ON entity_stats.entity_type = "media_file"
|
||||
AND entity_stats.entity_token = m.token
|
||||
"#
|
||||
));
|
||||
|
||||
@@ -222,6 +237,10 @@ struct MediaFileListItemInternal {
|
||||
|
||||
creator_set_visibility: Visibility,
|
||||
|
||||
maybe_ratings_positive_count: Option<u32>,
|
||||
maybe_ratings_negative_count: Option<u32>,
|
||||
maybe_bookmark_count: Option<u32>,
|
||||
|
||||
created_at: DateTime<Utc>,
|
||||
updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -252,6 +271,9 @@ impl FromRow<'_, MySqlRow> for MediaFileListItemInternal {
|
||||
maybe_public_bucket_prefix: row.try_get("maybe_public_bucket_prefix")?,
|
||||
maybe_public_bucket_extension: row.try_get("maybe_public_bucket_extension")?,
|
||||
creator_set_visibility: Visibility::try_from_mysql_row(row, "creator_set_visibility")?,
|
||||
maybe_ratings_positive_count: row.try_get("maybe_ratings_positive_count")?,
|
||||
maybe_ratings_negative_count: row.try_get("maybe_ratings_negative_count")?,
|
||||
maybe_bookmark_count: row.try_get("maybe_bookmark_count")?,
|
||||
created_at: row.try_get("created_at")?,
|
||||
updated_at: row.try_get("updated_at")?,
|
||||
})
|
||||
|
||||
+8
@@ -19,6 +19,7 @@ use mysql_queries::queries::media_files::list::list_media_files_for_user::{list_
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
use crate::http_server::common_responses::pagination_page::PaginationPage;
|
||||
use crate::http_server::common_responses::simple_entity_stats::SimpleEntityStats;
|
||||
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
|
||||
use crate::server_state::ServerState;
|
||||
|
||||
@@ -58,6 +59,9 @@ pub struct MediaFileForUserListItem {
|
||||
|
||||
pub creator_set_visibility: Visibility,
|
||||
|
||||
/// Statistics about the media file
|
||||
pub stats: SimpleEntityStats,
|
||||
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -176,6 +180,10 @@ pub async fn list_media_files_for_user_handler(
|
||||
.get_full_object_path_str()
|
||||
.to_string(),
|
||||
creator_set_visibility: record.creator_set_visibility,
|
||||
stats: SimpleEntityStats {
|
||||
positive_rating_count: record.maybe_ratings_positive_count.unwrap_or(0),
|
||||
bookmark_count: record.maybe_bookmark_count.unwrap_or(0),
|
||||
},
|
||||
created_at: record.created_at,
|
||||
updated_at: record.updated_at,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user