Skip to content

Commit

Permalink
feat: enhance EncodableBot structure with new fields (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
chikof authored Nov 10, 2024
2 parents e614340 + 6f02e83 commit 1302e82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/controllers/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
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<Bot>) -> AppResult<Vec<EncodableBot>> {
Expand Down Expand Up @@ -50,8 +48,8 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
// 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,
})))
})
Expand Down
17 changes: 13 additions & 4 deletions src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,17 @@ pub struct OwnedBot {
pub struct EncodableBot {
pub id: String,
pub name: String,
pub avatar: Option<String>,
pub description: String,
pub short_description: String,
pub supported_languages: Vec<Option<BotLanguages>>,
pub categories: Option<Vec<String>>,
pub guild_count: i32,
pub status: String,
#[serde(with = "rfc3339")]
pub updated_at: NaiveDateTime,
pub categories: Option<Vec<String>>,
#[serde(with = "rfc3339")]
pub created_at: NaiveDateTime,
pub description: String,
pub short_description: String,
pub supported_languages: Vec<Option<BotLanguages>>,
}

impl EncodableBot {
Expand All @@ -185,6 +188,9 @@ impl EncodableBot {
description,
short_description,
supported_languages,
guild_count,
status,
avatar,
..
} = bot;

Expand All @@ -199,6 +205,9 @@ impl EncodableBot {
description,
short_description,
supported_languages,
guild_count,
status: status.into(),
avatar,
}
}

Expand Down

0 comments on commit 1302e82

Please sign in to comment.