Skip to main content

Module service

Module service 

Source
Expand description

Generic CRUD service — one implementation used by all entities.

Generated code emits only a type alias:

ⓘ
// Generated (was ~250 lines, now 1 line):
pub type StoredFileService = GenericCrudService<
    StoredFile,
    CreateStoredFileDto,
    UpdateStoredFileDto,
    PostgresStoredFileRepository,
>;

Custom services wrap the alias with a decorator:

ⓘ
pub struct StoredFileServiceCustom {
    inner: Arc<StoredFileService>,
    notifications: Arc<NotificationService>,
}

impl StoredFileServiceCustom {
    pub async fn archive(&self, id: &str, reason: String) -> ServiceResult<StoredFile> {
        let entity = self.inner.get_by_id(id).await?.ok_or(ServiceError::NotFound)?;
        // custom business logic
    }
}

Structs§

GenericCrudService
A fully generic CRUD service.
NoOpLifecycle
No-op lifecycle — the default used by generated type aliases.

Enums§

ServiceError
Standard service-layer error type.

Constants§

MAX_BATCH_SIZE
Maximum number of ids / items a single batch operation may contain. Enforced here at the service layer (not only in the HTTP handlers) so every caller — gRPC, background jobs, internal code — gets the same bound.

Traits§

ApplyUpdateDto
Apply an Update DTO’s fields to an existing entity (full update).
FromCreateDto
Convert a Create DTO into a new entity instance.
ServiceLifecycle
Optional lifecycle callbacks injected into GenericCrudService.

Type Aliases§

ServiceResult