use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc};
#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
#[cfg(feature = "validation")]
use validator::Validate;
use crate::domain::entity::Booth;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::EventBoothState;
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct CreateBoothDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "event_id")]
pub event_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "booth_category_id")]
pub booth_category_id: Uuid,
#[cfg_attr(feature = "validation", validate(length(max = 200)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub name: String,
pub state: EventBoothState,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "partner_id")]
pub partner_id: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 200)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_name")]
pub contact_name: Option<String>,
#[cfg_attr(feature = "validation", validate(email, length(max = 254)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_email")]
pub contact_email: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 40)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_phone")]
pub contact_phone: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "sale_order_line_id")]
pub sale_order_line_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_paid")]
pub is_paid: bool,
}
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct UpdateBoothDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "event_id")]
pub event_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "booth_category_id")]
pub booth_category_id: Uuid,
#[cfg_attr(feature = "validation", validate(length(max = 200)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub name: String,
pub state: EventBoothState,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "partner_id")]
pub partner_id: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 200)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_name")]
pub contact_name: Option<String>,
#[cfg_attr(feature = "validation", validate(email, length(max = 254)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_email")]
pub contact_email: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 40)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_phone")]
pub contact_phone: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "sale_order_line_id")]
pub sale_order_line_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_paid")]
pub is_paid: bool,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct PatchBoothDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "event_id")]
pub event_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "booth_category_id")]
pub booth_category_id: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 200)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub state: Option<EventBoothState>,
#[serde(skip_serializing_if = "Option::is_none", alias = "partner_id")]
pub partner_id: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 200)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "contact_name")]
pub contact_name: Option<String>,
#[cfg_attr(feature = "validation", validate(email, length(max = 254)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "contact_email")]
pub contact_email: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 40)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "contact_phone")]
pub contact_phone: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "sale_order_line_id")]
pub sale_order_line_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "is_paid")]
pub is_paid: Option<bool>,
}
impl PatchBoothDto {
pub fn has_changes(&self) -> bool {
self.event_id.is_some() || self.booth_category_id.is_some() || self.name.is_some() || self.state.is_some() || self.partner_id.is_some() || self.contact_name.is_some() || self.contact_email.is_some() || self.contact_phone.is_some() || self.sale_order_line_id.is_some() || self.is_paid.is_some()
}
}
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct BoothResponseDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub event_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub booth_category_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub name: String,
pub state: EventBoothState,
pub partner_id: Option<Uuid>,
pub contact_name: Option<String>,
pub contact_email: Option<String>,
pub contact_phone: Option<String>,
pub sale_order_line_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub is_paid: bool,
pub metadata: AuditMetadata,
}
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct BoothListResponseDto {
pub items: Vec<BoothResponseDto>,
pub total: u64,
pub page: u32,
pub per_page: u32,
pub total_pages: u32,
pub has_next: bool,
pub has_prev: bool,
}
impl BoothListResponseDto {
pub fn new(items: Vec<BoothResponseDto>, total: u64, page: u32, per_page: u32) -> Self {
let total_pages = if per_page > 0 {
((total as f64) / (per_page as f64)).ceil() as u32
} else {
0
};
Self {
items,
total,
page,
per_page,
total_pages,
has_next: page < total_pages,
has_prev: page > 1,
}
}
}
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct BoothSummaryDto {
pub id: Uuid,
pub event_id: Uuid,
pub booth_category_id: Uuid,
pub name: String,
pub created_at: Option<DateTime<Utc>>,
}
impl From<Booth> for BoothResponseDto {
fn from(entity: Booth) -> Self {
Self {
id: entity.id,
event_id: entity.event_id,
booth_category_id: entity.booth_category_id,
name: entity.name,
state: entity.state,
partner_id: entity.partner_id,
contact_name: entity.contact_name,
contact_email: entity.contact_email,
contact_phone: entity.contact_phone,
sale_order_line_id: entity.sale_order_line_id,
is_paid: entity.is_paid,
metadata: entity.metadata,
}
}
}
impl From<Booth> for BoothSummaryDto {
fn from(entity: Booth) -> Self {
let created_at = backbone_core::PersistentEntity::created_at(&entity);
Self {
id: entity.id,
event_id: entity.event_id,
booth_category_id: entity.booth_category_id,
name: entity.name,
created_at,
}
}
}
impl From<CreateBoothDto> for Booth {
fn from(dto: CreateBoothDto) -> Self {
Self {
id: Uuid::new_v4(),
event_id: dto.event_id,
booth_category_id: dto.booth_category_id,
name: dto.name,
state: dto.state,
partner_id: dto.partner_id,
contact_name: dto.contact_name,
contact_email: dto.contact_email,
contact_phone: dto.contact_phone,
sale_order_line_id: dto.sale_order_line_id,
is_paid: dto.is_paid,
metadata: AuditMetadata::default(),
}
}
}
impl From<&Booth> for BoothResponseDto {
fn from(entity: &Booth) -> Self {
Self {
id: entity.id.clone(),
event_id: entity.event_id.clone(),
booth_category_id: entity.booth_category_id.clone(),
name: entity.name.clone(),
state: entity.state.clone(),
partner_id: entity.partner_id.clone(),
contact_name: entity.contact_name.clone(),
contact_email: entity.contact_email.clone(),
contact_phone: entity.contact_phone.clone(),
sale_order_line_id: entity.sale_order_line_id.clone(),
is_paid: entity.is_paid.clone(),
metadata: entity.metadata.clone(),
}
}
}
impl backbone_core::FromCreateDto<CreateBoothDto> for Booth {
fn from_create_dto(dto: CreateBoothDto) -> backbone_core::ServiceResult<Self> {
Ok(Booth::from(dto))
}
}
impl backbone_core::ApplyUpdateDto<UpdateBoothDto> for Booth {
fn apply_update(mut self, dto: UpdateBoothDto) -> backbone_core::ServiceResult<Self> {
self.event_id = dto.event_id;
self.booth_category_id = dto.booth_category_id;
self.name = dto.name;
self.state = dto.state;
self.partner_id = dto.partner_id;
self.contact_name = dto.contact_name;
self.contact_email = dto.contact_email;
self.contact_phone = dto.contact_phone;
self.sale_order_line_id = dto.sale_order_line_id;
self.is_paid = dto.is_paid;
Ok(self)
}
}