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 get_quest_category endpoint #143

Merged
merged 1 commit into from
Dec 1, 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ contract = "0x01b22f7a9d18754c994ae0ee9adb4628d414232e3ebd748c386ac286f86c3066"
[achievements.carbonable]
contract = "0x0541b5dd5fae206ceccaf4eeb0642e4c04d456c5bc296eab047c9414bdad4f09"

[quest_boost]
private_key = "xxxxxx"
update_interval = 600

[quizzes]

[quizzes.ekubo]
Expand Down
37 changes: 37 additions & 0 deletions src/endpoints/get_quest_category.rs
Original file line number Diff line number Diff line change
@@ -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<Arc<AppState>>,
Query(query): Query<GetQuestsQuery>,
) -> impl IntoResponse {
let collection = state
.db
.collection::<QuestCategoryDocument>("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()),
}
}
5 changes: 3 additions & 2 deletions src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -27,7 +27,6 @@ async fn main() {
.await
.unwrap();


let shared_state = Arc::new(models::AppState {
conf: conf.clone(),
provider: JsonRpcClient::new(HttpTransport::new(
Expand All @@ -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);
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 7 additions & 1 deletion src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ pub_struct!(Debug, Serialize, Deserialize; LeaderboardTable {
timestamp:f64,
});


pub_struct!(Debug, Serialize, Deserialize; BoostTable {
amount: i32,
token: String,
Expand Down Expand Up @@ -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,
});