diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-11-28 16:30:02 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-11-28 16:30:02 +0100 |
| commit | a62ab5c6dacaddb67931d7ac160bc7faaa707737 (patch) | |
| tree | a35fa3540fbb89f575ab1ea72f9b23ace399e01c /crates/rocie-server/src/api/get/recipe.rs | |
| parent | chore(crates/rocie-client): Re-generate (diff) | |
| download | server-a62ab5c6dacaddb67931d7ac160bc7faaa707737.zip | |
feat(crates/rocie-server): Get closer to feature parity between rocie and grocy
Diffstat (limited to 'crates/rocie-server/src/api/get/recipe.rs')
| -rw-r--r-- | crates/rocie-server/src/api/get/recipe.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/crates/rocie-server/src/api/get/recipe.rs b/crates/rocie-server/src/api/get/recipe.rs new file mode 100644 index 0000000..70bab39 --- /dev/null +++ b/crates/rocie-server/src/api/get/recipe.rs @@ -0,0 +1,66 @@ +use actix_web::{HttpResponse, Responder, error::Result, get, web}; + +use crate::{ + app::App, + storage::sql::recipe::{Recipe, RecipeId, RecipeIdStub}, +}; + +/// Get an recipe by it's id. +#[utoipa::path( + responses( + ( + status = OK, + description = "Recipe found in database and fetched", + body = Recipe, + ), + ( + status = NOT_FOUND, + description = "Recipe not found in database" + ), + ( + status = INTERNAL_SERVER_ERROR, + description = "Server encountered error", + body = String + ) + ), + params( + ( + "id" = RecipeId, + description = "Recipe id" + ), + ) +)] +#[get("/recipe/by-id/{id}")] +pub(crate) async fn recipe_by_id( + app: web::Data<App>, + id: web::Path<RecipeIdStub>, +) -> Result<impl Responder> { + let id = id.into_inner(); + + match Recipe::from_id(&app, id.into()).await? { + Some(recipe) => Ok(HttpResponse::Ok().json(recipe)), + None => Ok(HttpResponse::NotFound().finish()), + } +} + +/// Get all added recipes +#[utoipa::path( + responses( + ( + status = OK, + description = "All recipes found in database and fetched", + body = Recipe, + ), + ( + status = INTERNAL_SERVER_ERROR, + description = "Server encountered error", + body = String + ) + ), +)] +#[get("/recipe/all")] +pub(crate) async fn recipes(app: web::Data<App>) -> Result<impl Responder> { + let all = Recipe::get_all(&app).await?; + + Ok(HttpResponse::Ok().json(all)) +} |
