95 lines
2.0 KiB
Rust
95 lines
2.0 KiB
Rust
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("reference violation ({kind}: {relation})")]
|
|
ReferenceViolation {
|
|
relation: ReferenceRelation,
|
|
kind: ReferenceViolationKind,
|
|
#[source]
|
|
source: DatabaseError,
|
|
},
|
|
|
|
#[error(transparent)]
|
|
QueryConversion(#[from] QueryConversionError),
|
|
}
|
|
|
|
impl From<sqlx::Error> 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),
|
|
}
|