Handler.cs 1.0 KB

12345678910111213141516171819202122232425262728293031
  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.UpdateApp;
  6. internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command, Result>
  7. {
  8. public async Task<Result> Handle(Command request, CancellationToken ct)
  9. {
  10. if (string.IsNullOrWhiteSpace(request.Name) || request.Name.Length > 100)
  11. {
  12. return Result.Failure(Error.Problem("App.NameInvalid", "Name is required (1-100 chars)."));
  13. }
  14. var app = await db.ApiApplication
  15. .AsTracking()
  16. .FirstOrDefaultAsync(c => c.ID == request.AppID && c.OwnerMemberID == request.OwnerMemberID, ct);
  17. if (app is null)
  18. {
  19. return Result.Failure(Error.NotFound("App.NotFound", "App not found."));
  20. }
  21. app.UpdateInfo(request.Name, request.Description, request.HomepageUrl);
  22. await db.SaveChangesAsync(ct);
  23. return Result.Success();
  24. }
  25. }