feat(infra): add delete endpoint for transactions with corresponding integration tests

This commit is contained in:
Stevan Freeborn
2026-03-12 17:29:41 -05:00
parent f0c63c7ded
commit e47e08b9f0
3 changed files with 156 additions and 0 deletions
@@ -0,0 +1,34 @@
namespace FiscalOS.API.Transactions.DeleteById;
internal static class Endpoint
{
private const string Route = "/{id}";
public static RouteHandlerBuilder MapDeleteEndpoint(this RouteGroupBuilder groupBuilder)
{
return groupBuilder.MapDelete(Route, HandleAsync);
}
private static async Task<IResult> HandleAsync(
HttpContext httpContext,
[FromRoute] Guid id,
[FromServices] AppDbContext appDbContext,
CancellationToken ct
)
{
var userId = httpContext.GetUserId();
var existingTransaction = await appDbContext.Transactions
.SingleOrDefaultAsync(t => t.UserId == userId && t.Id == id, ct);
if (existingTransaction is null)
{
return Results.NotFound();
}
appDbContext.Transactions.Remove(existingTransaction);
await appDbContext.SaveChangesAsync(ct);
return Results.NoContent();
}
}
@@ -1,3 +1,4 @@
using FiscalOS.API.Transactions.DeleteById;
using FiscalOS.API.Transactions.FireWebhook;
using FiscalOS.API.Transactions.Get;
using FiscalOS.API.Transactions.Webhook;
@@ -14,6 +15,7 @@ internal static class TransactionsExtensions
.RequireAuthorization();
transactionsGroup.MapGetEndpoint();
transactionsGroup.MapDeleteEndpoint();
transactionsGroup.MapWebhookEndpoint().AllowAnonymous();
if (app.Environment.IsProduction() is false)