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: add boosted quests query #171

Merged
merged 1 commit into from
Jan 8, 2024
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
40 changes: 40 additions & 0 deletions src/endpoints/get_boosted_quests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::{models::AppState, utils::get_error};
use axum::{
extract::{State},
response::IntoResponse,
Json,
};

use futures::TryStreamExt;
use mongodb::bson::{doc, Document};
use reqwest::StatusCode;
use std::sync::Arc;

pub async fn handler(
State(state): State<Arc<AppState>>,
) -> impl IntoResponse {
let pipeline = vec![
doc! {
"$unwind": doc! {
"path": "$quests"
}
},
doc! {
"$project": doc! {
"_id": 0,
"id": "$quests"
}
},
];
let tasks_collection = state.db.collection::<Document>("boosts");
match tasks_collection.aggregate(pipeline, None).await {
Ok(mut cursor) => {
let mut quests: Vec<u32> = Vec::new();
while let Some(result) = cursor.try_next().await.unwrap() {
quests.push(result.get("id").unwrap().as_i32().unwrap() as u32);
}
(StatusCode::OK, Json(quests)).into_response()
}
Err(_) => get_error("Error querying boosts".to_string()),
}
}
1 change: 1 addition & 0 deletions src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pub mod has_completed_quest;
pub mod leaderboard;
pub mod quest_boost;
pub mod quests;
pub mod get_boosted_quests;
2 changes: 1 addition & 1 deletion src/endpoints/quests/verify_quiz.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::sync::Arc;

use crate::{
common::verify_quiz::verify_quiz,
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ async fn main() {
"/get_completed_quests",
get(endpoints::get_completed_quests::handler),
)
.route(
"/get_boosted_quests",
get(endpoints::get_boosted_quests::handler),
)
.route(
"/has_completed_quests",
get(endpoints::has_completed_quest::handler),
Expand Down