backend/controller/
plants.rs1use actix_web::{
4 get,
5 web::{Path, Query},
6 HttpResponse, Result,
7};
8
9use crate::{
10 config::data::SharedPool,
11 model::dto::{PageParameters, PlantsSearchParameters},
12 service::plants,
13};
14
15#[utoipa::path(
22 context_path = "/api/plants",
23 params(
24 PlantsSearchParameters,
25 PageParameters,
26 ),
27 responses(
28 (status = 200, description = "Fetch or search for all plants", body = PagePlantsSummaryDto),
29 ),
30 security(
31 ("oauth2" = [])
32 )
33)]
34#[get("")]
35pub async fn find(
36 search_query: Query<PlantsSearchParameters>,
37 page_query: Query<PageParameters>,
38 pool: SharedPool,
39) -> Result<HttpResponse> {
40 let payload = plants::find(search_query.into_inner(), page_query.into_inner(), &pool).await?;
41 Ok(HttpResponse::Ok().json(payload))
42}
43
44#[utoipa::path(
49 context_path = "/api/plants",
50 responses(
51 (status = 200, description = "Fetch plant by id", body = PlantsSummaryDto)
52 ),
53 security(
54 ("oauth2" = [])
55 )
56)]
57#[get("/{id}")]
58pub async fn find_by_id(id: Path<i32>, pool: SharedPool) -> Result<HttpResponse> {
59 let response = plants::find_by_id(*id, &pool).await?;
60 Ok(HttpResponse::Ok().json(response))
61}