mirror of
https://github.com/zzzzDev4/ias-tea-axum.git
synced 2025-04-21 07:41:21 +02:00
combined POST /tea-steeping-time/[id]
and POST /types-of-tea/[id]
This commit is contained in:
parent
88e152210d
commit
df8f7dd184
3 changed files with 6 additions and 31 deletions
|
@ -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)]
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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<MyState>,
|
||||
Path(id): Path<i32>,
|
||||
Json(steeping_time_change): Json<TeaSteepingTimeChange>,
|
||||
) -> Result<impl IntoResponse, impl IntoResponse> {
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue