finished adding payload dtos

This commit is contained in:
Franklin 2023-03-19 15:41:20 -04:00
parent 82c582583a
commit 8802b94bcb
7 changed files with 144 additions and 35 deletions

View File

@ -19,4 +19,4 @@ pub struct Agent {
pub time_created: DateTime<Utc>,
#[serde(rename = "lastUpdated")]
pub last_updated: DateTime<Utc>,
}
}

View File

@ -1,2 +1,2 @@
pub mod filters;
pub mod payloads;
pub mod payloads;

View File

@ -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<NewAgentPayload> 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();
}
}
}

View File

@ -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<NewLocationPayload> 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,
}
}
}
}

View File

@ -1,3 +1,4 @@
pub mod agent;
pub mod location;
pub mod project;
pub mod location;
pub mod unit;

View File

@ -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<ProjectState>,
#[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 => {}
};
}
}

View File

@ -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<String>,
}
#[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<f64>,
#[serde(rename = "unitType")]
pub unit_type: Option<UnitType>,
/// Amount of rooms in unit
pub rooms: Option<i16>,
/// Amount of bathrooms in unit
pub bathrooms: Option<i16>,
/// In meters squared
pub area: Option<f32>,
pub description: Option<String>,
pub media: Option<MediaList>,
pub admin_tag: Option<Option<String>>,
}
impl From<NewUnitPayload> 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();
}
}