46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use tokio_postgres::{Error, Row};
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Category {
|
|
pub id: Uuid,
|
|
pub display_name: String,
|
|
pub normalized_name: String,
|
|
pub description: String,
|
|
pub created_by: String,
|
|
pub active: bool,
|
|
pub created_at: DateTime<Utc>,
|
|
pub updated_at: DateTime<Utc>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct NewCategory {
|
|
pub display_name: String,
|
|
pub normalized_name: String,
|
|
#[serde(default)]
|
|
pub description: String,
|
|
#[serde(default = "default_ai")]
|
|
pub created_by: String,
|
|
}
|
|
|
|
fn default_ai() -> String {
|
|
"ai".to_owned()
|
|
}
|
|
|
|
impl Category {
|
|
pub fn from_row(row: &Row) -> Result<Self, Error> {
|
|
Ok(Self {
|
|
id: row.try_get("id")?,
|
|
display_name: row.try_get("display_name")?,
|
|
normalized_name: row.try_get("normalized_name")?,
|
|
description: row.try_get("description")?,
|
|
created_by: row.try_get("created_by")?,
|
|
active: row.try_get("active")?,
|
|
created_at: row.try_get("created_at")?,
|
|
updated_at: row.try_get("updated_at")?,
|
|
})
|
|
}
|
|
}
|