backend/model/dto/
layer_impl.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Contains the implementation of [`LayerDto`].

use crate::model::{
    dto::layers::{LayerDto, LayerRenameDto},
    entity::layers::{Layer, UpdateLayerName},
};

impl From<Layer> for LayerDto {
    fn from(layer: Layer) -> Self {
        Self {
            id: layer.id,
            map_id: layer.map_id,
            type_: layer.type_,
            name: layer.name,
            is_alternative: layer.is_alternative,
            order_index: layer.order_index,
            marked_deleted: layer.marked_deleted.is_some(),
        }
    }
}

impl From<(i32, LayerDto)> for Layer {
    fn from(tuple: (i32, LayerDto)) -> Self {
        let (map_id, dto) = tuple;
        Self {
            id: dto.id,
            map_id,
            type_: dto.type_,
            name: dto.name,
            is_alternative: dto.is_alternative,
            order_index: dto.order_index,
            // Cannot create a new layer that is marked deleted anyway.
            marked_deleted: None,
        }
    }
}

impl From<LayerRenameDto> for UpdateLayerName {
    fn from(dto: LayerRenameDto) -> Self {
        Self {
            id: dto.id,
            name: dto.name,
        }
    }
}