Skip to main content

koprogo_api/application/dto/
unit_dto.rs

1use crate::domain::entities::UnitType;
2use rust_decimal::Decimal;
3use serde::{Deserialize, Serialize};
4use validator::Validate;
5
6#[derive(Debug, Deserialize, Validate, Clone)]
7pub struct CreateUnitDto {
8    pub organization_id: String,
9    pub building_id: String,
10
11    #[validate(length(min = 1))]
12    pub unit_number: String,
13
14    pub unit_type: UnitType,
15    pub floor: Option<i32>,
16
17    #[validate(range(min = 0.1))]
18    pub surface_area: f64,
19
20    /// Quote-part en millièmes (Decimal exact, range 0.1..=1000 enforced en domain).
21    pub quota: Decimal,
22}
23
24#[derive(Debug, Deserialize, Validate, Clone)]
25pub struct UpdateUnitDto {
26    #[validate(length(min = 1))]
27    pub unit_number: String,
28
29    pub unit_type: UnitType,
30    pub floor: i32,
31
32    #[validate(range(min = 0.1))]
33    pub surface_area: f64,
34
35    /// Quote-part en millièmes (Decimal exact, range 0.1..=1000 enforced en domain).
36    pub quota: Decimal,
37}
38
39#[derive(Debug, Serialize)]
40pub struct UnitResponseDto {
41    pub id: String,
42    pub building_id: String,
43    pub unit_number: String,
44    pub unit_type: UnitType,
45    pub floor: Option<i32>,
46    pub surface_area: f64,
47    pub quota: Decimal,
48    pub owner_id: Option<String>,
49}