66 lines
2.0 KiB
Rust
66 lines
2.0 KiB
Rust
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 Video {
|
|
pub id: Uuid,
|
|
pub channel_id: Uuid,
|
|
pub youtube_video_id: String,
|
|
pub canonical_url: String,
|
|
pub title: String,
|
|
pub description: String,
|
|
pub published_at: Option<DateTime<Utc>>,
|
|
pub duration_seconds: Option<i32>,
|
|
pub thumbnail_asset_id: Option<Uuid>,
|
|
pub processing_status: String,
|
|
pub metadata: Value,
|
|
pub created_at: DateTime<Utc>,
|
|
pub updated_at: DateTime<Utc>,
|
|
pub deleted_at: Option<DateTime<Utc>>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct NewVideo {
|
|
pub channel_id: Uuid,
|
|
pub youtube_video_id: String,
|
|
pub canonical_url: String,
|
|
pub title: String,
|
|
#[serde(default)]
|
|
pub description: String,
|
|
pub published_at: Option<DateTime<Utc>>,
|
|
pub duration_seconds: Option<i32>,
|
|
pub thumbnail_asset_id: Option<Uuid>,
|
|
#[serde(default = "default_pending")]
|
|
pub processing_status: String,
|
|
#[serde(default)]
|
|
pub metadata: Value,
|
|
}
|
|
|
|
fn default_pending() -> String {
|
|
"pending".to_owned()
|
|
}
|
|
|
|
impl Video {
|
|
pub fn from_row(row: &Row) -> Result<Self, Error> {
|
|
Ok(Self {
|
|
id: row.try_get("id")?,
|
|
channel_id: row.try_get("channel_id")?,
|
|
youtube_video_id: row.try_get("youtube_video_id")?,
|
|
canonical_url: row.try_get("canonical_url")?,
|
|
title: row.try_get("title")?,
|
|
description: row.try_get("description")?,
|
|
published_at: row.try_get("published_at")?,
|
|
duration_seconds: row.try_get("duration_seconds")?,
|
|
thumbnail_asset_id: row.try_get("thumbnail_asset_id")?,
|
|
processing_status: row.try_get("processing_status")?,
|
|
metadata: row.try_get("metadata")?,
|
|
created_at: row.try_get("created_at")?,
|
|
updated_at: row.try_get("updated_at")?,
|
|
deleted_at: row.try_get("deleted_at")?,
|
|
})
|
|
}
|
|
}
|