use actix_web::web::Data;
use uuid::Uuid;
use crate::{
config::data::AppDataInner,
error::ServiceError,
model::dto::base_layer_images::{BaseLayerImageDto, UpdateBaseLayerImageDto},
model::entity::base_layer_images::BaseLayerImages,
};
pub async fn find(
app_data: &Data<AppDataInner>,
layer_id: Uuid,
) -> Result<Vec<BaseLayerImageDto>, ServiceError> {
let mut conn = app_data.pool.get().await?;
let result = BaseLayerImages::find(&mut conn, layer_id).await?;
Ok(result)
}
pub async fn create(
dto: BaseLayerImageDto,
app_data: &Data<AppDataInner>,
) -> Result<BaseLayerImageDto, ServiceError> {
let mut conn = app_data.pool.get().await?;
let result = BaseLayerImages::create(dto, &mut conn).await?;
Ok(result)
}
pub async fn update(
id: Uuid,
dto: UpdateBaseLayerImageDto,
app_data: &Data<AppDataInner>,
) -> Result<BaseLayerImageDto, ServiceError> {
let mut conn = app_data.pool.get().await?;
let result = BaseLayerImages::update(id, dto, &mut conn).await?;
Ok(result)
}
pub async fn delete_by_id(id: Uuid, app_data: &Data<AppDataInner>) -> Result<(), ServiceError> {
let mut conn = app_data.pool.get().await?;
let _ = BaseLayerImages::delete_by_id(id, &mut conn).await?;
Ok(())
}