first commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::{Error, Row};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Origin {
|
||||
pub id: Uuid,
|
||||
pub display_name: String,
|
||||
pub canonical_url: String,
|
||||
pub domain: String,
|
||||
pub source_type: String,
|
||||
pub icon_asset_id: Option<Uuid>,
|
||||
pub first_seen_at: DateTime<Utc>,
|
||||
pub last_seen_at: DateTime<Utc>,
|
||||
pub metadata: Value,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NewOrigin {
|
||||
pub display_name: String,
|
||||
pub canonical_url: String,
|
||||
pub domain: String,
|
||||
#[serde(default = "default_website")]
|
||||
pub source_type: String,
|
||||
pub icon_asset_id: Option<Uuid>,
|
||||
#[serde(default)]
|
||||
pub metadata: Value,
|
||||
}
|
||||
|
||||
fn default_website() -> String {
|
||||
"website".to_owned()
|
||||
}
|
||||
|
||||
impl Origin {
|
||||
pub fn from_row(row: &Row) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
id: row.try_get("id")?,
|
||||
display_name: row.try_get("display_name")?,
|
||||
canonical_url: row.try_get("canonical_url")?,
|
||||
domain: row.try_get("domain")?,
|
||||
source_type: row.try_get("source_type")?,
|
||||
icon_asset_id: row.try_get("icon_asset_id")?,
|
||||
first_seen_at: row.try_get("first_seen_at")?,
|
||||
last_seen_at: row.try_get("last_seen_at")?,
|
||||
metadata: row.try_get("metadata")?,
|
||||
created_at: row.try_get("created_at")?,
|
||||
updated_at: row.try_get("updated_at")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user