use crate::{
config::data::SharedPool,
error::ServiceError,
model::{
dto::{Page, PageParameters, PlantsSearchParameters, PlantsSummaryDto},
entity::Plants,
},
};
pub async fn find(
search_parameters: PlantsSearchParameters,
page_parameters: PageParameters,
pool: &SharedPool,
) -> Result<Page<PlantsSummaryDto>, ServiceError> {
let mut conn = pool.get().await?;
let result = match &search_parameters.name {
Some(query) if !query.is_empty() => {
Plants::search(query, page_parameters, &mut conn).await?
}
_ => Plants::find_any(page_parameters, &mut conn).await?,
};
Ok(result)
}
pub async fn find_by_id(id: i32, pool: &SharedPool) -> Result<PlantsSummaryDto, ServiceError> {
let mut conn = pool.get().await?;
let result = Plants::find_by_id(id, &mut conn).await?;
Ok(result)
}