4
0
Fork 0
mirror of https://github.com/zzzzDev4/ias-tea-axum.git synced 2025-04-21 07:41:21 +02:00

general improvements and bugfixes, endpoints tested and working

This commit is contained in:
zzzz 2024-06-11 22:31:07 +02:00
parent 2c60c6c4dc
commit 30dc7571ca
4 changed files with 8 additions and 13 deletions

View file

@ -1,9 +1,9 @@
CREATE TABLE IF NOT EXISTS tea ( CREATE TABLE IF NOT EXISTS tea (
id serial PRIMARY KEY, 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, rfid_code VARCHAR(128) NOT NULL,
tea_notes VARCHAR(512), tea_notes VARCHAR(512) NOT NULL DEFAULT '',
water_temp INT, water_temp INT NOT NULL DEFAULT -1,
steeping_seconds INT NOT NULL, steeping_seconds INT NOT NULL,
registration_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP registration_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
); );

View file

@ -22,9 +22,7 @@ pub struct TeaSteepingTimeChange {
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct TeaNew { pub struct TeaNew {
pub tea_name: String,
pub rfid_code: String, pub rfid_code: String,
pub water_temp: i32,
pub steeping_seconds: i32, pub steeping_seconds: i32,
} }

View file

@ -86,7 +86,7 @@ pub async fn delete_tea_by_id(
match sqlx::query_as::<_, Tea>( match sqlx::query_as::<_, Tea>(
" "
DELETE FROM tea WHERE id = $1 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) .bind(id)

View file

@ -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( pub async fn update_tea_meta_by_id(
State(state): State<MyState>, State(state): State<MyState>,
Path(id): Path<i32>, Path(id): Path<i32>,
@ -63,7 +62,7 @@ pub async fn update_tea_steeping_time_by_id(
" "
UPDATE tea SET steeping_seconds = $1 UPDATE tea SET steeping_seconds = $1
WHERE id = $2 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) .bind(steeping_time_change.new_steeping_seconds)
@ -99,14 +98,12 @@ pub async fn add_tea(
) -> Result<impl IntoResponse, impl IntoResponse> { ) -> Result<impl IntoResponse, impl IntoResponse> {
match sqlx::query_as::<_, Tea>( match sqlx::query_as::<_, Tea>(
" "
INSERT INTO tea (tea_name, rfid_code, water_temp, steeping_seconds) INSERT INTO tea (rfid_code, steeping_seconds)
VALUES ($1, $2, $3, $4) VALUES ($1, $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(&tea_new.tea_name)
.bind(&tea_new.rfid_code) .bind(&tea_new.rfid_code)
.bind(tea_new.water_temp)
.bind(tea_new.steeping_seconds) .bind(tea_new.steeping_seconds)
.fetch_one(&state.pool) .fetch_one(&state.pool)
.await .await