crudcrate 0.8.0

Derive complete REST APIs from Sea-ORM entities — endpoints, filtering, pagination, batch ops, and OpenAPI on Axum
Documentation
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
//! Trait-based CRUD customization.
//!
//! [`CRUDOperations`] provides an alternative to per-attribute hooks: implement the trait
//! on a unit struct, override only the methods you need, and wire it in with
//! `#[crudcrate(operations = MyOps)]`.
//!
//! ```rust,ignore
//! pub struct AssetOps;
//!
//! #[async_trait]
//! impl CRUDOperations for AssetOps {
//!     type Resource = Asset;
//!
//!     async fn delete(&self, db: &DatabaseConnection, id: Uuid) -> Result<Uuid, ApiError> {
//!         let asset = Asset::get_one(db, id).await?;
//!         delete_from_s3(&asset.s3_key).await
//!             .map_err(|e| ApiError::internal(format!("S3 cleanup failed: {e}"), None))?;
//!         Asset::delete(db, id).await
//!     }
//! }
//!
//! #[derive(EntityToModels)]
//! #[crudcrate(generate_router, operations = AssetOps)]
//! pub struct Model { /* ... */ }
//! ```

use async_trait::async_trait;
use sea_orm::{Condition, DatabaseConnection, Order};
use uuid::Uuid;

use crate::ApiError;
use crate::core::CRUDResource;

/// Trait for defining CRUD operations with customizable behavior
///
/// This trait provides **three levels of customization**:
///
/// 1. **Lifecycle Hooks**: `before_*` and `after_*` methods for validation, logging, enrichment
/// 2. **Core Logic**: `fetch_*` and `perform_*` methods for custom queries and business logic
/// 3. **Full Override**: Replace entire operations like `get_one`, `delete`, etc.
///
/// ## Type Parameters
///
/// - `Resource`: The CRUD resource type that implements `CRUDResource`
///
/// ## Customization Levels
///
/// **Level 1: Hooks Only** (validation, logging, enrichment)
/// ```rust,ignore
/// async fn before_create(&self, db: &DatabaseConnection, data: &CreateModel) -> Result<(), DbErr> {
///     validate(data)?;
///     Ok(())
/// }
///
/// async fn after_get_one(&self, db: &DatabaseConnection, entity: &mut Resource) -> Result<(), DbErr> {
///     entity.view_count = get_view_count(db, entity.id).await?;
///     Ok(())
/// }
/// ```
///
/// **Level 2: Core Logic** (custom queries, business logic)
/// ```rust,ignore
/// async fn fetch_one(&self, db: &DatabaseConnection, id: Uuid) -> Result<Resource, DbErr> {
///     // Custom query with joins
///     Entity::find_by_id(id).find_with_related(Related).one(db).await?.ok_or(...)
/// }
/// ```
///
/// **Level 3: Full Override** (complete control)
/// ```rust,ignore
/// async fn delete(&self, db: &DatabaseConnection, id: Uuid) -> Result<Uuid, DbErr> {
///     // Completely custom implementation
///     cleanup_s3(id).await?;
///     Entity::delete_by_id(id).exec(db).await?;
///     Ok(id)
/// }
/// ```
#[async_trait]
pub trait CRUDOperations: Send + Sync {
    /// The CRUD resource type this operations implementation works with
    type Resource: CRUDResource;

    // ==========================================
    // LIFECYCLE HOOKS - GET ONE
    // ==========================================

    /// Hook called before fetching a single entity
    ///
    /// Use for: authorization checks, rate limiting, logging
    ///
    /// # Errors
    /// Return `ApiError` to abort the operation with specific HTTP status code
    ///
    /// # Example
    /// ```rust,ignore
    /// async fn before_get_one(&self, _db: &DatabaseConnection, id: Uuid) -> Result<(), ApiError> {
    ///     if !has_permission(id) {
    ///         return Err(ApiError::forbidden("Access denied"));
    ///     }
    ///     Ok(())
    /// }
    /// ```
    async fn before_get_one(&self, _db: &DatabaseConnection, _id: Uuid) -> Result<(), ApiError> {
        Ok(()) // Default: no-op
    }

    /// Hook called after fetching a single entity
    ///
    /// Use for: enrichment, computed fields, audit logging
    ///
    /// # Errors
    /// Return `ApiError` to abort the operation
    async fn after_get_one(
        &self,
        _db: &DatabaseConnection,
        _entity: &mut Self::Resource,
    ) -> Result<(), ApiError> {
        Ok(()) // Default: no-op
    }

