Handler.cs 929 B

123456789101112131415161718192021222324252627
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using Microsoft.EntityFrameworkCore;
  4. using SharedKernel.Results;
  5. namespace Application.Features.Api.Developers.Apps.DeleteApp;
  6. internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command, Result>
  7. {
  8. public async Task<Result> Handle(Command request, CancellationToken ct)
  9. {
  10. var app = await db.ApiApplication
  11. .AsTracking()
  12. .FirstOrDefaultAsync(c => c.ID == request.AppID && c.OwnerMemberID == request.OwnerMemberID, ct);
  13. if (app is null)
  14. {
  15. return Result.Failure(Error.NotFound("App.NotFound", "App not found."));
  16. }
  17. // Cascade delete: Configurations 에 OnDelete=Cascade 로 설정됨 → Credentials/Scopes/RateLimit 자동 삭제
  18. db.ApiApplication.Remove(app);
  19. await db.SaveChangesAsync(ct);
  20. return Result.Success();
  21. }
  22. }