Delete resources.
This commit is contained in:
@@ -19,6 +19,7 @@ pub fn create_router() -> axum::Router<PgPool> {
|
||||
axum::Router::new()
|
||||
.route("/", axum::routing::get(get_scheduled_transactions))
|
||||
.route("/{id}", axum::routing::put(put_scheduled_transaction))
|
||||
.route("/{id}", axum::routing::delete(delete_scheduled_transaction))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(pool))]
|
||||
@@ -133,3 +134,22 @@ async fn put_scheduled_transaction(
|
||||
|
||||
Ok((status, Json(transaction.into())))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn delete_scheduled_transaction(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
let deleted = sqlx::query!(
|
||||
"DELETE FROM recurring_transactions WHERE id = $1 RETURNING id",
|
||||
id
|
||||
)
|
||||
.fetch_optional(&pool)
|
||||
.await?;
|
||||
|
||||
if deleted.is_none() {
|
||||
return Ok(StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
use axum::{Json, extract::State};
|
||||
use axum::{
|
||||
Json,
|
||||
extract::{Path, State},
|
||||
http::StatusCode,
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
database::dtos::transaction::TransactionRow, error::AppError,
|
||||
@@ -7,7 +12,9 @@ use crate::{
|
||||
};
|
||||
|
||||
pub fn create_router() -> axum::Router<PgPool> {
|
||||
axum::Router::new().route("/", axum::routing::get(get_transactions))
|
||||
axum::Router::new()
|
||||
.route("/", axum::routing::get(get_transactions))
|
||||
.route("/{id}", axum::routing::delete(delete_transaction))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(pool))]
|
||||
@@ -32,3 +39,19 @@ async fn get_transactions(
|
||||
|
||||
Ok(Json(transactions))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn delete_transaction(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
let deleted = sqlx::query!("DELETE FROM transactions WHERE id = $1 RETURNING id", id)
|
||||
.fetch_optional(&pool)
|
||||
.await?;
|
||||
|
||||
if deleted.is_none() {
|
||||
return Ok(StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user