backend/controller/
plants.rsuse actix_web::{
get,
web::{Path, Query},
HttpResponse, Result,
};
use crate::{
config::data::SharedPool,
model::dto::{PageParameters, PlantsSearchParameters},
service::plants,
};
#[utoipa::path(
context_path = "/api/plants",
params(
PlantsSearchParameters,
PageParameters,
),
responses(
(status = 200, description = "Fetch or search for all plants", body = PagePlantsSummaryDto),
),
security(
("oauth2" = [])
)
)]
#[get("")]
pub async fn find(
search_query: Query<PlantsSearchParameters>,
page_query: Query<PageParameters>,
pool: SharedPool,
) -> Result<HttpResponse> {
let payload = plants::find(search_query.into_inner(), page_query.into_inner(), &pool).await?;
Ok(HttpResponse::Ok().json(payload))
}
#[utoipa::path(
context_path = "/api/plants",
responses(
(status = 200, description = "Fetch plant by id", body = PlantsSummaryDto)
),
security(
("oauth2" = [])
)
)]
#[get("/{id}")]
pub async fn find_by_id(id: Path<i32>, pool: SharedPool) -> Result<HttpResponse> {
let response = plants::find_by_id(*id, &pool).await?;
Ok(HttpResponse::Ok().json(response))
}