diff --git a/Cargo.toml b/Cargo.toml index 181ee42e..185562a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ futures = "0.3.28" reqwest = { version = "0.11.17", features = ["json"] } rand = "0.8.5" async-trait = "0.1.68" -percent-encoding = "2.3.0" +percent-encoding = "2.3.1" chrono = "0.4.19" lazy_static = "1.4.0" regex = "1.10.0" diff --git a/config.template.toml b/config.template.toml index 4d3137e1..9ab51400 100644 --- a/config.template.toml +++ b/config.template.toml @@ -61,6 +61,10 @@ contract = "0x01b22f7a9d18754c994ae0ee9adb4628d414232e3ebd748c386ac286f86c3066" [achievements.carbonable] contract = "0x0541b5dd5fae206ceccaf4eeb0642e4c04d456c5bc296eab047c9414bdad4f09" +[quest_boost] +private_key = "xxxxxx" +update_interval = 600 + [quizzes] [quizzes.ekubo] diff --git a/src/endpoints/get_quest_category.rs b/src/endpoints/get_quest_category.rs new file mode 100644 index 00000000..c140a85a --- /dev/null +++ b/src/endpoints/get_quest_category.rs @@ -0,0 +1,37 @@ +use crate::{ + models::{AppState, QuestCategoryDocument}, + utils::get_error, +}; +use axum::{ + extract::{Query, State}, + http::StatusCode, + response::{IntoResponse, Json}, +}; +use mongodb::bson::doc; +use serde::Deserialize; +use std::sync::Arc; + +#[derive(Deserialize)] +pub struct GetQuestsQuery { + name: String, +} + +pub async fn handler( + State(state): State>, + Query(query): Query, +) -> impl IntoResponse { + let collection = state + .db + .collection::("quest_categories"); + let filter = doc! { + "name": &query.name + }; + + match collection.find_one(filter, None).await { + Ok(option) => match option { + Some(category) => (StatusCode::OK, Json(category)).into_response(), + None => get_error("Category not found".to_string()), + }, + Err(_) => get_error("Error querying quest category data".to_string()), + } +} diff --git a/src/endpoints/mod.rs b/src/endpoints/mod.rs index dc271acb..c49b38f6 100644 --- a/src/endpoints/mod.rs +++ b/src/endpoints/mod.rs @@ -2,12 +2,13 @@ pub mod achievements; pub mod get_completed_quests; pub mod get_deployed_time; pub mod get_quest; +pub mod get_quest_category; pub mod get_quest_participants; pub mod get_quests; pub mod get_quiz; pub mod get_tasks; pub mod get_trending_quests; -pub mod quests; +pub mod has_completed_quest; pub mod leaderboard; pub mod quest_boost; -pub mod has_completed_quest; +pub mod quests; diff --git a/src/main.rs b/src/main.rs index cb3dde7f..0836963d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,8 @@ use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient}; use std::net::SocketAddr; use std::sync::Arc; +use crate::utils::{add_leaderboard_table, run_boosts_raffle}; use tower_http::cors::{Any, CorsLayer}; -use crate::utils::{ add_leaderboard_table, run_boosts_raffle}; #[tokio::main] async fn main() { @@ -27,7 +27,6 @@ async fn main() { .await .unwrap(); - let shared_state = Arc::new(models::AppState { conf: conf.clone(), provider: JsonRpcClient::new(HttpTransport::new( @@ -50,7 +49,7 @@ async fn main() { } let db_instance = shared_state.db.clone(); - run_boosts_raffle(&db_instance,conf.quest_boost.update_interval); + run_boosts_raffle(&db_instance, conf.quest_boost.update_interval); add_leaderboard_table(&shared_state.db).await; let cors = CorsLayer::new().allow_headers(Any).allow_origin(Any); @@ -85,6 +84,10 @@ async fn main() { "/get_deployed_time", get(endpoints::get_deployed_time::handler), ) + .route( + "/get_quest_category", + get(endpoints::get_quest_category::handler), + ) .route( "/quests/verify_quiz", post(endpoints::quests::verify_quiz::handler), diff --git a/src/models.rs b/src/models.rs index 57c2b736..92cd08ae 100644 --- a/src/models.rs +++ b/src/models.rs @@ -147,7 +147,6 @@ pub_struct!(Debug, Serialize, Deserialize; LeaderboardTable { timestamp:f64, }); - pub_struct!(Debug, Serialize, Deserialize; BoostTable { amount: i32, token: String, @@ -223,3 +222,10 @@ pub_struct!(Deserialize, Serialize, Debug; UserAchievementCategory { completed: bool, verify_type: String, }); + +pub_struct!(Debug, Serialize, Deserialize; QuestCategoryDocument { + name: String, + title: String, + desc: String, + img_url: String, +});