From 6f02e83533d1e4c08dc10d1afe9a5affbb65e97b Mon Sep 17 00:00:00 2001 From: Chiko Date: Sun, 10 Nov 2024 02:06:22 +0000 Subject: [PATCH] feat: enhance EncodableBot structure with new fields Add new fields to the EncodableBot struct, including avatar, description, short_description, supported_languages, categories, guild_count, and status. These changes improve the data representation of bots by providing more context and details. Refactor related code in the summary function to accommodate the updated structure and clean up unused variables. fixes #100 --- src/controllers/summary.rs | 6 ++---- src/views.rs | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/controllers/summary.rs b/src/controllers/summary.rs index 6a56102..2670051 100644 --- a/src/controllers/summary.rs +++ b/src/controllers/summary.rs @@ -21,8 +21,6 @@ pub async fn summary(state: AppState) -> AppResult> { spawn_blocking(move || { let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into(); - let config = &state.config; - let num_bots: i64 = bots::table.count().get_result(conn)?; fn encode_bots(bot_list: Vec) -> AppResult> { @@ -50,8 +48,8 @@ pub async fn summary(state: AppState) -> AppResult> { // TODO: top rated, most voted Ok(Json(json!({ "num_bots": num_bots, - "new_bots": encode_bots( new_bots)?, - "just_updated": encode_bots( just_updated)?, + "new_bots": encode_bots(new_bots)?, + "just_updated": encode_bots(just_updated)?, "popular_categories": popular_categories, }))) }) diff --git a/src/views.rs b/src/views.rs index 0ff8e29..add41f0 100644 --- a/src/views.rs +++ b/src/views.rs @@ -165,14 +165,17 @@ pub struct OwnedBot { pub struct EncodableBot { pub id: String, pub name: String, + pub avatar: Option, + pub description: String, + pub short_description: String, + pub supported_languages: Vec>, + pub categories: Option>, + pub guild_count: i32, + pub status: String, #[serde(with = "rfc3339")] pub updated_at: NaiveDateTime, - pub categories: Option>, #[serde(with = "rfc3339")] pub created_at: NaiveDateTime, - pub description: String, - pub short_description: String, - pub supported_languages: Vec>, } impl EncodableBot { @@ -185,6 +188,9 @@ impl EncodableBot { description, short_description, supported_languages, + guild_count, + status, + avatar, .. } = bot; @@ -199,6 +205,9 @@ impl EncodableBot { description, short_description, supported_languages, + guild_count, + status: status.into(), + avatar, } }