Added projectcarddto

This commit is contained in:
Franklin 2023-03-24 08:39:01 -04:00
parent 8802b94bcb
commit 6cdfba8805
6 changed files with 57 additions and 0 deletions

View File

@ -28,6 +28,8 @@ impl FromStr for ProjectCondition {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Nuevo" => Ok(Self::New),
"Reventa" => Ok(Self::Resale),
_ => Err(Error::Parsing),
}
}

View File

@ -11,3 +11,15 @@ pub enum Filter {
ByProjectType(ProjectType),
ByProjectCondition(ProjectCondition),
}
impl Filter {
pub fn to_param(self) -> (String, String) {
match self {
Filter::InCity(city) => (String::from("incity"), city),
Filter::InDistrict(district) => (String::from("indistrict"), district),
Filter::Finished => (String::from("finished"), String::from("a")),
Filter::ByProjectType(project_type) => (String::from("byprojecttype"), project_type.to_string()),
Filter::ByProjectCondition(project_condition) => (String::from("byprojectcondition"), project_condition.to_string()),
}
}
}

18
src/dto/listing.rs Normal file
View File

@ -0,0 +1,18 @@
use serde::{Deserialize, Serialize};
use crate::domain::{project::Project, unit::Unit, location::Location, agent::Agent};
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, PartialOrd)]
pub struct Listing {
pub project: Project,
pub units: Vec<Unit>,
pub location: Location,
pub agent: Agent,
}
impl Listing {
pub fn new(project: Project, units: Vec<Unit>, location: Location, agent: Agent) -> Self {
Self { project, units, location, agent }
}
}

View File

@ -1,2 +1,4 @@
pub mod filters;
pub mod payloads;
pub mod listing;
pub mod project_card;

View File

@ -26,6 +26,7 @@ pub struct NewUnitPayload {
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, PartialOrd)]
pub struct UpdateUnitPayload {
pub id: Uuid,
/// Let the client convert from usd to whatever currency
#[serde(rename = "priceUsd")]
pub price_usd: Option<f64>,

22
src/dto/project_card.rs Normal file
View File

@ -0,0 +1,22 @@
use chrono::NaiveDateTime;
use serde::{Serialize, Deserialize};
use uuid::Uuid;
use crate::domain::{project_state::ProjectState, project_type::ProjectType, project_condition::ProjectCondition, media::MediaList};
/// A Dto with everything included in the card of the project list views in the frontend app.
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct ProjectCardDto {
pub id: Uuid,
#[serde(rename = "projectState")]
pub project_state: Option<ProjectState>,
#[serde(rename = "projectType")]
pub project_type: Option<ProjectType>,
#[serde(rename = "projectCondition")]
pub project_condition: Option<ProjectCondition>,
pub city: String,
pub district: String,
#[serde(rename = "finishDate")]
pub finish_date: NaiveDateTime,
pub media: Option<MediaList>,
}