4fb17abb71
Co-authored-by: Ganonmaster <168445+Ganonmaster@users.noreply.github.com>
54 lines
1.4 KiB
Rust
54 lines
1.4 KiB
Rust
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use uuid::Uuid;
|
|
|
|
/// Row as stored in the database.
|
|
/// Timestamps are stored as ISO 8601 strings because `sqlx::Any` does not
|
|
/// provide a blanket `Encode`/`Decode` impl for `chrono::DateTime<Utc>`.
|
|
#[derive(Debug, Clone, sqlx::FromRow)]
|
|
pub struct EmoteRow {
|
|
pub uuid: String,
|
|
pub name: String,
|
|
pub alias: Option<String>,
|
|
pub image_key: String,
|
|
/// ISO 8601 string, e.g. "2022-02-13T11:27:38.219685+00:00"
|
|
pub created: String,
|
|
/// ISO 8601 string
|
|
pub modified: String,
|
|
}
|
|
|
|
impl EmoteRow {
|
|
pub fn created_dt(&self) -> DateTime<Utc> {
|
|
DateTime::parse_from_rfc3339(&self.created)
|
|
.map(|dt| dt.with_timezone(&Utc))
|
|
.unwrap_or_else(|_| Utc::now())
|
|
}
|
|
|
|
pub fn modified_dt(&self) -> DateTime<Utc> {
|
|
DateTime::parse_from_rfc3339(&self.modified)
|
|
.map(|dt| dt.with_timezone(&Utc))
|
|
.unwrap_or_else(|_| Utc::now())
|
|
}
|
|
}
|
|
|
|
/// JSON representation returned by the API.
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub struct EmoteResponse {
|
|
pub name: String,
|
|
pub url: String,
|
|
pub created: DateTime<Utc>,
|
|
pub modified: DateTime<Utc>,
|
|
}
|
|
|
|
/// Payload for updating an existing emote.
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct UpdateEmoteRequest {
|
|
pub name: Option<String>,
|
|
pub alias: Option<String>,
|
|
pub image_key: Option<String>,
|
|
}
|
|
|
|
pub fn new_uuid() -> String {
|
|
Uuid::new_v4().to_string()
|
|
}
|