25 lines
850 B
Rust
25 lines
850 B
Rust
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))
|
|
}
|