Files
imphnen-backend-service/imphnen-gacha/src/v1/gacha_items/gacha_items_schema.rs
T

52 lines
1.1 KiB
Rust
Raw Normal View History

use crate::make_thing;
2025-05-20 10:45:01 +07:00
use imphnen_iam::get_iso_date;
use imphnen_libs::ResourceEnum;
2025-04-07 00:50:57 +07:00
use serde::{Deserialize, Serialize};
use surrealdb::{Uuid, sql::Thing};
use crate::v1::gacha_items::gacha_items_dto::GachaItemRequestDto;
2025-05-20 10:45:01 +07:00
2025-04-07 00:50:57 +07:00
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GachaItemSchema {
pub id: Thing,
pub name: String,
pub image_url: String,
pub is_deleted: bool,
pub created_at: Option<String>,
pub updated_at: Option<String>,
}
impl Default for GachaItemSchema {
fn default() -> Self {
GachaItemSchema {
id: make_thing(
&ResourceEnum::GachaItems.to_string(),
&Uuid::new_v4().to_string(),
),
name: String::new(),
image_url: String::new(),
is_deleted: false,
2025-05-20 10:45:01 +07:00
created_at: Some(get_iso_date()),
updated_at: Some(get_iso_date()),
}
}
}
impl GachaItemSchema {
pub fn from(dto: GachaItemRequestDto) -> Self {
Self {
id: make_thing(
&ResourceEnum::GachaItems.to_string(),
&Uuid::new_v4().to_string(),
),
name: dto.name,
image_url: dto.image_url,
2025-05-22 00:31:36 +07:00
..Default::default()
2025-04-07 00:50:57 +07:00
}
}
pub fn from_existing(existing: GachaItemSchema) -> Self {
existing
}
2025-04-07 00:50:57 +07:00
}