Skip to content

Commit

Permalink
Merge pull request #108 from starknet-id/feat/disable_achievements
Browse files Browse the repository at this point in the history
feat: enable/disable achievements
  • Loading branch information
Th0rgal authored Oct 25, 2023
2 parents 66c0f95 + 65efbee commit f573cac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/endpoints/achievements/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub async fn handler(
"category_desc": "$desc",
"category_img_url": "$img_url",
"category_type": "$type",
"category_disabled": "$disabled",
"achievements": {
"id": "$achievement.id",
"name": "$achievement.name",
Expand All @@ -82,7 +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_name": "$category_name",
"category_desc": "$category_desc",
"category_img_url": "$category_img_url",
"category_type": "$category_type",
"category_disabled": "$category_disabled",
},
"achievements": { "$push": "$achievements" }
}
},
Expand All @@ -92,6 +99,7 @@ pub async fn handler(
"category_desc": "$_id.category_desc",
"category_img_url": "$_id.category_img_url",
"category_type": "$_id.category_type",
"category_disabled": "$_id.category_disabled",
"achievements": 1,
"_id": 0
}
Expand All @@ -105,7 +113,9 @@ pub async fn handler(
match result {
Ok(document) => {
if let Ok(achievement) = from_document::<UserAchievements>(document) {
achievements.push(achievement);
if !achievement.category_disabled {
achievements.push(achievement);
}
}
}
_ => continue,
Expand Down
11 changes: 9 additions & 2 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,20 @@ pub_struct!(Debug, Serialize, Deserialize; AchievementCategoryDocument {
img_url: String,
});

pub_struct!(Debug, Serialize, Deserialize; UserAchievements {
#[derive(Debug, Serialize, Deserialize)]
pub struct UserAchievements {
category_name: String,
category_desc: String,
category_img_url: String,
category_type: String,
#[serde(default = "default_category_disabled")]
pub category_disabled: bool,
achievements: Vec<UserAchievement>,
});
}

pub fn default_category_disabled() -> bool {
false
}

pub_struct!(Debug, Serialize, Deserialize; UserAchievement {
id: u32,
Expand Down

0 comments on commit f573cac

Please sign in to comment.