1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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))
}
|