diff --git a/src/endpoints/admin/quest_boost/get_boost_winners.rs b/src/endpoints/admin/quest_boost/get_boost_winners.rs new file mode 100644 index 0000000..812f49b --- /dev/null +++ b/src/endpoints/admin/quest_boost/get_boost_winners.rs @@ -0,0 +1,37 @@ +use crate::middleware::auth::auth_middleware; +use crate::models::{AppState, BoostTable}; +use crate::utils::get_error; +use axum::{ + extract::{Query, State, Extension}, + response::IntoResponse, + Json, +}; +use axum_auto_routes::route; +use mongodb::bson::doc; +use serde::Deserialize; +use std::sync::Arc; +use serde_json::json; + +#[derive(Deserialize)] +pub struct GetBoostWinnersParams { + boost_id: i64, +} + +#[route(get, "/admin/boosts/get_boost_winners", auth_middleware)] +pub async fn get_boost_winners_handler( + State(state): State>, + Extension(_sub): Extension, + Query(params): Query, +) -> impl IntoResponse { + let collection = state.db.collection::("boosts"); + + let filter = doc! { "id": params.boost_id }; + + match collection.find_one(filter, None).await { + Ok(Some(boost_doc)) => { + Json(json!({ "winners": boost_doc.winner })).into_response() + }, + Ok(None) => get_error(format!("Boost with id {} not found", params.boost_id)), + Err(e) => get_error(format!("Error fetching boost winners: {}", e)), + } +} \ No newline at end of file diff --git a/src/endpoints/admin/quest_boost/mod.rs b/src/endpoints/admin/quest_boost/mod.rs index da8d6c4..8daed52 100644 --- a/src/endpoints/admin/quest_boost/mod.rs +++ b/src/endpoints/admin/quest_boost/mod.rs @@ -1,3 +1,4 @@ pub mod create_boost; +pub mod get_boost_winners; pub mod get_quest_users; -pub mod update_boost; +pub mod update_boost; \ No newline at end of file