first
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
use axum::{extract::Extension, http::StatusCode, Json};
|
||||
|
||||
use crate::{app_state::{AppState, SessionSnapshot, SessionStartRequest}, error::AppError};
|
||||
|
||||
pub async fn start(
|
||||
Extension(state): Extension<AppState>,
|
||||
Json(payload): Json<SessionStartRequest>,
|
||||
) -> Result<(StatusCode, Json<SessionSnapshot>), AppError> {
|
||||
let session = state.start_session(payload).await;
|
||||
Ok((StatusCode::CREATED, Json(session)))
|
||||
}
|
||||
|
||||
pub async fn end(Extension(state): Extension<AppState>) -> Result<Json<SessionSnapshot>, AppError> {
|
||||
let session = state.end_session().await?;
|
||||
Ok(Json(session))
|
||||
}
|
||||
|
||||
pub async fn me(Extension(state): Extension<AppState>) -> Result<Json<SessionSnapshot>, AppError> {
|
||||
let session = state
|
||||
.current_session()
|
||||
.await
|
||||
.ok_or_else(|| AppError::not_found("No active session"))?;
|
||||
Ok(Json(session))
|
||||
}
|
||||
Reference in New Issue
Block a user