Created all payloads
This commit is contained in:
parent
54a576e853
commit
2d9dd6e9a9
|
@ -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]]
|
||||
|
|
|
@ -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"
|
|
@ -12,4 +12,15 @@ pub struct Agent {
|
|||
pub time_created: DateTime<Utc>,
|
||||
#[serde(rename = "lastUpdated")]
|
||||
pub last_updated: DateTime<Utc>,
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,11 +9,11 @@ pub struct ContactInformation {
|
|||
pub agent_id: Uuid,
|
||||
#[serde(rename = "phoneNumber")]
|
||||
pub phone_number: String,
|
||||
pub email: String,
|
||||
pub email: Option<String>,
|
||||
#[serde(rename = "profilePictureUrl")]
|
||||
pub profile_picture_url: Option<String>,
|
||||
/// 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<String>,
|
||||
}
|
|
@ -18,6 +18,20 @@ pub struct Property {
|
|||
pub last_updated: DateTime<Utc>,
|
||||
}
|
||||
|
||||
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]
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
pub mod property;
|
||||
pub mod agent;
|
||||
pub mod agent;
|
||||
pub mod payload;
|
|
@ -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<String>,
|
||||
pub profile_picture_url: Option<String>,
|
||||
pub default_message: Option<String>,
|
||||
}
|
||||
impl From<NewAgentPayload> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<String>,
|
||||
#[serde(rename = "googleMapsUrl")]
|
||||
pub google_maps_url: Option<String>,
|
||||
}
|
||||
|
||||
impl From<NewLocationPayload> 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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
pub mod property;
|
||||
pub mod location;
|
||||
pub mod agent;
|
|
@ -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<NewPropertyPayload> 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
}
|
Loading…
Reference in New Issue