use axum::{extract::State, http::StatusCode, response::{IntoResponse, Json}}; use serde::Deserialize; use crate::{AppState, routes::errors::RouteError}; #[derive(Deserialize)] pub struct CreateProblemRequest { title: String, description: String, } pub async fn create_problem( State(state): State, Json(request): Json ) -> Result { let Ok(problem) = state.database.insert_problem(&request.title, &request.description) else { return Err(RouteError::Internal("database action failed".into())); }; Ok((StatusCode::CREATED, Json(problem))) } pub async fn get_problems( State(state): State, ) -> Result { let Ok(problems) = state.database.fetch_problems() else { return Err(RouteError::Internal("database action failed".into())); }; Ok((StatusCode::CREATED, Json(problems))) }