diff options
Diffstat (limited to 'src/routes/problem.rs')
| -rw-r--r-- | src/routes/problem.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/routes/problem.rs b/src/routes/problem.rs index 9b2eba3..69d1b66 100644 --- a/src/routes/problem.rs +++ b/src/routes/problem.rs @@ -1,4 +1,4 @@ -use axum::{extract::State, http::StatusCode, response::{IntoResponse, Json}}; +use axum::{extract::{Path, State}, http::StatusCode, response::{IntoResponse, Json}}; use serde::Deserialize; use crate::{AppState, routes::errors::RouteError}; @@ -31,3 +31,14 @@ pub async fn get_problems( Ok((StatusCode::CREATED, Json(problems))) } + +pub async fn get_problem( + State(state): State<AppState>, + Path(problem_id): Path<i64>, +) -> Result<impl IntoResponse, RouteError> { + match state.database.fetch_problem(problem_id) { + Err(_) => Err(RouteError::Internal("database action failed".into())), + Ok(None) => Err(RouteError::NotFound("problem".into())), + Ok(Some(problem)) => Ok(Json(problem)) + } +} |
