Skip to content

Commit

Permalink
feat: order achievements categories based on ids
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Oct 24, 2023
1 parent e13726b commit 08ba19e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/endpoints/achievements/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub async fn handler(
doc! {
"$project": {
"_id": 0,
"category_id": "$id",
"category_name": "$name",
"category_desc": "$desc",
"category_img_url": "$img_url",
Expand Down Expand Up @@ -82,12 +83,13 @@ pub async fn handler(
},
doc! {
"$group": {
"_id": { "category_name": "$category_name", "category_desc": "$category_desc", "category_img_url": "$category_img_url", "category_type": "$category_type" },
"_id": { "category_id": "$category_id", "category_name": "$category_name", "category_desc": "$category_desc", "category_img_url": "$category_img_url", "category_type": "$category_type" },
"achievements": { "$push": "$achievements" }
}
},
doc! {
"$project": {
"category_id": "$_id.category_id",
"category_name": "$_id.category_name",
"category_desc": "$_id.category_desc",
"category_img_url": "$_id.category_img_url",
Expand All @@ -111,6 +113,7 @@ pub async fn handler(
_ => continue,
}
}
achievements.sort_by(|a, b| a.category_id.cmp(&b.category_id));
(StatusCode::OK, Json(achievements)).into_response()
}
Err(e) => get_error(format!("Error fetching user achievements: {}", e)),
Expand Down
1 change: 1 addition & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub_struct!(Debug, Serialize, Deserialize; AchievementCategoryDocument {
});

pub_struct!(Debug, Serialize, Deserialize; UserAchievements {
category_id: u32,
category_name: String,
category_desc: String,
category_img_url: String,
Expand Down

0 comments on commit 08ba19e

Please sign in to comment.