| 12345678910111213141516171819202122232425262728293031 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Microsoft.EntityFrameworkCore;
- using SharedKernel.Results;
- namespace Application.Features.Api.Developers.Tokens.RevokePat;
- internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command, Result>
- {
- public async Task<Result> Handle(Command request, CancellationToken ct)
- {
- var pat = await db.ApiPersonalAccessToken
- .AsTracking()
- .FirstOrDefaultAsync(c => c.ID == request.PatID && c.OwnerMemberID == request.OwnerMemberID, ct);
- if (pat is null)
- {
- return Result.Failure(Error.NotFound("Pat.NotFound", "PAT not found."));
- }
- if (pat.IsRevoked)
- {
- return Result.Failure(Error.Conflict("Pat.AlreadyRevoked", "PAT already revoked."));
- }
- pat.Revoke();
- await db.SaveChangesAsync(ct);
- return Result.Success();
- }
- }
|