Added get scheduled transaction.

This commit is contained in:
2026-09-25 15:41:40 +02:00
parent 251f6ac3f4
commit adf6888cc7
3 changed files with 31 additions and 4 deletions
+4
View File
@@ -14,6 +14,9 @@ use crate::routes::{
#[derive(Debug, thiserror::Error)]
pub enum AppError {
#[error("not found")]
NotFound,
#[error("database error")]
Database(#[from] sqlx::Error),
@@ -33,6 +36,7 @@ pub enum AppError {
impl IntoResponse for AppError {
fn into_response(self) -> Response {
match self {
Self::NotFound => return StatusCode::NOT_FOUND.into_response(),
Self::ScheduledTransactionValidation(error) => {
return (StatusCode::UNPROCESSABLE_ENTITY, error.to_string()).into_response();
}
+25 -4
View File
@@ -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,
+2
View File
@@ -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>,