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