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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user