    /// Core database fetch logic for a single entity
    ///
    /// Override this to customize the query (e.g., add joins, select specific columns)
    ///
    /// # Errors
    /// Returns `ApiError::NotFound` if entity doesn't exist
    async fn fetch_one(
        &self,
        db: &DatabaseConnection,
        id: Uuid,
    ) -> Result<Self::Resource, ApiError> {
        use sea_orm::EntityTrait;

        let model = <Self::Resource as CRUDResource>::EntityType::find_by_id(id)
            .one(db)
            .await
            .map_err(ApiError::database)?
            .ok_or_else(|| {
                ApiError::not_found(
                    <Self::Resource as CRUDResource>::RESOURCE_NAME_SINGULAR,
                    Some(id.to_string()),
                )
            })?;
        Ok(Self::Resource::from(model))
    }

    // ==========================================
    // LIFECYCLE HOOKS - GET ALL
    // ==========================================

    /// Hook called before fetching multiple entities
    async fn before_get_all(
        &self,
        _db: &DatabaseConnection,
        _condition: &Condition,
        _order_column: <Self::Resource as CRUDResource>::ColumnType,
        _order_direction: &Order,
        _offset: u64,
        _limit: u64,
    ) -> Result<(), ApiError> {
        Ok(())
    }

    /// Hook called after fetching multiple entities
    ///
    /// Receives a mutable reference to the list for enrichment
    async fn after_get_all(
        &self,
        _db: &DatabaseConnection,
        _entities: &mut Vec<<Self::Resource as CRUDResource>::ListModel>,
    ) -> Result<(), ApiError> {
        Ok(())
    }

    /// Core database fetch logic for multiple entities
    async fn fetch_all(
        &self,
        db: &DatabaseConnection,
        condition: &Condition,
        order_column: <Self::Resource as CRUDResource>::ColumnType,
        order_direction: Order,
        offset: u64,
        limit: u64,
    ) -> Result<Vec<<Self::Resource as CRUDResource>::ListModel>, ApiError> {
        use sea_orm::{EntityTrait, QueryFilter, QueryOrder, QuerySelect};

        let models = <Self::Resource as CRUDResource>::EntityType::find()
            .filter(condition.clone())
            .order_by(order_column, order_direction)
            .offset(offset)
            .limit(limit)
            .all(db)
            .await
            .map_err(ApiError::database)?;
        Ok(models
            .into_iter()
            .map(|model| {
                <Self::Resource as CRUDResource>::ListModel::from(Self::Resource::from(model))
            })
            .collect())
    }

    // ==========================================
    // LIFECYCLE HOOKS - CREATE
    // ==========================================

    /// Hook called before creating an entity
    ///
    /// Use for: validation, authorization, setting default values
    ///
    /// # Example
    /// ```rust,ignore
    /// async fn before_create(&self, db: &DatabaseConnection, data: &CreateModel) -> Result<(), ApiError> {
    ///     if data.price <= 0 {
    ///         return Err(ApiError::bad_request("Price must be greater than 0"));
    ///     }
    ///     Ok(())
    /// }
    /// ```
    async fn before_create(
        &self,
        _db: &DatabaseConnection,
        _data: &<Self::Resource as CRUDResource>::CreateModel,
    ) -> Result<(), ApiError> {
        Ok(())
    }

    /// Hook called after creating an entity
    ///
    /// Use for: sending notifications, logging, cache invalidation
    async fn after_create(
        &self,
        _db: &DatabaseConnection,
        _entity: &mut Self::Resource,
    ) -> Result<(), ApiError> {
        Ok(())
    }

    /// Core database insert logic
    async fn perform_create(
        &self,
        db: &DatabaseConnection,
        data: <Self::Resource as CRUDResource>::CreateModel,
    ) -> Result<Self::Resource, ApiError> {
        use sea_orm::ActiveModelTrait;

        let active_model: <Self::Resource as CRUDResource>::ActiveModelType = data.into();
        let model = active_model.insert(db).await.map_err(ApiError::database)?;
        Ok(Self::Resource::from(model))
    }

    // ==========================================
    // LIFECYCLE HOOKS - UPDATE
    // ==========================================

    /// Hook called before updating an entity
    async fn before_update(
        &self,
        _db: &DatabaseConnection,
        _id: Uuid,
        _data: &<Self::Resource as CRUDResource>::UpdateModel,
    ) -> Result<(), ApiError> {
        Ok(())
    }

    /// Hook called after updating an entity
    async fn after_update(
        &self,
        _db: &DatabaseConnection,
        _entity: &mut Self::Resource,
    ) -> Result<(), ApiError> {
        Ok(())
    }

