From 2d9dd6e9a95091e61ca2d7978191b8301ea55f7d Mon Sep 17 00:00:00 2001 From: Franklin Date: Thu, 9 Mar 2023 18:07:19 -0400 Subject: [PATCH] Created all payloads --- Cargo.lock | 14 ++++++++++++ Cargo.toml | 2 +- src/domain/agent/mod.rs | 11 +++++++++ src/domain/contact_info/mod.rs | 4 ++-- src/domain/property/mod.rs | 14 ++++++++++++ src/dto/mod.rs | 3 ++- src/dto/payload/agent.rs | 36 +++++++++++++++++++++++++++++ src/dto/payload/location.rs | 28 +++++++++++++++++++++++ src/dto/payload/mod.rs | 3 +++ src/dto/payload/property.rs | 42 ++++++++++++++++++++++++++++++++++ src/dto/property/mod.rs | 6 +++-- 11 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 src/dto/payload/agent.rs create mode 100644 src/dto/payload/location.rs create mode 100644 src/dto/payload/mod.rs create mode 100644 src/dto/payload/property.rs diff --git a/Cargo.lock b/Cargo.lock index c391638..39dcf7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1292,7 +1292,21 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" dependencies = [ + "getrandom", + "rand", "serde", + "uuid-macro-internal", +] + +[[package]] +name = "uuid-macro-internal" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b300a878652a387d2a0de915bdae8f1a548f0c6d45e072fe2688794b656cc9" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 83840ea..5c43cb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" chrono = { version = "0.4.23", features = [ "serde" ] } chrono-tz = "0.8" serde = { version = "1.0", features = ["derive"] } -uuid = { version = "1.3.0", features = ["serde"] } +uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics", "serde"] } format_num = "0.1.0" sqlx = { version = "0.6.0", features = [ "runtime-tokio-rustls", "postgres", "chrono", "uuid" ] } bincode = "1.3.3" \ No newline at end of file diff --git a/src/domain/agent/mod.rs b/src/domain/agent/mod.rs index 4383b1c..991b2a9 100644 --- a/src/domain/agent/mod.rs +++ b/src/domain/agent/mod.rs @@ -12,4 +12,15 @@ pub struct Agent { pub time_created: DateTime, #[serde(rename = "lastUpdated")] pub last_updated: DateTime, +} + +impl Agent { + pub fn new_from_full_name(full_name: String) -> Self { + Self { + id: Uuid::new_v4(), + full_name, + time_created: Utc::now(), + last_updated: Utc::now(), + } + } } \ No newline at end of file diff --git a/src/domain/contact_info/mod.rs b/src/domain/contact_info/mod.rs index 6618e52..700fcb0 100644 --- a/src/domain/contact_info/mod.rs +++ b/src/domain/contact_info/mod.rs @@ -9,11 +9,11 @@ pub struct ContactInformation { pub agent_id: Uuid, #[serde(rename = "phoneNumber")] pub phone_number: String, - pub email: String, + pub email: Option, #[serde(rename = "profilePictureUrl")] pub profile_picture_url: Option, /// This is the message to be sent to this user on every platform. So for whatsapp /// it will be the wa.me link message that gets placed in the chat when a user clicks on the link. #[serde(rename = "defaultMessage")] - pub default_message: String, + pub default_message: Option, } \ No newline at end of file diff --git a/src/domain/property/mod.rs b/src/domain/property/mod.rs index dedde42..061708c 100644 --- a/src/domain/property/mod.rs +++ b/src/domain/property/mod.rs @@ -18,6 +18,20 @@ pub struct Property { pub last_updated: DateTime, } +impl Property { + pub fn new(title: String, description: String, agent_id: Uuid) -> Self { + Self { + id: Uuid::new_v4(), + title, + description, + agent_id, + state: ListingState::Draft, + time_created: Utc::now(), + last_updated: Utc::now(), + } + } +} + #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Default)] pub enum ListingState { #[default] diff --git a/src/dto/mod.rs b/src/dto/mod.rs index 6a6c0c3..aa7d191 100644 --- a/src/dto/mod.rs +++ b/src/dto/mod.rs @@ -1,2 +1,3 @@ pub mod property; -pub mod agent; \ No newline at end of file +pub mod agent; +pub mod payload; \ No newline at end of file diff --git a/src/dto/payload/agent.rs b/src/dto/payload/agent.rs new file mode 100644 index 0000000..22ad66b --- /dev/null +++ b/src/dto/payload/agent.rs @@ -0,0 +1,36 @@ +use serde::{Serialize, Deserialize}; + +use crate::domain::{agent::Agent, contact_info::ContactInformation}; + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd)] +pub struct AgentWithDetails { + agent: Agent, + contact_info: ContactInformation, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd)] +pub struct NewAgentPayload { + pub full_name: String, + pub phone_number: String, + + // Optional fields + pub email: Option, + pub profile_picture_url: Option, + pub default_message: Option, +} +impl From for AgentWithDetails { + fn from(value: NewAgentPayload) -> Self { + let agent = Agent::new_from_full_name(value.full_name); + let agent_id = agent.id.clone(); + Self { + agent, + contact_info: ContactInformation { + agent_id, + phone_number: value.phone_number, + email: value.email, + profile_picture_url: value.profile_picture_url, + default_message: value.default_message, + } + } + } +} diff --git a/src/dto/payload/location.rs b/src/dto/payload/location.rs new file mode 100644 index 0000000..360a643 --- /dev/null +++ b/src/dto/payload/location.rs @@ -0,0 +1,28 @@ +use serde::{Serialize, Deserialize}; +use uuid::Uuid; + +use crate::domain::location::Location; + + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd)] +pub struct NewLocationPayload { + pub country: String, + pub province: String, + pub city: String, + pub district: Option, + #[serde(rename = "googleMapsUrl")] + pub google_maps_url: Option, +} + +impl From for Location { + fn from(value: NewLocationPayload) -> Self { + Self { + id: Uuid::new_v4(), + country: value.country, + province: value.province, + city: value.city, + district: value.district, + google_maps_url: value.google_maps_url, + } + } +} \ No newline at end of file diff --git a/src/dto/payload/mod.rs b/src/dto/payload/mod.rs new file mode 100644 index 0000000..f29accd --- /dev/null +++ b/src/dto/payload/mod.rs @@ -0,0 +1,3 @@ +pub mod property; +pub mod location; +pub mod agent; \ No newline at end of file diff --git a/src/dto/payload/property.rs b/src/dto/payload/property.rs new file mode 100644 index 0000000..283d2d6 --- /dev/null +++ b/src/dto/payload/property.rs @@ -0,0 +1,42 @@ +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +use crate::domain::{property_details::{ListingType, Photos, PropertyDetails}, property::Property}; + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd)] +pub struct PropertyWithDetails { + property: Property, + details: PropertyDetails, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd)] +pub struct NewPropertyPayload { + #[serde(rename = "agentId")] + pub agent_id: Uuid, + pub title: String, + pub description: String, + pub meters: f32, + #[serde(rename = "listingType")] + pub listing_type: ListingType, + #[serde(rename = "photoUrls")] + pub photo_urls: Photos, + #[serde(rename = "locationId")] + pub location_id: Uuid, +} + +impl From for PropertyWithDetails { + fn from(value: NewPropertyPayload) -> Self { + let property = Property::new(value.title, value.description, value.agent_id); + let property_id = property.id.clone(); + Self { + property, + details: PropertyDetails { + property_id, + meters: value.meters, + listing_type: value.listing_type, + photo_urls: value.photo_urls, + location_id: value.location_id, + }, + } + } +} \ No newline at end of file diff --git a/src/dto/property/mod.rs b/src/dto/property/mod.rs index 8a09a22..3ebcf85 100644 --- a/src/dto/property/mod.rs +++ b/src/dto/property/mod.rs @@ -4,6 +4,7 @@ use crate::domain::{property::Property, property_details::PropertyDetails, locat use super::agent::AgentContainer; +/// This is the struct that the frontend will request when showing listings in list view. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd)] pub struct PropertyContainer { pub property: Property, @@ -11,8 +12,9 @@ pub struct PropertyContainer { pub location: Location, } +/// This is the struct that the frontend will request when a user clicks on a Listing. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd)] pub struct ListingContainer { - property: PropertyContainer, - agent: AgentContainer, + pub property: PropertyContainer, + pub agent: AgentContainer, } \ No newline at end of file