handle adding drinks when no open shift exists
This commit is contained in:
parent
58fa1864d1
commit
a22cb3b306
1 changed files with 14 additions and 3 deletions
17
src/api.rs
17
src/api.rs
|
@ -2,9 +2,10 @@ use std::time::Duration;
|
|||
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
http::StatusCode,
|
||||
response::{
|
||||
sse::{Event, KeepAlive},
|
||||
IntoResponse, Sse,
|
||||
IntoResponse, Response, Sse,
|
||||
},
|
||||
routing::{get, post},
|
||||
Form,
|
||||
|
@ -99,7 +100,7 @@ async fn add_drink(
|
|||
State(state): State<AppState>,
|
||||
HxRequest(hx): HxRequest,
|
||||
Form(form): Form<DrinkForm>,
|
||||
) -> impl IntoResponse {
|
||||
) -> Response {
|
||||
let mut conn = state.connection.get().await.unwrap();
|
||||
|
||||
let open_shift: Option<Shift> = {
|
||||
|
@ -113,7 +114,16 @@ async fn add_drink(
|
|||
.optional()
|
||||
.expect("Query failed: No open shifts found")
|
||||
};
|
||||
let open_shift = open_shift.unwrap();
|
||||
|
||||
if open_shift.is_none() {
|
||||
return (
|
||||
StatusCode::CONFLICT,
|
||||
"Unable to to add a drink when no shift is open",
|
||||
)
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let open_shift = unsafe { open_shift.unwrap_unchecked() };
|
||||
|
||||
{
|
||||
use cm_lib::schema::drinks::dsl::*;
|
||||
|
@ -131,6 +141,7 @@ async fn add_drink(
|
|||
headers,
|
||||
render!(crate::templates::home_html, Some(open_shift), !hx),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
|
Loading…
Reference in a new issue