Delete resources.
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "DELETE FROM recurring_transactions WHERE id = $1 RETURNING id",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "id",
|
||||||
|
"type_info": "Uuid"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Uuid"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "20f1027f06ea416d4f0d0a5b231ec8dde2291c3c49a937a8fa4612646e191420"
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "DELETE FROM transactions WHERE id = $1 RETURNING id",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "id",
|
||||||
|
"type_info": "Uuid"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Uuid"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "3093183e1ab856c510b7a6a32c05210f18f845cb70fc3e5882dd38db4f23ec14"
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ pub fn create_router() -> axum::Router<PgPool> {
|
|||||||
axum::Router::new()
|
axum::Router::new()
|
||||||
.route("/", axum::routing::get(get_scheduled_transactions))
|
.route("/", axum::routing::get(get_scheduled_transactions))
|
||||||
.route("/{id}", axum::routing::put(put_scheduled_transaction))
|
.route("/{id}", axum::routing::put(put_scheduled_transaction))
|
||||||
|
.route("/{id}", axum::routing::delete(delete_scheduled_transaction))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(pool))]
|
#[tracing::instrument(skip(pool))]
|
||||||
@@ -133,3 +134,22 @@ async fn put_scheduled_transaction(
|
|||||||
|
|
||||||
Ok((status, Json(transaction.into())))
|
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 sqlx::PgPool;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::dtos::transaction::TransactionRow, error::AppError,
|
database::dtos::transaction::TransactionRow, error::AppError,
|
||||||
@@ -7,7 +12,9 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn create_router() -> axum::Router<PgPool> {
|
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))]
|
#[tracing::instrument(skip(pool))]
|
||||||
@@ -32,3 +39,19 @@ async fn get_transactions(
|
|||||||
|
|
||||||
Ok(Json(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