Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hide hidden quests and block disabled ones #52

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/endpoints/get_quest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pub async fn handler(
Query(query): Query<GetQuestsQuery>,
) -> impl IntoResponse {
let collection = state.db.collection::<QuestDocument>("quests");
match collection.find_one(doc! {"id": query.id}, None).await {
match collection
.find_one(doc! {"id": query.id, "disabled" : false}, None)
.await
{
Ok(Some(quest)) => (StatusCode::OK, Json(quest)).into_response(),
Ok(None) => get_error("Quest not found".to_string()),
Err(_) => get_error("Error querying quest".to_string()),
Expand Down
10 changes: 8 additions & 2 deletions src/endpoints/get_quests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ pub struct NFTItem {

pub async fn handler(State(state): State<Arc<AppState>>) -> impl IntoResponse {
let collection = state.db.collection::<QuestDocument>("quests");
match collection.find(None, None).await {
let filter = doc! {
"$and": [
{"disabled": false},
{"hidden": false}
]
};
match collection.find(Some(filter), None).await {
Ok(cursor) => {
let quests: Vec<QuestDocument> = cursor.try_collect().await.unwrap_or_else(|_| vec![]);
if quests.is_empty() {
Expand All @@ -29,6 +35,6 @@ pub async fn handler(State(state): State<Arc<AppState>>) -> impl IntoResponse {
(StatusCode::OK, Json(quests)).into_response()
}
}
Err(_) => get_error("Error querying quest".to_string()),
Err(_) => get_error("Error querying quests".to_string()),
}
}
10 changes: 10 additions & 0 deletions src/endpoints/get_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ pub async fn handler(
"as": "completed",
}
},
doc! {
"$lookup": {
"from": "quests",
"localField": "quest_id",
"foreignField": "id",
"as": "quest"
}
},
doc! { "$unwind": "$quest" },
doc! { "$match": { "quest.disabled": false } },
doc! {
"$project": {
"_id": 0,
Expand Down
3 changes: 2 additions & 1 deletion src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub_struct!(Debug, Serialize, Deserialize; QuestDocument {
rewards_nfts: Vec<NFTItem>,
img_card: String,
title_card: String,
finished: bool,
hidden: bool,
disabled: bool,
});

pub_struct!(Deserialize; CompletedTasks {
Expand Down