Create/update scheduled transactions.
This commit is contained in:
+21
-8
@@ -3,16 +3,20 @@ use axum::{
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
|
||||
use crate::routes::dtos::{
|
||||
scheduled_transaction::RecurringTransactionConversionError,
|
||||
transaction_direction::TransactionDirectionConversionError,
|
||||
use crate::routes::{
|
||||
dtos::{
|
||||
direction::DirectionConversionError,
|
||||
scheduled_transaction::RecurringTransactionConversionError,
|
||||
},
|
||||
validation::scheduled_transaction::ScheduledTransactionValidationError,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AppError {
|
||||
Database(sqlx::Error),
|
||||
TransactionDirection(TransactionDirectionConversionError),
|
||||
Direction(DirectionConversionError),
|
||||
RecurringTransaction(RecurringTransactionConversionError),
|
||||
ScheduledTransactionValidation(ScheduledTransactionValidationError),
|
||||
}
|
||||
|
||||
impl From<sqlx::Error> for AppError {
|
||||
@@ -21,9 +25,9 @@ impl From<sqlx::Error> for AppError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionDirectionConversionError> for AppError {
|
||||
fn from(error: TransactionDirectionConversionError) -> Self {
|
||||
Self::TransactionDirection(error)
|
||||
impl From<DirectionConversionError> for AppError {
|
||||
fn from(error: DirectionConversionError) -> Self {
|
||||
Self::Direction(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,11 +37,20 @@ impl From<RecurringTransactionConversionError> for AppError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ScheduledTransactionValidationError> for AppError {
|
||||
fn from(error: ScheduledTransactionValidationError) -> Self {
|
||||
Self::ScheduledTransactionValidation(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> Response {
|
||||
match self {
|
||||
Self::ScheduledTransactionValidation(error) => {
|
||||
return (StatusCode::UNPROCESSABLE_ENTITY, error.to_string()).into_response();
|
||||
}
|
||||
Self::Database(error) => tracing::error!(%error, "Database query failed"),
|
||||
Self::TransactionDirection(error) => {
|
||||
Self::Direction(error) => {
|
||||
tracing::error!(%error, "Invalid transaction direction")
|
||||
}
|
||||
Self::RecurringTransaction(error) => {
|
||||
|
||||
Reference in New Issue
Block a user