using Application.Abstractions.Data; using Application.Abstractions.Messaging; using Microsoft.EntityFrameworkCore; using SharedKernel.Results; namespace Application.Features.Api.Developers.Apps.DeleteApp; internal sealed class Handler(IAppDbContext db) : ICommandHandler { public async Task Handle(Command request, CancellationToken ct) { var app = await db.ApiApplication .AsTracking() .FirstOrDefaultAsync(c => c.ID == request.AppID && c.OwnerMemberID == request.OwnerMemberID, ct); if (app is null) { return Result.Failure(Error.NotFound("App.NotFound", "App not found.")); } // Cascade delete: Configurations 에 OnDelete=Cascade 로 설정됨 → Credentials/Scopes/RateLimit 자동 삭제 db.ApiApplication.Remove(app); await db.SaveChangesAsync(ct); return Result.Success(); } }