    /// Core database update logic
    async fn perform_update(
        &self,
        db: &DatabaseConnection,
        id: Uuid,
        data: <Self::Resource as CRUDResource>::UpdateModel,
    ) -> Result<Self::Resource, ApiError> {
        use crate::core::MergeIntoActiveModel;
        use sea_orm::{ActiveModelTrait, EntityTrait, IntoActiveModel};

        let model = <Self::Resource as CRUDResource>::EntityType::find_by_id(id)
            .one(db)
            .await
            .map_err(ApiError::database)?
            .ok_or_else(|| {
                ApiError::not_found(
                    <Self::Resource as CRUDResource>::RESOURCE_NAME_SINGULAR,
                    Some(id.to_string()),
                )
            })?;
        let existing: <Self::Resource as CRUDResource>::ActiveModelType = model.into_active_model();
        let updated_model = data.merge_into_activemodel(existing)?;
        let updated = updated_model.update(db).await.map_err(ApiError::database)?;
        Ok(Self::Resource::from(updated))
    }

    // ==========================================
    // LIFECYCLE HOOKS - DELETE
    // ==========================================

    /// Hook called before deleting an entity
    ///
    /// Use for: authorization, cleanup of related resources
    ///
    /// # Example
    /// ```rust,ignore
    /// async fn before_delete(&self, db: &DatabaseConnection, id: Uuid) -> Result<(), ApiError> {
    ///     if !user_can_delete(id) {
    ///         return Err(ApiError::forbidden("You don't have permission to delete this resource"));
    ///     }
    ///     Ok(())
    /// }
    /// ```
    async fn before_delete(&self, _db: &DatabaseConnection, _id: Uuid) -> Result<(), ApiError> {
        Ok(())
    }

    /// Hook called after deleting an entity
    ///
    /// Use for: cache invalidation, notifications, audit logging
    async fn after_delete(&self, _db: &DatabaseConnection, _id: Uuid) -> Result<(), ApiError> {
        Ok(())
    }

    /// Core database delete logic
    async fn perform_delete(&self, db: &DatabaseConnection, id: Uuid) -> Result<Uuid, ApiError> {
        use sea_orm::EntityTrait;

        let res = <Self::Resource as CRUDResource>::EntityType::delete_by_id(id)
            .exec(db)
            .await
            .map_err(ApiError::database)?;
        match res.rows_affected {
            0 => Err(ApiError::not_found(
                <Self::Resource as CRUDResource>::RESOURCE_NAME_SINGULAR,
                Some(id.to_string()),
            )),
            _ => Ok(id),
        }
    }

    // ==========================================
    // LIFECYCLE HOOKS - DELETE MANY
    // ==========================================

    /// Hook called before batch deleting entities
    async fn before_delete_many(
        &self,
        _db: &DatabaseConnection,
        _ids: &[Uuid],
    ) -> Result<(), ApiError> {
        Ok(())
    }

    /// Hook called after batch deleting entities
    async fn after_delete_many(
        &self,
        _db: &DatabaseConnection,
        _ids: &[Uuid],
    ) -> Result<(), ApiError> {
        Ok(())
    }

    /// Core database batch delete logic
    async fn perform_delete_many(
        &self,
        db: &DatabaseConnection,
        ids: Vec<Uuid>,
    ) -> Result<Vec<Uuid>, ApiError> {
        use crate::core::UuidIdResult;
        use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QuerySelect};

        // Security: Limit batch size to prevent DoS attacks (uses resource's configured limit)
        let batch_limit = <Self::Resource as CRUDResource>::batch_limit();
        if ids.len() > batch_limit {
            return Err(ApiError::bad_request(format!(
                "Batch delete limited to {} items. Received {} items.",
                batch_limit,
                ids.len()
            )));
        }

        if ids.is_empty() {
            return Ok(vec![]);
        }

        // Pre-query: which IDs actually exist?
        let existing: Vec<UuidIdResult> = <Self::Resource as CRUDResource>::EntityType::find()
            .select_only()
            .column_as(<Self::Resource as CRUDResource>::ID_COLUMN, "id")
            .filter(<Self::Resource as CRUDResource>::ID_COLUMN.is_in(ids.clone()))
            .into_model::<UuidIdResult>()
            .all(db)
            .await
            .map_err(ApiError::database)?;
        let existing_set: std::collections::HashSet<Uuid> =
            existing.into_iter().map(|r| r.id).collect();

