Some more cleanup.
This commit is contained in:
@@ -4,13 +4,11 @@ mod recurring_transaction;
|
||||
mod schedule;
|
||||
mod transaction;
|
||||
|
||||
pub use cents::{Cents, CentsError};
|
||||
pub use direction::Direction;
|
||||
pub use recurring_transaction::RecurringTransaction;
|
||||
pub use schedule::{
|
||||
Recurrence, RecurrenceInterval, RecurrenceUnit, Schedule, ScheduleError, WeekendAdjustment,
|
||||
};
|
||||
pub use transaction::Transaction;
|
||||
pub use cents::*;
|
||||
pub use direction::*;
|
||||
pub use recurring_transaction::*;
|
||||
pub use schedule::*;
|
||||
pub use transaction::*;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum DomainError {
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ impl IntoResponse for AppError {
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct ErrorResponse {
|
||||
struct ErrorResponse {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
@@ -60,6 +60,6 @@ impl ErrorResponse {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error_response(status_code: StatusCode, message: impl Into<String>) -> Response {
|
||||
fn error_response(status_code: StatusCode, message: impl Into<String>) -> Response {
|
||||
(status_code, axum::Json(ErrorResponse::new(message))).into_response()
|
||||
}
|
||||
|
||||
+12
-14
@@ -1,3 +1,5 @@
|
||||
use axum::{http::StatusCode, routing::get};
|
||||
|
||||
use crate::error::AppError;
|
||||
|
||||
pub mod dtos;
|
||||
@@ -6,20 +8,16 @@ pub mod scheduled_transactions;
|
||||
pub mod transactions;
|
||||
|
||||
pub fn create_router(pool: sqlx::PgPool) -> axum::Router {
|
||||
let scheduled_transactions = scheduled_transactions::create_router();
|
||||
let transactions = transactions::create_router();
|
||||
|
||||
let api = axum::Router::new()
|
||||
.nest("/scheduled-transactions", scheduled_transactions)
|
||||
.nest("/transactions", transactions);
|
||||
|
||||
axum::Router::new()
|
||||
.nest(
|
||||
"/api",
|
||||
axum::Router::new()
|
||||
.nest(
|
||||
"/scheduled-transactions",
|
||||
scheduled_transactions::create_router(),
|
||||
)
|
||||
.nest("/transactions", transactions::create_router()),
|
||||
)
|
||||
.fallback(handle_fallback)
|
||||
.nest("/api", api)
|
||||
.route("/health", get(async || StatusCode::NO_CONTENT))
|
||||
.fallback(async || AppError::NotFound)
|
||||
.with_state(pool)
|
||||
}
|
||||
|
||||
async fn handle_fallback() -> AppError {
|
||||
AppError::NotFound
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ use crate::{
|
||||
|
||||
pub fn create_router() -> axum::Router<PgPool> {
|
||||
axum::Router::new()
|
||||
.route("/", axum::routing::get(get_scheduled_transactions))
|
||||
.route("/", axum::routing::get(query_scheduled_transactions))
|
||||
.route(
|
||||
"/{id}",
|
||||
axum::routing::get(get_scheduled_transaction)
|
||||
.put(put_scheduled_transaction)
|
||||
.put(upsert_scheduled_transaction)
|
||||
.delete(delete_scheduled_transaction),
|
||||
)
|
||||
}
|
||||
@@ -49,7 +49,7 @@ impl TryFrom<QueryParams> for repository::Query {
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_scheduled_transactions(
|
||||
async fn query_scheduled_transactions(
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<ScheduledTransactionResponse>>, AppError> {
|
||||
@@ -78,7 +78,7 @@ async fn get_scheduled_transaction(
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool, transaction))]
|
||||
async fn put_scheduled_transaction(
|
||||
async fn upsert_scheduled_transaction(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(transaction): Json<ScheduledTransactionRequest>,
|
||||
|
||||
@@ -17,11 +17,11 @@ use crate::{
|
||||
|
||||
pub fn create_router() -> axum::Router<PgPool> {
|
||||
axum::Router::new()
|
||||
.route("/", axum::routing::get(get_transactions))
|
||||
.route("/", axum::routing::get(query_transactions))
|
||||
.route(
|
||||
"/{id}",
|
||||
axum::routing::get(get_transaction)
|
||||
.put(put_transaction)
|
||||
.put(upsert_transaction)
|
||||
.delete(delete_transaction),
|
||||
)
|
||||
}
|
||||
@@ -45,7 +45,7 @@ impl TryFrom<QueryParams> for repository::Query {
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_transactions(
|
||||
async fn query_transactions(
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<TransactionResponse>>, AppError> {
|
||||
@@ -73,7 +73,7 @@ async fn get_transaction(
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool, transaction))]
|
||||
async fn put_transaction(
|
||||
async fn upsert_transaction(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(transaction): Json<TransactionRequest>,
|
||||
|
||||
Reference in New Issue
Block a user