diff --git a/Cargo.lock b/Cargo.lock index d2e8647..0ef4e93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -541,6 +541,7 @@ dependencies = [ "chrono", "chrono-tz", "format_num", + "rand", "serde", "serde_json", "sqlx", diff --git a/Cargo.toml b/Cargo.toml index 42c18e6..84f3f3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics", " format_num = "0.1.0" sqlx = { version = "0.6.0", features = [ "runtime-tokio-rustls", "postgres", "chrono", "uuid" ], optional = true } bincode = "1.3.3" +rand = "0.8.5" [features] sqlx = ["dep:sqlx"] diff --git a/src/domain/agent.rs b/src/domain/agent.rs index 5ce3304..13e636d 100644 --- a/src/domain/agent.rs +++ b/src/domain/agent.rs @@ -1,4 +1,5 @@ use chrono::{DateTime, Utc}; +use rand::{Rng, distributions::Alphanumeric}; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -7,6 +8,8 @@ use super::credential::CredentialType; #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Agent { pub id: Uuid, + /// 8 Character string unique to every agent + pub shortcode: String, #[serde(rename = "fullName")] pub full_name: String, @@ -20,3 +23,9 @@ pub struct Agent { #[serde(rename = "lastUpdated")] pub last_updated: DateTime, } + +impl Agent { + pub fn new_shortcode() -> String { + rand::thread_rng().sample_iter(&Alphanumeric).take(8).map(char::from).collect() + } +} \ No newline at end of file diff --git a/src/dto/filters.rs b/src/dto/filters.rs index 6f724c2..4d80dad 100644 --- a/src/dto/filters.rs +++ b/src/dto/filters.rs @@ -17,7 +17,7 @@ impl Filter { 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::Finished => (String::from("finished"), String::from("true")), Filter::ByProjectType(project_type) => (String::from("byprojecttype"), project_type.to_string()), Filter::ByProjectCondition(project_condition) => (String::from("byprojectcondition"), project_condition.to_string()), } diff --git a/src/dto/payloads/agent.rs b/src/dto/payloads/agent.rs index ac153e4..7a07555 100644 --- a/src/dto/payloads/agent.rs +++ b/src/dto/payloads/agent.rs @@ -31,6 +31,7 @@ impl From for Agent { fn from(value: NewAgentPayload) -> Self { Agent { id: Uuid::new_v4(), + shortcode: Self::new_shortcode(), full_name: value.full_name, credential: value.credential, credential_type: value.credential_type, diff --git a/src/dto/project_card.rs b/src/dto/project_card.rs index e7332da..2f641cb 100644 --- a/src/dto/project_card.rs +++ b/src/dto/project_card.rs @@ -5,18 +5,19 @@ 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)] +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, PartialOrd)] pub struct ProjectCardDto { pub id: Uuid, #[serde(rename = "projectState")] - pub project_state: Option, + pub project_state: ProjectState, #[serde(rename = "projectType")] - pub project_type: Option, + pub project_type: ProjectType, #[serde(rename = "projectCondition")] - pub project_condition: Option, + pub project_condition: ProjectCondition, pub city: String, + pub starts_from: Option, pub district: String, #[serde(rename = "finishDate")] pub finish_date: NaiveDateTime, - pub media: Option, + pub media: MediaList, } \ No newline at end of file