Files
Knots/Knots/Endpoints/User/PatchUserPasswordEndpoint.cs
T

30 lines
833 B
C#

using FastEndpoints;
using Knots.DTO.User;
using Microsoft.EntityFrameworkCore;
namespace Knots.Endpoints.User;
public class PatchUserPasswordEndpoint(KnotsDbContext db, AutoMapper.IMapper mapper) : Endpoint<UpdateUserPasswordDto>
{
public override void Configure()
{
Patch("/users/{@Id}/password/", x => new {x.Id});
AllowAnonymous();
}
public override async Task HandleAsync(UpdateUserPasswordDto req, CancellationToken ct)
{
Models.User? databaseUser = await db.Users.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseUser is null)
{
await SendNotFoundAsync(ct);
return;
}
mapper.Map(req, databaseUser);
await db.SaveChangesAsync(ct);
await SendNoContentAsync(ct);
}
}