diff --git a/src/domain/agent.rs b/src/domain/agent.rs index b5a8b65..838c243 100644 --- a/src/domain/agent.rs +++ b/src/domain/agent.rs @@ -13,9 +13,10 @@ pub struct Agent { pub credential: String, #[serde(rename = "credentialType")] pub credential_type: CredentialType, - + #[serde(rename = "profilePictureUrl")] + pub profile_picture_url: String, #[serde(rename = "timeCreated")] 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 2589ce3..bed6fcf 100644 --- a/src/dto/mod.rs +++ b/src/dto/mod.rs @@ -1 +1,2 @@ pub mod filters; +pub mod payloads; \ No newline at end of file diff --git a/src/dto/payloads/agent.rs b/src/dto/payloads/agent.rs new file mode 100644 index 0000000..c65dd71 --- /dev/null +++ b/src/dto/payloads/agent.rs @@ -0,0 +1,58 @@ +use chrono::{Utc}; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +use crate::domain::{credential::CredentialType, agent::Agent}; + + + +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct NewAgentPayload { + #[serde(rename = "fullName")] + pub full_name: String, + pub credential: String, + #[serde(rename = "credentialType")] + pub credential_type: CredentialType, + #[serde(rename = "profilePictureUrl")] + pub profile_picture_url: String, +} + +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct UpdateAgentPayload { + pub id: Uuid, + #[serde(rename = "fullName")] + pub full_name: Option, + pub credential: Option, + #[serde(rename = "credentialType")] + pub credential_type: Option, + #[serde(rename = "profilePictureUrl")] + pub profile_picture_url: Option, +} + +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() } + } +} + +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 => {}, + }; + match self.credential { + Some(credential) => persisted_agent.credential = credential, + None => {}, + }; + match self.credential_type { + Some(credential_type) => persisted_agent.credential_type = credential_type, + None => {}, + }; + match self.profile_picture_url { + Some(profile_picture_url) => persisted_agent.profile_picture_url = profile_picture_url, + 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 new file mode 100644 index 0000000..f1fe86f --- /dev/null +++ b/src/dto/payloads/location.rs @@ -0,0 +1,18 @@ +use serde::{Serialize, Deserialize}; +use uuid::Uuid; + +use crate::domain::location::Location; + + + +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct NewLocationPayload { + pub city: String, + pub district: String, +} + +impl From for Location { + fn from(value: NewLocationPayload) -> Self { + 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 new file mode 100644 index 0000000..fbd0aa1 --- /dev/null +++ b/src/dto/payloads/mod.rs @@ -0,0 +1,3 @@ +pub mod agent; +pub mod project; +pub mod location; \ No newline at end of file diff --git a/src/dto/payloads/project.rs b/src/dto/payloads/project.rs new file mode 100644 index 0000000..997e8c2 --- /dev/null +++ b/src/dto/payloads/project.rs @@ -0,0 +1,127 @@ +use chrono::{NaiveDateTime, Utc}; +use serde::{Serialize, Deserialize}; +use uuid::Uuid; + +use crate::domain::{project::Project, project_state::ProjectState, project_type::ProjectType, project_condition::ProjectCondition, media::MediaList}; + + + +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct NewProjectPayload { + #[serde(rename = "projectState")] + pub project_state: ProjectState, + #[serde(rename = "projectType")] + pub project_type: ProjectType, + #[serde(rename = "projectCondition")] + pub project_condition: ProjectCondition, + #[serde(rename = "agentId")] + pub agent_id: Uuid, + #[serde(rename = "locationId")] + pub location_id: Uuid, + /// Title is optional as the agent can choose not to put the title there (in that case the title will be generated in the frontend) + pub title: Option, + pub description: String, + #[serde(rename = "adminTag")] + pub admin_tag: Option, + #[serde(rename = "finishDate")] + pub finish_date: NaiveDateTime, + /// Amount of floors the building/house has + pub floors: i16, + pub media: MediaList, +} + +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] + +pub struct UpdateProjectPayload { + #[serde(rename = "projectState")] + pub project_state: Option, + #[serde(rename = "projectType")] + pub project_type: Option, + #[serde(rename = "projectCondition")] + pub project_condition: Option, + #[serde(rename = "agentId")] + pub agent_id: Option, + #[serde(rename = "locationId")] + pub location_id: Option, + /// Title is optional as the agent can choose not to put the title there (in that case the title will be generated in the frontend) + pub title: Option>, + pub description: Option, + #[serde(rename = "adminTag")] + pub admin_tag: Option>, + #[serde(rename = "finishDate")] + pub finish_date: Option, + /// Amount of floors the building/house has + pub floors: Option, + pub media: Option, +} + +impl From for Project { + fn from(value: NewProjectPayload) -> Self { + Self { + id: Uuid::new_v4(), + project_state: value.project_state, + project_type: value.project_type, + project_condition: value.project_condition, + agent_id: value.agent_id, + location_id: value.location_id, + title: value.title, + description: value.description, + admin_tag: value.admin_tag, + finish_date: value.finish_date, + floors: value.floors, + media: value.media, + time_created: Utc::now(), + last_updated: Utc::now(), + } + } +} + +impl UpdateProjectPayload { + pub fn update_project(self, project: &mut Project) { + match self.project_state { + Some(project_state) => project.project_state = project_state, + None => {}, + }; + match self.project_type { + Some(project_type) => project.project_type = project_type, + None => {}, + }; + match self.project_condition { + Some(project_condition) => project.project_condition = project_condition, + None => {}, + }; + match self.agent_id { + Some(agent_id) => project.agent_id = agent_id, + None => {}, + }; + match self.location_id { + Some(location_id) => project.location_id = location_id, + None => {}, + }; + match self.title { + Some(title) => project.title = title, + None => {}, + }; + match self.description { + Some(description) => project.description = description, + None => {}, + }; + match self.admin_tag { + Some(admin_tag) => project.admin_tag = admin_tag, + None => {}, + }; + match self.finish_date { + Some(finish_date) => project.finish_date = finish_date, + None => {}, + }; + match self.floors { + Some(floors) => project.floors = floors, + None => {}, + }; + match self.media { + Some(media) => project.media = media, + None => {}, + }; + } +} + diff --git a/src/dto/payloads/unit.rs b/src/dto/payloads/unit.rs new file mode 100644 index 0000000..e69de29