49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
use serde::{Serialize, Deserialize};
|
|
use sea_orm::ActiveValue::Set;
|
|
use uuid::Uuid;
|
|
use crate::models::category;
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct CategorySerializer {
|
|
#[serde(skip_deserializing)]
|
|
pub id: Option<Uuid>,
|
|
|
|
pub server_id: Uuid,
|
|
|
|
pub name: String,
|
|
|
|
#[serde(skip_deserializing)]
|
|
pub created_at: Option<String>,
|
|
|
|
#[serde(skip_deserializing)]
|
|
pub updated_at: Option<String>,
|
|
}
|
|
|
|
impl From<category::Model> for CategorySerializer {
|
|
fn from(model: category::Model) -> Self {
|
|
Self {
|
|
id: Some(model.id),
|
|
server_id: model.server_id,
|
|
name: model.name,
|
|
created_at: Some(model.created_at.to_string()),
|
|
updated_at: Some(model.updated_at.to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl CategorySerializer {
|
|
pub fn into_active_model(self) -> category::ActiveModel {
|
|
category::ActiveModel {
|
|
server_id: Set(self.server_id),
|
|
name: Set(self.name),
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
pub fn apply_to_active_model(self, mut active_model: category::ActiveModel) -> category::ActiveModel {
|
|
active_model.server_id = Set(self.server_id);
|
|
active_model.name = Set(self.name);
|
|
active_model
|
|
}
|
|
}
|