From 30dc7571ca8983fe77359e0e7003bc2e6dfd251a Mon Sep 17 00:00:00 2001 From: zzzz Date: Tue, 11 Jun 2024 22:31:07 +0200 Subject: [PATCH] general improvements and bugfixes, endpoints tested and working --- migrations/0001_init.sql | 6 +++--- src/data.rs | 2 -- src/requests/get_requests.rs | 2 +- src/requests/post_requests.rs | 11 ++++------- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/migrations/0001_init.sql b/migrations/0001_init.sql index 1916798..9185bd7 100644 --- a/migrations/0001_init.sql +++ b/migrations/0001_init.sql @@ -1,9 +1,9 @@ CREATE TABLE IF NOT EXISTS tea ( id serial PRIMARY KEY, - tea_name VARCHAR(128) NOT NULL, + tea_name VARCHAR(128) NOT NULL DEFAULT 'Unnamed Tea', rfid_code VARCHAR(128) NOT NULL, - tea_notes VARCHAR(512), - water_temp INT, + tea_notes VARCHAR(512) NOT NULL DEFAULT '', + water_temp INT NOT NULL DEFAULT -1, steeping_seconds INT NOT NULL, registration_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); diff --git a/src/data.rs b/src/data.rs index 55330f0..33dd726 100644 --- a/src/data.rs +++ b/src/data.rs @@ -22,9 +22,7 @@ pub struct TeaSteepingTimeChange { #[derive(Deserialize)] pub struct TeaNew { - pub tea_name: String, pub rfid_code: String, - pub water_temp: i32, pub steeping_seconds: i32, } diff --git a/src/requests/get_requests.rs b/src/requests/get_requests.rs index 05c99bc..0107418 100644 --- a/src/requests/get_requests.rs +++ b/src/requests/get_requests.rs @@ -86,7 +86,7 @@ pub async fn delete_tea_by_id( match sqlx::query_as::<_, Tea>( " DELETE FROM tea WHERE id = $1 - RETURNING id, teaname, rfidcode, tea_notes, water_temp, steeping_seconds, registration_timestamp + RETURNING id, tea_name, rfid_code, tea_notes, water_temp, steeping_seconds, registration_timestamp ", ) .bind(id) diff --git a/src/requests/post_requests.rs b/src/requests/post_requests.rs index 6e9c523..1ad7a3a 100644 --- a/src/requests/post_requests.rs +++ b/src/requests/post_requests.rs @@ -27,7 +27,6 @@ pub async fn update_config( } } -// TODO: should be used by web-interface to update metadata pub async fn update_tea_meta_by_id( State(state): State, Path(id): Path, @@ -63,7 +62,7 @@ pub async fn update_tea_steeping_time_by_id( " UPDATE tea SET steeping_seconds = $1 WHERE id = $2 - RETURNING id, tea_name, rfid_code, water_temp, steeping_seconds + RETURNING id, tea_name, rfid_code, tea_notes, water_temp, steeping_seconds, registration_timestamp ", ) .bind(steeping_time_change.new_steeping_seconds) @@ -99,14 +98,12 @@ pub async fn add_tea( ) -> Result { match sqlx::query_as::<_, Tea>( " - INSERT INTO tea (tea_name, rfid_code, water_temp, steeping_seconds) - VALUES ($1, $2, $3, $4) - RETURNING id, tea_name, rfid_code, water_temp, steeping_seconds + INSERT INTO tea (rfid_code, steeping_seconds) + VALUES ($1, $2) + RETURNING id, tea_name, rfid_code, tea_notes, water_temp, steeping_seconds, registration_timestamp ", ) - .bind(&tea_new.tea_name) .bind(&tea_new.rfid_code) - .bind(tea_new.water_temp) .bind(tea_new.steeping_seconds) .fetch_one(&state.pool) .await