use crate::{ database::DatabaseError, domain::{CentsError, ScheduleError}, }; pub mod accounts; pub mod dtos; mod encoding; pub mod recurring_transactions; pub mod tokens; pub mod transactions; pub mod user_app_secrets; pub mod user_apps; pub mod users; #[derive(Debug, thiserror::Error)] pub enum RepositoryError { #[error(transparent)] Database(#[from] DatabaseError), #[error(transparent)] Decode(#[from] DecodeError), #[error("{relation} cannot be found")] NotFound { relation: ReferenceRelation }, #[error("{relation} is owned by another user")] OwnershipConflict { relation: ReferenceRelation }, #[error("reference violation ({kind}: {relation})")] ReferenceViolation { relation: ReferenceRelation, kind: ReferenceViolationKind, #[source] source: DatabaseError, }, #[error(transparent)] QueryConversion(#[from] QueryConversionError), } impl From for RepositoryError { fn from(error: sqlx::Error) -> Self { Self::Database(DatabaseError::from(error)) } } #[derive(Debug, thiserror::Error)] pub enum DecodeError { #[error(transparent)] Amount(#[from] CentsError), #[error("invalid direction value: {0}")] Direction(String), #[error("invalid recurrence_unit value: {0}")] RecurrenceUnit(String), #[error(transparent)] Schedule(#[from] ScheduleError), #[error("invalid weekend_adjustment value: {0}")] WeekendAdjustment(String), } #[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)] pub enum ReferenceRelation { #[error("account")] Account, #[error("transaction")] Transaction, #[error("user")] User, #[error("user app")] UserApp, #[error("recurring transaction")] RecurringTransaction, } #[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)] pub enum ReferenceViolationKind { #[error("missing")] Missing, #[error("still referenced")] StillReferenced, } #[derive(Debug, thiserror::Error)] pub enum QueryConversionError { #[error("failed to convert limit: {0}")] Limit(u64), #[error("failed to convert offset: {0}")] Offset(u64), }