Added agent shortcodes

This commit is contained in:
Franklin 2023-04-14 14:49:37 -04:00
parent 6cdfba8805
commit 6aa4e0095d
6 changed files with 19 additions and 6 deletions

1
Cargo.lock generated
View File

@ -541,6 +541,7 @@ dependencies = [
"chrono",
"chrono-tz",
"format_num",
"rand",
"serde",
"serde_json",
"sqlx",

View File

@ -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"]

View File

@ -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<Utc>,
}
impl Agent {
pub fn new_shortcode() -> String {
rand::thread_rng().sample_iter(&Alphanumeric).take(8).map(char::from).collect()
}
}

View File

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

View File

@ -31,6 +31,7 @@ impl From<NewAgentPayload> 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,

View File

@ -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<ProjectState>,
pub project_state: ProjectState,
#[serde(rename = "projectType")]
pub project_type: Option<ProjectType>,
pub project_type: ProjectType,
#[serde(rename = "projectCondition")]
pub project_condition: Option<ProjectCondition>,
pub project_condition: ProjectCondition,
pub city: String,
pub starts_from: Option<f64>,
pub district: String,
#[serde(rename = "finishDate")]
pub finish_date: NaiveDateTime,
pub media: Option<MediaList>,
pub media: MediaList,
}