use uuid::Uuid;
use crate::model::{
dto::shadings::{
NewShadingDto, ShadingDto, UpdateAddDateShadingDto, UpdateNotesShadingDto,
UpdateRemoveDateShadingDto, UpdateShadingDto, UpdateValuesShadingDto,
},
entity::shadings::{Shading, UpdateShading},
};
impl From<Shading> for ShadingDto {
fn from(entity: Shading) -> Self {
Self {
id: entity.id,
layer_id: entity.layer_id,
shade: entity.shade,
geometry: entity.geometry,
add_date: entity.add_date,
remove_date: entity.remove_date,
notes: entity.notes,
}
}
}
impl From<NewShadingDto> for Shading {
fn from(dto: NewShadingDto) -> Self {
Self {
id: dto.id.unwrap_or_else(Uuid::new_v4),
layer_id: dto.layer_id,
shade: dto.shade,
geometry: dto.geometry,
add_date: dto.add_date,
remove_date: None,
notes: String::new(),
}
}
}
impl From<UpdateShadingDto> for Vec<UpdateShading> {
fn from(dto: UpdateShadingDto) -> Self {
match dto {
UpdateShadingDto::Update(vec) => vec.into_iter().map(Into::into).collect(),
UpdateShadingDto::UpdateAddDate(vec) => vec.into_iter().map(Into::into).collect(),
UpdateShadingDto::UpdateRemoveDate(vec) => vec.into_iter().map(Into::into).collect(),
UpdateShadingDto::UpdateNotes(vec) => vec.into_iter().map(Into::into).collect(),
}
}
}
impl From<UpdateValuesShadingDto> for UpdateShading {
fn from(dto: UpdateValuesShadingDto) -> Self {
Self {
id: dto.id,
shade: dto.shade,
geometry: dto.geometry,
..Default::default()
}
}
}
impl From<UpdateAddDateShadingDto> for UpdateShading {
fn from(dto: UpdateAddDateShadingDto) -> Self {
Self {
id: dto.id,
add_date: Some(dto.add_date),
..Default::default()
}
}
}
impl From<UpdateRemoveDateShadingDto> for UpdateShading {
fn from(dto: UpdateRemoveDateShadingDto) -> Self {
Self {
id: dto.id,
remove_date: Some(dto.remove_date),
..Default::default()
}
}
}
impl From<UpdateNotesShadingDto> for UpdateShading {
fn from(dto: UpdateNotesShadingDto) -> Self {
Self {
id: dto.id,
notes: Some(dto.notes),
..Default::default()
}
}
}