1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! Repository trait for Registration aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the Registration aggregate.
//! Implementation is in the infrastructure layer.
use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;
use crate::domain::entity::{Registration, EventRegistrationState, EventSaleOrderState, EventSaleStatus};
/// Pagination parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct RegistrationPaginationParams {
pub page: u32,
pub per_page: u32,
}
impl RegistrationPaginationParams {
pub fn new(page: u32, per_page: u32) -> Self {
Self { page, per_page }
}
pub fn offset(&self) -> u64 {
((self.page.saturating_sub(1)) * self.per_page) as u64
}
pub fn limit(&self) -> u64 {
self.per_page as u64
}
}
/// Paginated result for list queries
#[derive(Debug, Clone)]
pub struct RegistrationPaginatedResult {
pub data: Vec<Registration>,
pub total: u64,
pub page: u32,
pub per_page: u32,
}
/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct RegistrationFilter {
pub event_id: Option<Uuid>,
pub event_slot_id: Option<Uuid>,
pub event_ticket_id: Option<Uuid>,
pub name: Option<String>,
pub email: Option<String>,
pub phone: Option<String>,
pub company_name: Option<String>,
pub partner_id: Option<Uuid>,
pub state: Option<EventRegistrationState>,
pub sale_order_id: Option<Uuid>,
pub sale_order_state: Option<EventSaleOrderState>,
pub sale_status: Option<EventSaleStatus>,
pub active: Option<bool>,
pub barcode: Option<String>,
}
impl RegistrationFilter {
/// Check if any filter is set
pub fn has_filters(&self) -> bool {
self.event_id.is_some() || self.event_slot_id.is_some() || self.event_ticket_id.is_some() || self.name.is_some() || self.email.is_some() || self.phone.is_some() || self.company_name.is_some() || self.partner_id.is_some() || self.state.is_some() || self.sale_order_id.is_some() || self.sale_order_state.is_some() || self.sale_status.is_some() || self.active.is_some() || self.barcode.is_some()
}
}
/// Repository trait for Registration aggregate
///
/// This trait defines the persistence contract for Registration entities.
/// Implementations should be in the infrastructure layer.
#[async_trait]
pub trait RegistrationRepository: Send + Sync {
// =========================================================================
// Core CRUD Operations
// =========================================================================
/// Save a new registration entity
async fn save(&self, entity: &Registration) -> Result<Registration>;
/// Find registration by ID
async fn find_by_id(&self, id: &str) -> Result<Option<Registration>>;
/// Find all registration entities
async fn find_all(&self) -> Result<Vec<Registration>>;
/// Update registration by ID
async fn update(&self, id: &str, entity: &Registration) -> Result<Option<Registration>>;
/// Delete registration by ID
async fn delete(&self, id: &str) -> Result<bool>;
// =========================================================================
// Pagination
// =========================================================================
/// List registration with pagination
async fn list(&self, params: RegistrationPaginationParams) -> Result<RegistrationPaginatedResult>;
/// List registration with pagination and filters
async fn list_with_filters(&self, params: RegistrationPaginationParams, filters: RegistrationFilter) -> Result<RegistrationPaginatedResult>;
/// Count all registration entities
async fn count(&self) -> Result<u64>;
/// Count registration entities matching filters
async fn count_with_filters(&self, filters: RegistrationFilter) -> Result<u64>;
/// Check if registration exists by ID
async fn exists(&self, id: &str) -> Result<bool>;
// =========================================================================
// Soft Delete Operations
// =========================================================================
/// Soft delete registration by ID
async fn soft_delete(&self, id: &str) -> Result<bool>;
/// Restore soft-deleted registration by ID
async fn restore(&self, id: &str) -> Result<Option<Registration>>;
/// List soft-deleted registration entities
async fn list_deleted(&self, params: RegistrationPaginationParams) -> Result<RegistrationPaginatedResult>;
/// Empty trash (permanently delete all soft-deleted entities)
async fn empty_trash(&self) -> Result<u64>;
// =========================================================================
// Query by Unique Fields
// =========================================================================
/// Find registration by barcode
async fn find_by_barcode(&self, barcode: &str) -> Result<Option<Registration>>;
// =========================================================================
// Existence Checks by Unique Fields
// =========================================================================
/// Check if registration exists by barcode
async fn exists_by_barcode(&self, barcode: &str) -> Result<bool>;
// =========================================================================
// Bulk Operations
// =========================================================================
/// Bulk save registration entities
async fn bulk_save(&self, entities: &[Registration]) -> Result<Vec<Registration>>;
/// Bulk delete by IDs
async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}