        // Delete only existing IDs
        if !existing_set.is_empty() {
            <Self::Resource as CRUDResource>::EntityType::delete_many()
                .filter(
                    <Self::Resource as CRUDResource>::ID_COLUMN
                        .is_in(existing_set.iter().copied().collect::<Vec<_>>()),
                )
                .exec(db)
                .await
                .map_err(ApiError::database)?;
        }

        // Return only IDs that actually existed (preserving input order)
        Ok(ids
            .into_iter()
            .filter(|id| existing_set.contains(id))
            .collect())
    }

    // ==========================================
    // MAIN OPERATIONS (orchestrate hooks + core logic)
    // ==========================================

    /// Fetch a single entity by ID
    ///
    /// Orchestrates the full `get_one` lifecycle:
    /// 1. `before_get_one` - validation, auth, logging
    /// 2. `fetch_one` - database query
    /// 3. `after_get_one` - enrichment, computed fields
    ///
    /// # Errors
    ///
    /// Returns `ApiError::NotFound` if the entity doesn't exist
    /// Returns `ApiError` if any hook or core logic fails
    async fn get_one(&self, db: &DatabaseConnection, id: Uuid) -> Result<Self::Resource, ApiError> {
        // 1. Before hook
        self.before_get_one(db, id).await?;

        // 2. Core logic (fetch)
        let mut entity = self.fetch_one(db, id).await?;

        // 3. After hook
        self.after_get_one(db, &mut entity).await?;

        Ok(entity)
    }

    /// Fetch multiple entities with filtering, sorting, and pagination
    ///
    /// Orchestrates the full `get_all` lifecycle:
    /// 1. `before_get_all` - validation, auth, logging
    /// 2. `fetch_all` - database query
    /// 3. `after_get_all` - enrichment, computed fields
    ///
    /// # Parameters
    ///
    /// - `db`: Database connection
    /// - `condition`: Filter conditions to apply
    /// - `order_column`: Column to sort by
    /// - `order_direction`: Sort direction (ASC or DESC)
    /// - `offset`: Number of records to skip
    /// - `limit`: Maximum number of records to return
    ///
    /// # Errors
    ///
    /// Returns `ApiError` if any hook or database query fails
    async fn get_all(
        &self,
        db: &DatabaseConnection,
        condition: &Condition,
        order_column: <Self::Resource as CRUDResource>::ColumnType,
        order_direction: Order,
        offset: u64,
        limit: u64,
    ) -> Result<Vec<<Self::Resource as CRUDResource>::ListModel>, ApiError> {
        // 1. Before hook
        self.before_get_all(db, condition, order_column, &order_direction, offset, limit)
            .await?;

        // 2. Core logic (fetch)
        let mut entities = self
            .fetch_all(db, condition, order_column, order_direction, offset, limit)
            .await?;

        // 3. After hook
        self.after_get_all(db, &mut entities).await?;

        Ok(entities)
    }

    /// Create a new entity
    ///
    /// Orchestrates the full create lifecycle:
    /// 1. `before_create` - validation, auth, setting defaults
    /// 2. `perform_create` - database insert
    /// 3. `after_create` - notifications, cache updates
    ///
    /// # Errors
    ///
    /// Returns `ApiError` if any hook or database insertion fails
    async fn create(
        &self,
        db: &DatabaseConnection,
        data: <Self::Resource as CRUDResource>::CreateModel,
    ) -> Result<Self::Resource, ApiError> {
        // 1. Before hook
        self.before_create(db, &data).await?;

        // 2. Core logic (insert)
        let mut entity = self.perform_create(db, data).await?;

        // 3. After hook
        self.after_create(db, &mut entity).await?;

        Ok(entity)
    }

    /// Update an existing entity
    ///
    /// Orchestrates the full update lifecycle:
    /// 1. `before_update` - validation, auth, checking permissions
    /// 2. `perform_update` - database update
    /// 3. `after_update` - notifications, cache invalidation
    ///
    /// # Errors
    ///
    /// Returns `ApiError::NotFound` if the entity doesn't exist
    /// Returns `ApiError` if any hook or database update fails
    async fn update(
        &self,
        db: &DatabaseConnection,
        id: Uuid,
        data: <Self::Resource as CRUDResource>::UpdateModel,
    ) -> Result<Self::Resource, ApiError> {
        // 1. Before hook
        self.before_update(db, id, &data).await?;

        // 2. Core logic (update)
        let mut entity = self.perform_update(db, id, data).await?;

        // 3. After hook
        self.after_update(db, &mut entity).await?;

        Ok(entity)
    }

    /// Delete a single entity by ID
    ///
    /// Orchestrates the full delete lifecycle:
    /// 1. `before_delete` - auth, cleanup of related resources (e.g., S3)
    /// 2. `perform_delete` - database deletion
    /// 3. `after_delete` - notifications, cache invalidation, audit logging
    ///
    /// # Errors
    ///
    /// Returns `ApiError::NotFound` if the entity doesn't exist
    /// Returns `ApiError` if any hook or database deletion fails
    async fn delete(&self, db: &DatabaseConnection, id: Uuid) -> Result<Uuid, ApiError> {
        // 1. Before hook
        self.before_delete(db, id).await?;

        // 2. Core logic (delete)
        let deleted_id = self.perform_delete(db, id).await?;

        // 3. After hook
        self.after_delete(db, deleted_id).await?;

        Ok(deleted_id)
    }

    /// Delete multiple entities by IDs
    ///
    /// Orchestrates the full batch delete lifecycle:
    /// 1. `before_delete_many` - auth, batch validation
    /// 2. `perform_delete_many` - database batch deletion
    /// 3. `after_delete_many` - notifications, cache invalidation
    ///
    /// **Security**: Limited to 100 items by default. Override for different limits.
    ///
    /// # Errors
    ///
    /// Returns `ApiError` if the batch size exceeds the security limit (default: 100)
    /// Returns `ApiError` if any hook or database deletion fails
    async fn delete_many(
        &self,
        db: &DatabaseConnection,
        ids: Vec<Uuid>,
    ) -> Result<Vec<Uuid>, ApiError> {
        // 1. Before hook
        self.before_delete_many(db, &ids).await?;

        // 2. Core logic (batch delete)
        let deleted_ids = self.perform_delete_many(db, ids).await?;

        // 3. After hook
        self.after_delete_many(db, &deleted_ids).await?;

        Ok(deleted_ids)
    }

    /// Create multiple entities in a batch
    ///
    /// Orchestrates the full batch create lifecycle:
    /// 1. Validation via before hooks (per item)
    /// 2. Database batch insertion
    /// 3. After hooks (per item)
    ///
    /// **Security**: Limited to 100 items by default to prevent `DoS`.
    ///
    /// # Errors
    ///
    /// Returns `ApiError` if the batch size exceeds the security limit (default: 100)
    /// Returns `ApiError` if any validation or database insertion fails
    async fn create_many(
        &self,
        db: &DatabaseConnection,
        data: Vec<<Self::Resource as CRUDResource>::CreateModel>,
    ) -> Result<Vec<Self::Resource>, ApiError> {
        Self::Resource::create_many(db, data).await
    }

    /// Update multiple entities in a batch
    ///
    /// Orchestrates the full batch update lifecycle:
    /// 1. Validation via before hooks (per item)
    /// 2. Database batch updates
    /// 3. After hooks (per item)
    ///
    /// **Security**: Limited to 100 items by default to prevent `DoS`.
    ///
    /// # Errors
    ///
    /// Returns `ApiError` if the batch size exceeds the security limit (default: 100)
    /// Returns `ApiError` if any validation or database update fails
    async fn update_many(
        &self,
        db: &DatabaseConnection,
        updates: Vec<(Uuid, <Self::Resource as CRUDResource>::UpdateModel)>,
    ) -> Result<Vec<Self::Resource>, ApiError> {
        Self::Resource::update_many(db, updates).await
    }
}

