diff options
| author | Daniel Hader <[email protected]> | 2026-06-02 20:37:40 -0500 |
|---|---|---|
| committer | Daniel Hader <[email protected]> | 2026-06-02 20:37:40 -0500 |
| commit | 51fac3f3b6f73b649ba8109b37d8ff311b905cd4 (patch) | |
| tree | 4a2eb771842bf65ccb6e95c6c1d59ef65cbd2a7d /src/routes/problem.rs | |
| parent | 14a4d586b7c7abc86674724153757f15faf7262c (diff) | |
problem statement on submission page and submission logic tweaks
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)) + } +} |
