Cargo fmt and added payloads
This commit is contained in:
parent
bf818bb408
commit
1b4600ec21
|
@ -1,4 +1,5 @@
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -22,3 +23,13 @@ pub struct Realtor {
|
||||||
#[serde(rename = "lastUpdated")]
|
#[serde(rename = "lastUpdated")]
|
||||||
pub last_updated: DateTime<Utc>,
|
pub last_updated: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Realtor {
|
||||||
|
pub fn new_shortcode() -> String {
|
||||||
|
rand::thread_rng()
|
||||||
|
.sample_iter(&Alphanumeric)
|
||||||
|
.take(8)
|
||||||
|
.map(char::from)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// A user that can be tracked. All the info that you can gather from the user based on their browser & IP network.
|
/// A user that can be tracked. All the info that you can gather from the user based on their browser & IP network.
|
||||||
|
/// What's important is that the initial things are stored. Meaning window height & width, if those things change in the same session, then whatever.
|
||||||
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Trackable {
|
pub struct Trackable {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
use chrono::Utc;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::domain::{click::Click, clickable::Clickable};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct ClickForCreationPayload {
|
||||||
|
#[serde(rename = "realtorId")]
|
||||||
|
pub realtor_id: Uuid,
|
||||||
|
pub clickable: Clickable,
|
||||||
|
#[serde(rename = "trackableId")]
|
||||||
|
pub trackable_id: Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ClickForCreationPayload> for Click {
|
||||||
|
fn from(value: ClickForCreationPayload) -> Self {
|
||||||
|
Self {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
realtor_id: value.realtor_id,
|
||||||
|
clickable: value.clickable,
|
||||||
|
trackable_id: value.trackable_id,
|
||||||
|
time_created: Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1,6 @@
|
||||||
|
pub mod click;
|
||||||
|
pub mod project;
|
||||||
|
pub mod property;
|
||||||
|
pub mod realtor;
|
||||||
|
pub mod trackable;
|
||||||
|
pub mod view;
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
use chrono::{NaiveDate, Utc};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
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 ProjectForCreationPayload {
|
||||||
|
pub title: Option<String>,
|
||||||
|
pub description: String,
|
||||||
|
#[serde(rename = "realtorId")]
|
||||||
|
pub realtor_id: Uuid,
|
||||||
|
pub media: MediaList,
|
||||||
|
#[serde(rename = "projectCondition")]
|
||||||
|
pub project_condition: ProjectCondition,
|
||||||
|
#[serde(rename = "projectType")]
|
||||||
|
pub project_type: ProjectType,
|
||||||
|
#[serde(rename = "projectState")]
|
||||||
|
pub project_state: ProjectState,
|
||||||
|
pub country: String,
|
||||||
|
pub city: String,
|
||||||
|
pub district: String,
|
||||||
|
#[serde(rename = "adminTag", skip_serializing_if = "Option::is_none")]
|
||||||
|
pub admin_tag: Option<String>,
|
||||||
|
pub floors: i16,
|
||||||
|
#[serde(rename = "finishDate")]
|
||||||
|
pub finish_date: NaiveDate,
|
||||||
|
/// This gives the realtor the option to order the projects/properties. On birth,
|
||||||
|
#[serde(rename = "orderIndex")]
|
||||||
|
pub order_index: i32,
|
||||||
|
}
|
||||||
|
impl From<ProjectForCreationPayload> for Project {
|
||||||
|
fn from(value: ProjectForCreationPayload) -> Self {
|
||||||
|
Self {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
title: value.title,
|
||||||
|
description: value.description,
|
||||||
|
realtor_id: value.realtor_id,
|
||||||
|
media: value.media,
|
||||||
|
project_condition: value.project_condition,
|
||||||
|
project_type: value.project_type,
|
||||||
|
project_state: value.project_state,
|
||||||
|
country: value.country,
|
||||||
|
city: value.city,
|
||||||
|
district: value.district,
|
||||||
|
admin_tag: value.admin_tag,
|
||||||
|
floors: value.floors,
|
||||||
|
finish_date: value.finish_date,
|
||||||
|
order_index: value.order_index,
|
||||||
|
time_created: Utc::now(),
|
||||||
|
last_updated: Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
use chrono::Utc;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::domain::{
|
||||||
|
media::MediaList, property::Property, property_sale_type::PropertySaleType,
|
||||||
|
property_type::PropertyType,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A property can belong to a project, or not. It should always belong to a realtor.
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, PartialOrd)]
|
||||||
|
pub struct PropertyForCreationPayload {
|
||||||
|
#[serde(rename = "projectId")]
|
||||||
|
pub project_id: Option<Uuid>,
|
||||||
|
#[serde(rename = "realtorId")]
|
||||||
|
pub realtor_id: Uuid,
|
||||||
|
pub media: MediaList,
|
||||||
|
#[serde(rename = "propertyType")]
|
||||||
|
pub property_type: PropertyType,
|
||||||
|
#[serde(rename = "propertySaleType")]
|
||||||
|
pub property_sale_type: PropertySaleType,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub country: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub city: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub district: Option<String>,
|
||||||
|
#[serde(rename = "priceUsd")]
|
||||||
|
pub price_usd: f64,
|
||||||
|
/// Amount of rooms in unit
|
||||||
|
pub rooms: i16,
|
||||||
|
/// Amount of bathrooms in unit
|
||||||
|
pub bathrooms: f32,
|
||||||
|
/// In meters squared
|
||||||
|
pub area: f32,
|
||||||
|
#[serde(rename = "adminTag")]
|
||||||
|
pub admin_tag: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<PropertyForCreationPayload> for Property {
|
||||||
|
fn from(value: PropertyForCreationPayload) -> Self {
|
||||||
|
Self {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
project_id: value.project_id,
|
||||||
|
realtor_id: value.realtor_id,
|
||||||
|
media: value.media,
|
||||||
|
property_type: value.property_type,
|
||||||
|
property_sale_type: value.property_sale_type,
|
||||||
|
country: value.country,
|
||||||
|
city: value.city,
|
||||||
|
district: value.district,
|
||||||
|
price_usd: value.price_usd,
|
||||||
|
rooms: value.rooms,
|
||||||
|
bathrooms: value.bathrooms,
|
||||||
|
area: value.area,
|
||||||
|
admin_tag: value.admin_tag,
|
||||||
|
time_created: Utc::now(),
|
||||||
|
last_updated: Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
use chrono::Utc;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::domain::realtor::Realtor;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct RealtorForCreationPayload {
|
||||||
|
pub name: String,
|
||||||
|
pub bio: String,
|
||||||
|
#[serde(rename = "phoneNumber")]
|
||||||
|
pub phone_number: String,
|
||||||
|
pub email: Option<String>,
|
||||||
|
#[serde(rename = "profilePictureUrl")]
|
||||||
|
pub profile_picture_url: String,
|
||||||
|
#[serde(rename = "showProjects")]
|
||||||
|
pub show_projects: bool,
|
||||||
|
#[serde(rename = "remaxAgentId")]
|
||||||
|
pub remax_agent_id: Option<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RealtorForCreationPayload> for Realtor {
|
||||||
|
fn from(value: RealtorForCreationPayload) -> Self {
|
||||||
|
Self {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
name: value.name,
|
||||||
|
bio: value.bio,
|
||||||
|
phone_number: value.phone_number,
|
||||||
|
email: value.email,
|
||||||
|
profile_picture_url: value.profile_picture_url,
|
||||||
|
show_projects: value.show_projects,
|
||||||
|
shortcode: Self::new_shortcode(),
|
||||||
|
remax_agent_id: value.remax_agent_id,
|
||||||
|
time_created: Utc::now(),
|
||||||
|
last_updated: Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
use chrono::Utc;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::domain::trackable::Trackable;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct TrackableForCreationPayload {
|
||||||
|
/// This field is used to indetify if a user has been to the website before. Pretty much checks to see if the user already has a Trackable UUID in record.
|
||||||
|
/// But has changed things like IpAddress or user agent.
|
||||||
|
#[serde(rename = "whoWas")]
|
||||||
|
pub who_was: Option<Uuid>,
|
||||||
|
#[serde(rename = "ipAddress")]
|
||||||
|
pub ip_address: String,
|
||||||
|
/// Used to determine on what device the user is
|
||||||
|
#[serde(rename = "browserWidth")]
|
||||||
|
pub browser_width: i32,
|
||||||
|
/// Used to determine on what device the user is
|
||||||
|
#[serde(rename = "browserWidth")]
|
||||||
|
pub browser_height: i32,
|
||||||
|
#[serde(rename = "userAgent")]
|
||||||
|
pub user_agent: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TrackableForCreationPayload> for Trackable {
|
||||||
|
fn from(value: TrackableForCreationPayload) -> Self {
|
||||||
|
Trackable {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
who_was: value.who_was,
|
||||||
|
ip_address: value.ip_address,
|
||||||
|
browser_width: value.browser_width,
|
||||||
|
browser_height: value.browser_height,
|
||||||
|
user_agent: value.user_agent,
|
||||||
|
time_created: Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
use chrono::Utc;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::domain::{thing_pk::ThingPk, view::View};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct ViewForCreationPayload {
|
||||||
|
#[serde(rename = "thingId")]
|
||||||
|
pub thing_id: Uuid,
|
||||||
|
#[serde(rename = "thingPk")]
|
||||||
|
pub thing_pk: ThingPk,
|
||||||
|
#[serde(rename = "trackableId")]
|
||||||
|
pub trackable_id: Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ViewForCreationPayload> for View {
|
||||||
|
fn from(value: ViewForCreationPayload) -> Self {
|
||||||
|
Self {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
thing_id: value.thing_id,
|
||||||
|
thing_pk: value.thing_pk,
|
||||||
|
trackable_id: value.trackable_id,
|
||||||
|
time_created: Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue