mirror of
https://github.com/zzzzDev4/ias-tea-axum.git
synced 2025-04-21 07:41:21 +02:00
add update route WIP
This commit is contained in:
parent
075ab0c3be
commit
6f45b88108
1 changed files with 19 additions and 0 deletions
19
src/main.rs
19
src/main.rs
|
@ -56,6 +56,24 @@ async fn retrieve_all(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn update(
|
||||||
|
State(state): State<MyState>,
|
||||||
|
Json(data): Json<TeaNew>,
|
||||||
|
) -> Result<impl IntoResponse, impl IntoResponse> {
|
||||||
|
println!("update");
|
||||||
|
match sqlx::query_as::<_, Tea>("UPDATE tea SET teaname = $1, watertemp = $2, steepingseconds = $3 WHERE rfidcode = $4 RETURNING id, teaname, rfidcode, watertemp, steepingseconds")
|
||||||
|
.bind(&data.teaname)
|
||||||
|
.bind(&data.watertemp)
|
||||||
|
.bind(&data.steepingseconds)
|
||||||
|
.bind(&data.rfidcode)
|
||||||
|
.fetch_one(&state.pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(tea) => Ok((StatusCode::OK, Json(tea))),
|
||||||
|
Err(e) => Err((StatusCode::BAD_REQUEST, e.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn add(
|
async fn add(
|
||||||
State(state): State<MyState>,
|
State(state): State<MyState>,
|
||||||
Json(data): Json<TeaNew>,
|
Json(data): Json<TeaNew>,
|
||||||
|
@ -90,6 +108,7 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_axum::Shut
|
||||||
let router = Router::new()
|
let router = Router::new()
|
||||||
.nest_service("/", ServeFile::new("assets/index.html"))
|
.nest_service("/", ServeFile::new("assets/index.html"))
|
||||||
.route("/addtea", post(add))
|
.route("/addtea", post(add))
|
||||||
|
.route("/updatetea", post(update))
|
||||||
.route("/tea/:id", get(retrieve))
|
.route("/tea/:id", get(retrieve))
|
||||||
.route("/teabyrfid/:rfid", get(retrieve_by_rfid))
|
.route("/teabyrfid/:rfid", get(retrieve_by_rfid))
|
||||||
.route("/alltea", get(retrieve_all))
|
.route("/alltea", get(retrieve_all))
|
||||||
|
|
Loading…
Add table
Reference in a new issue