e034b46
use db::issue::issue_label as label_entity;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use time::format_description::well_known::Rfc3339;
use utoipa::{IntoParams, ToSchema};
use uuid::Uuid;
fn fmt_ts(ts: OffsetDateTime) -> String {
ts.format(&Rfc3339).unwrap_or_default()
}
fn fmt_ts_opt(ts: Option<OffsetDateTime>) -> Option<String> {
ts.map(fmt_ts)
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct LabelView {
pub id: Uuid,
pub channel_id: Uuid,
pub name: String,
pub exclusive: bool,
pub exclusive_order: i32,
pub description: Option<String>,
pub color: String,
pub is_archived: bool,
pub created_at: String,
pub updated_at: Option<String>,
}
impl From<label_entity::Model> for LabelView {
fn from(m: label_entity::Model) -> Self {
Self {
id: m.id,
channel_id: m.channel_id,
name: m.name,
exclusive: m.exclusive,
exclusive_order: m.exclusive_order,
description: m.description,
color: m.color,
is_archived: m.is_archived,
created_at: fmt_ts(m.created_at),
updated_at: fmt_ts_opt(m.updated_at),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct LabelPage {
pub items: Vec<LabelView>,
pub total: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct CreateLabelOption {
pub name: String,
pub color: String,
pub exclusive: Option<bool>,
pub exclusive_order: Option<i32>,
pub description: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct UpdateLabelOption {
pub name: Option<String>,
pub color: Option<String>,
pub exclusive: Option<bool>,
pub exclusive_order: Option<i32>,
pub description: Option<Option<String>>,
pub is_archived: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
pub struct ListLabelQuery {
pub q: Option<String>,
pub is_archived: Option<bool>,
pub limit: Option<u64>,
pub offset: Option<u64>,
}