backend/service/
drawings.rs1use uuid::Uuid;
4
5use crate::config::data::SharedPool;
6use crate::error::ServiceError;
7use crate::model::dto::drawings::{DrawingDto, UpdateDrawingsDto};
8use crate::model::entity::drawings::Drawing;
9
10pub async fn find(map_id: i32, pool: &SharedPool) -> Result<Vec<DrawingDto>, ServiceError> {
15 let mut conn = pool.get().await?;
16 let results = Drawing::find(map_id, &mut conn).await?;
17 results.into_iter().map(TryFrom::try_from).collect()
18}
19
20pub async fn create(
25 dtos: Vec<DrawingDto>,
26 pool: &SharedPool,
27) -> Result<Vec<DrawingDto>, ServiceError> {
28 let mut conn = pool.get().await?;
29 let drawing_updates = dtos
30 .into_iter()
31 .map(Drawing::try_from)
32 .collect::<Result<Vec<Drawing>, ServiceError>>()?;
33 let result = Drawing::create(drawing_updates, &mut conn).await?;
34 result.into_iter().map(TryFrom::try_from).collect()
35}
36
37pub async fn update(
42 dto: UpdateDrawingsDto,
43 pool: &SharedPool,
44) -> Result<Vec<DrawingDto>, ServiceError> {
45 let mut conn = pool.get().await?;
46 let result = Drawing::update(dto.try_into()?, &mut conn).await?;
47 result.into_iter().map(TryFrom::try_from).collect()
48}
49
50pub async fn delete_by_ids(ids: Vec<Uuid>, pool: &SharedPool) -> Result<(), ServiceError> {
55 let mut conn = pool.get().await?;
56 let _ = Drawing::delete_by_ids(ids, &mut conn).await?;
57 Ok(())
58}