-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from starknet-id/feat/add_category_metatgs
feat: add get_quest_category endpoint
- Loading branch information
Showing
6 changed files
with
58 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters