diff --git a/src/domain/agent.rs b/src/domain/agent.rs index 838c243..5ce3304 100644 --- a/src/domain/agent.rs +++ b/src/domain/agent.rs @@ -19,4 +19,4 @@ pub struct Agent { pub time_created: DateTime, #[serde(rename = "lastUpdated")] pub last_updated: DateTime, -} \ No newline at end of file +} diff --git a/src/dto/mod.rs b/src/dto/mod.rs index bed6fcf..943d4c4 100644 --- a/src/dto/mod.rs +++ b/src/dto/mod.rs @@ -1,2 +1,2 @@ pub mod filters; -pub mod payloads; \ No newline at end of file +pub mod payloads; diff --git a/src/dto/payloads/agent.rs b/src/dto/payloads/agent.rs index c65dd71..ac153e4 100644 --- a/src/dto/payloads/agent.rs +++ b/src/dto/payloads/agent.rs @@ -1,10 +1,8 @@ -use chrono::{Utc}; +use chrono::Utc; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::domain::{credential::CredentialType, agent::Agent}; - - +use crate::domain::{agent::Agent, credential::CredentialType}; #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct NewAgentPayload { @@ -31,7 +29,15 @@ pub struct UpdateAgentPayload { impl From for Agent { fn from(value: NewAgentPayload) -> Self { - Agent { id: Uuid::new_v4(), full_name: value.full_name, credential: value.credential, credential_type: value.credential_type, profile_picture_url: value.profile_picture_url, time_created: Utc::now(), last_updated: Utc::now() } + Agent { + id: Uuid::new_v4(), + full_name: value.full_name, + credential: value.credential, + credential_type: value.credential_type, + profile_picture_url: value.profile_picture_url, + time_created: Utc::now(), + last_updated: Utc::now(), + } } } @@ -39,20 +45,20 @@ impl UpdateAgentPayload { pub fn update_agent(self, persisted_agent: &mut Agent) { match self.full_name { Some(full_name) => persisted_agent.full_name = full_name, - None => {}, + None => {} }; match self.credential { Some(credential) => persisted_agent.credential = credential, - None => {}, + None => {} }; match self.credential_type { Some(credential_type) => persisted_agent.credential_type = credential_type, - None => {}, + None => {} }; match self.profile_picture_url { Some(profile_picture_url) => persisted_agent.profile_picture_url = profile_picture_url, - None => {}, + None => {} }; persisted_agent.last_updated = Utc::now(); } -} \ No newline at end of file +} diff --git a/src/dto/payloads/location.rs b/src/dto/payloads/location.rs index f1fe86f..f1a386b 100644 --- a/src/dto/payloads/location.rs +++ b/src/dto/payloads/location.rs @@ -1,10 +1,8 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use uuid::Uuid; use crate::domain::location::Location; - - #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct NewLocationPayload { pub city: String, @@ -13,6 +11,10 @@ pub struct NewLocationPayload { impl From for Location { fn from(value: NewLocationPayload) -> Self { - Location { id: Uuid::new_v4(), city: value.city, district: value.district } + Location { + id: Uuid::new_v4(), + city: value.city, + district: value.district, + } } -} \ No newline at end of file +} diff --git a/src/dto/payloads/mod.rs b/src/dto/payloads/mod.rs index fbd0aa1..404583c 100644 --- a/src/dto/payloads/mod.rs +++ b/src/dto/payloads/mod.rs @@ -1,3 +1,4 @@ pub mod agent; +pub mod location; pub mod project; -pub mod location; \ No newline at end of file +pub mod unit; diff --git a/src/dto/payloads/project.rs b/src/dto/payloads/project.rs index 997e8c2..5fc4b05 100644 --- a/src/dto/payloads/project.rs +++ b/src/dto/payloads/project.rs @@ -1,10 +1,11 @@ use chrono::{NaiveDateTime, Utc}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::domain::{project::Project, project_state::ProjectState, project_type::ProjectType, project_condition::ProjectCondition, media::MediaList}; - - +use crate::domain::{ + media::MediaList, project::Project, project_condition::ProjectCondition, + project_state::ProjectState, project_type::ProjectType, +}; #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct NewProjectPayload { @@ -31,8 +32,8 @@ pub struct NewProjectPayload { } #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] - pub struct UpdateProjectPayload { + pub id: Uuid, #[serde(rename = "projectState")] pub project_state: Option, #[serde(rename = "projectType")] @@ -80,48 +81,47 @@ impl UpdateProjectPayload { pub fn update_project(self, project: &mut Project) { match self.project_state { Some(project_state) => project.project_state = project_state, - None => {}, + None => {} }; match self.project_type { Some(project_type) => project.project_type = project_type, - None => {}, + None => {} }; match self.project_condition { Some(project_condition) => project.project_condition = project_condition, - None => {}, + None => {} }; match self.agent_id { Some(agent_id) => project.agent_id = agent_id, - None => {}, + None => {} }; match self.location_id { Some(location_id) => project.location_id = location_id, - None => {}, + None => {} }; match self.title { Some(title) => project.title = title, - None => {}, + None => {} }; match self.description { Some(description) => project.description = description, - None => {}, + None => {} }; match self.admin_tag { Some(admin_tag) => project.admin_tag = admin_tag, - None => {}, + None => {} }; match self.finish_date { Some(finish_date) => project.finish_date = finish_date, - None => {}, + None => {} }; match self.floors { Some(floors) => project.floors = floors, - None => {}, + None => {} }; match self.media { Some(media) => project.media = media, - None => {}, + None => {} }; } } - diff --git a/src/dto/payloads/unit.rs b/src/dto/payloads/unit.rs index e69de29..8a3f56d 100644 --- a/src/dto/payloads/unit.rs +++ b/src/dto/payloads/unit.rs @@ -0,0 +1,100 @@ +use chrono::Utc; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +use crate::domain::{media::MediaList, unit::Unit, unit_type::UnitType}; + +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, PartialOrd)] +pub struct NewUnitPayload { + #[serde(rename = "projectId")] + pub project_id: Uuid, + /// Let the client convert from usd to whatever currency + #[serde(rename = "priceUsd")] + pub price_usd: f64, + #[serde(rename = "unitType")] + pub unit_type: UnitType, + /// Amount of rooms in unit + pub rooms: i16, + /// Amount of bathrooms in unit + pub bathrooms: i16, + /// In meters squared + pub area: f32, + pub description: String, + pub media: MediaList, + pub admin_tag: Option, +} + +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, PartialOrd)] +pub struct UpdateUnitPayload { + /// Let the client convert from usd to whatever currency + #[serde(rename = "priceUsd")] + pub price_usd: Option, + #[serde(rename = "unitType")] + pub unit_type: Option, + /// Amount of rooms in unit + pub rooms: Option, + /// Amount of bathrooms in unit + pub bathrooms: Option, + /// In meters squared + pub area: Option, + pub description: Option, + pub media: Option, + pub admin_tag: Option>, +} + +impl From for Unit { + fn from(value: NewUnitPayload) -> Self { + Self { + id: Uuid::new_v4(), + project_id: value.project_id, + price_usd: value.price_usd, + unit_type: value.unit_type, + rooms: value.rooms, + bathrooms: value.bathrooms, + area: value.area, + description: value.description, + media: value.media, + admin_tag: value.admin_tag, + time_created: Utc::now(), + last_updated: Utc::now(), + } + } +} + +impl UpdateUnitPayload { + pub fn update_unit(self, unit: &mut Unit) { + match self.price_usd { + Some(price_usd) => unit.price_usd = price_usd, + None => {} + }; + match self.unit_type { + Some(unit_type) => unit.unit_type = unit_type, + None => {} + }; + match self.rooms { + Some(rooms) => unit.rooms = rooms, + None => {} + }; + match self.bathrooms { + Some(bathrooms) => unit.bathrooms = bathrooms, + None => {} + }; + match self.area { + Some(area) => unit.area = area, + None => {} + }; + match self.description { + Some(description) => unit.description = description, + None => {} + }; + match self.media { + Some(media) => unit.media = media, + None => {} + }; + match self.admin_tag { + Some(admin_tag) => unit.admin_tag = admin_tag, + None => {} + }; + unit.last_updated = Utc::now(); + } +}