Added get scheduled transaction.
This commit is contained in:
@@ -12,8 +12,8 @@ use crate::{
|
||||
common::{Delete, Upsert},
|
||||
dtos::recurring_transaction::RecurringTransactionRow,
|
||||
recurring_transactions::{
|
||||
delete_scheduled_transaction_by_id, query_scheduled_transactions,
|
||||
upsert_scheduled_transaction,
|
||||
delete_scheduled_transaction_by_id, get_scheduled_transaction_by_id,
|
||||
query_scheduled_transactions, upsert_scheduled_transaction,
|
||||
},
|
||||
},
|
||||
error::AppError,
|
||||
@@ -25,10 +25,12 @@ use crate::{
|
||||
pub fn create_router() -> axum::Router<PgPool> {
|
||||
axum::Router::new()
|
||||
.route("/", axum::routing::get(get_scheduled_transactions))
|
||||
.route("/{id}", axum::routing::get(get_scheduled_transaction))
|
||||
.route("/{id}", axum::routing::put(put_scheduled_transaction))
|
||||
.route("/{id}", axum::routing::delete(delete_scheduled_transaction))
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_scheduled_transactions(
|
||||
State(pool): State<PgPool>,
|
||||
@@ -44,10 +46,28 @@ async fn get_scheduled_transactions(
|
||||
Ok(Json(transactions))
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_scheduled_transaction(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<ScheduledTransaction>, AppError> {
|
||||
let row = get_scheduled_transaction_by_id(&pool, id)
|
||||
.await?
|
||||
.map(|t| RecurringTransaction::try_from(t))
|
||||
.transpose()?;
|
||||
|
||||
match row {
|
||||
Some(transaction) => Ok(Json(ScheduledTransaction::from(transaction))),
|
||||
None => Err(AppError::NotFound),
|
||||
}
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool, transaction))]
|
||||
async fn put_scheduled_transaction(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(transaction): Json<ScheduledTransactionData>,
|
||||
) -> Result<(StatusCode, Json<ScheduledTransaction>), AppError> {
|
||||
let ScheduledTransactionData::Recurring(transaction) = transaction;
|
||||
@@ -76,10 +96,11 @@ async fn put_scheduled_transaction(
|
||||
Ok((status, Json(transaction.into())))
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn delete_scheduled_transaction(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
Ok(match delete_scheduled_transaction_by_id(&pool, id).await? {
|
||||
Delete::Deleted => StatusCode::NO_CONTENT,
|
||||
|
||||
@@ -17,6 +17,7 @@ pub fn create_router() -> axum::Router<PgPool> {
|
||||
.route("/{id}", axum::routing::delete(delete_transaction))
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_transactions(
|
||||
State(pool): State<PgPool>,
|
||||
@@ -40,6 +41,7 @@ async fn get_transactions(
|
||||
Ok(Json(transactions))
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn delete_transaction(
|
||||
Path(id): Path<Uuid>,
|
||||
|
||||
Reference in New Issue
Block a user