diff --git a/src/data.rs b/src/data.rs index 33dd726..d48aef9 100644 --- a/src/data.rs +++ b/src/data.rs @@ -13,6 +13,7 @@ pub struct TeaMeta { pub tea_name: String, pub tea_notes: String, pub water_temp: i32, + pub steeping_seconds: i32, } #[derive(Deserialize)] diff --git a/src/main.rs b/src/main.rs index 90cf5b1..df3b449 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_axum::Shut .route("/configuration", post(update_config)) // brewing events .route("/brewing-events", get(retrieve_brewing_events)) - // types of tea + // types of tea (update tea metadata, no log entry for steeping time) .route("/types-of-tea", get(retrieve_types_of_tea)) .route("/types-of-tea/:id", post(update_tea_meta_by_id)) .route("/types-of-tea/:id", get(retrieve_tea_by_id)) @@ -39,11 +39,6 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_axum::Shut "/tea-steeping-time-log/:id", post(update_tea_steeping_time_log_by_id), ) - // update target steeping time for next use (no log entry) - .route( - "/tea-steeping-time/:id", - post(update_tea_steeping_time_by_id), - ) // teavail-device .route("/tea-by-rfid/:rfid", get(retrieve_tea_by_rfid)) .route("/add-tea", post(add_tea)) diff --git a/src/requests/post_requests.rs b/src/requests/post_requests.rs index 7c053c9..f1e644e 100644 --- a/src/requests/post_requests.rs +++ b/src/requests/post_requests.rs @@ -35,36 +35,15 @@ pub async fn update_tea_meta_by_id( match sqlx::query_as::<_, Tea>( " UPDATE tea - SET tea_name = $1, water_temp = $2, tea_notes = $3 - WHERE id = $4 + SET tea_name = $1, tea_notes = $2, water_temp = $3, steeping_seconds = $4 + WHERE id = $5 RETURNING id, tea_name, rfid_code, tea_notes, water_temp, steeping_seconds, registration_timestamp ", ) .bind(&tea_meta.tea_name) + .bind(tea_meta.tea_notes) .bind(tea_meta.water_temp) - .bind(&tea_meta.tea_notes) - .bind(id) - .fetch_one(&state.pool) - .await - { - Ok(tea) => Ok((StatusCode::OK, Json(tea))), - Err(e) => Err((StatusCode::BAD_REQUEST, e.to_string())), - } -} - -pub async fn update_tea_steeping_time_by_id( - State(state): State, - Path(id): Path, - Json(steeping_time_change): Json, -) -> Result { - match sqlx::query_as::<_, Tea>( - " - UPDATE tea SET steeping_seconds = $1 - WHERE id = $2 - RETURNING id, tea_name, rfid_code, tea_notes, water_temp, steeping_seconds, registration_timestamp - ", - ) - .bind(steeping_time_change.new_steeping_seconds) + .bind(tea_meta.steeping_seconds) .bind(id) .fetch_one(&state.pool) .await