| 12345678910111213141516171819202122232425262728293031 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Microsoft.EntityFrameworkCore;
- using SharedKernel.Results;
- namespace Application.Features.Api.Developers.Apps.UpdateApp;
- internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command, Result>
- {
- public async Task<Result> Handle(Command request, CancellationToken ct)
- {
- if (string.IsNullOrWhiteSpace(request.Name) || request.Name.Length > 100)
- {
- return Result.Failure(Error.Problem("App.NameInvalid", "Name is required (1-100 chars)."));
- }
- 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."));
- }
- app.UpdateInfo(request.Name, request.Description, request.HomepageUrl);
- await db.SaveChangesAsync(ct);
- return Result.Success();
- }
- }
|