backend/service/
base_layer_images.rs

1//! Service layer for images on the base layer.
2
3use uuid::Uuid;
4
5use crate::{
6    config::data::SharedPool,
7    error::ServiceError,
8    model::dto::base_layer_images::{BaseLayerImageDto, UpdateBaseLayerImageDto},
9    model::entity::base_layer_images::BaseLayerImages,
10};
11
12/// Fetch all base layer images for the layer from the database.
13///
14/// # Errors
15/// If the connection to the database could not be established.
16pub async fn find(
17    pool: &SharedPool,
18    layer_id: Uuid,
19) -> Result<Vec<BaseLayerImageDto>, ServiceError> {
20    let mut conn = pool.get().await?;
21    let result = BaseLayerImages::find(&mut conn, layer_id).await?;
22    Ok(result)
23}
24
25/// Create a base layer image in the database.
26///
27/// # Errors
28/// If the connection to the database could not be established.
29pub async fn create(
30    dto: BaseLayerImageDto,
31    pool: &SharedPool,
32) -> Result<BaseLayerImageDto, ServiceError> {
33    let mut conn = pool.get().await?;
34    let result = BaseLayerImages::create(dto, &mut conn).await?;
35    Ok(result)
36}
37
38/// Update the base layer image in the database.
39///
40/// # Errors
41/// If the connection to the database could not be established.
42pub async fn update(
43    id: Uuid,
44    dto: UpdateBaseLayerImageDto,
45    pool: &SharedPool,
46) -> Result<BaseLayerImageDto, ServiceError> {
47    let mut conn = pool.get().await?;
48    let result = BaseLayerImages::update(id, dto, &mut conn).await?;
49    Ok(result)
50}
51
52/// Delete the base layer image from the database.
53///
54/// # Errors
55/// If the connection to the database could not be established.
56pub async fn delete_by_id(id: Uuid, pool: &SharedPool) -> Result<(), ServiceError> {
57    let mut conn = pool.get().await?;
58    let _ = BaseLayerImages::delete_by_id(id, &mut conn).await?;
59    Ok(())
60}