diff --git a/src/main.rs b/src/main.rs index 09202ef..75be7fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,8 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_axum::Shut .route("/configuration", put(update_config)) // brewing events .route("/brewing-events", get(retrieve_brewing_events)) + // brewing events by id + .route("/brewing-events/:id", get(retrieve_brewing_events_by_tea_id)) // 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", put(update_tea_meta_by_id)) diff --git a/src/requests/get_requests.rs b/src/requests/get_requests.rs index 0107418..d21124c 100644 --- a/src/requests/get_requests.rs +++ b/src/requests/get_requests.rs @@ -62,6 +62,27 @@ pub async fn retrieve_brewing_events( } } +pub async fn retrieve_brewing_events_by_tea_id( + Path(id): Path, + State(state): State, +) -> Result { + match sqlx::query_as::<_, SteepingLog>( + " + SELECT * + FROM steepinglog + WHERE id = $1 + ORDER BY steeping_tested_time + ", + ) + .bind(id) + .fetch_all(&state.pool) + .await + { + Ok(steeping_log) => Ok((StatusCode::OK, Json(steeping_log))), + Err(e) => Err((StatusCode::BAD_REQUEST, e.to_string())), + } +} + // used by teavail-device pub async fn retrieve_tea_by_rfid( Path(rfid): Path,