blob: 9b2eba313a288ae46e45cf687be2b2e0d9ec26c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
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<AppState>,
Json(request): Json<CreateProblemRequest>
) -> Result<impl IntoResponse, RouteError> {
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<AppState>,
) -> Result<impl IntoResponse, RouteError> {
let Ok(problems) = state.database.fetch_problems() else {
return Err(RouteError::Internal("database action failed".into()));
};
Ok((StatusCode::CREATED, Json(problems)))
}
|