/// Default CRUD operations implementation
///
/// This struct provides a zero-cost wrapper that delegates all operations to the
/// underlying `CRUDResource` trait. It's used automatically when no custom
/// `operations` attribute is specified.
///
/// ## Usage
///
/// This is used automatically by the derive macro:
///
/// ```rust,ignore
/// #[derive(EntityToModels)]
/// #[crudcrate(generate_router)]  // No operations specified
/// pub struct Todo {
///     pub id: Uuid,
///     pub title: String,
/// }
/// // Automatically uses DefaultCRUDOperations<Todo>
/// ```
pub struct DefaultCRUDOperations<T: CRUDResource> {
    _phantom: std::marker::PhantomData<T>,
}

impl<T: CRUDResource> DefaultCRUDOperations<T> {
    /// Create a new default operations instance
    #[must_use]
    pub const fn new() -> Self {
        Self {
            _phantom: std::marker::PhantomData,
        }
    }
}

impl<T: CRUDResource> Default for DefaultCRUDOperations<T> {
    fn default() -> Self {
        Self::new()
    }
}

#[async_trait]
impl<T: CRUDResource> CRUDOperations for DefaultCRUDOperations<T> {
    type Resource = T;

    // All methods use default implementations from the trait
    // No overrides needed - delegates to T::method() automatically
}