added all payloads except unit

This commit is contained in:
Franklin 2023-03-19 12:13:02 -04:00
parent 9a37e9c278
commit 82c582583a
7 changed files with 210 additions and 2 deletions

View File

@ -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<Utc>,
#[serde(rename = "lastUpdated")]
pub last_updated: DateTime<Utc>,
}
}

View File

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

58
src/dto/payloads/agent.rs Normal file
View File

@ -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<String>,
pub credential: Option<String>,
#[serde(rename = "credentialType")]
pub credential_type: Option<CredentialType>,
#[serde(rename = "profilePictureUrl")]
pub profile_picture_url: Option<String>,
}
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() }
}
}
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();
}
}

View File

@ -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<NewLocationPayload> for Location {
fn from(value: NewLocationPayload) -> Self {
Location { id: Uuid::new_v4(), city: value.city, district: value.district }
}
}

3
src/dto/payloads/mod.rs Normal file
View File

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

127
src/dto/payloads/project.rs Normal file
View File

@ -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<String>,
pub description: String,
#[serde(rename = "adminTag")]
pub admin_tag: Option<String>,
#[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<ProjectState>,
#[serde(rename = "projectType")]
pub project_type: Option<ProjectType>,
#[serde(rename = "projectCondition")]
pub project_condition: Option<ProjectCondition>,
#[serde(rename = "agentId")]
pub agent_id: Option<Uuid>,
#[serde(rename = "locationId")]
pub location_id: Option<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<Option<String>>,
pub description: Option<String>,
#[serde(rename = "adminTag")]
pub admin_tag: Option<Option<String>>,
#[serde(rename = "finishDate")]
pub finish_date: Option<NaiveDateTime>,
/// Amount of floors the building/house has
pub floors: Option<i16>,
pub media: Option<MediaList>,
}
impl From<NewProjectPayload> 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 => {},
};
}
}

0
src/dto/payloads/unit.rs Normal file
View File