34 lines
984 B
C#
34 lines
984 B
C#
using BeReadyBackend.DTO.Users;
|
|
using BeReadyBackend.Models;
|
|
using BeReadyBackend.Repositories;
|
|
using BeReadyBackend.Services;
|
|
using BeReadyBackend.Specifications.Users;
|
|
using FastEndpoints;
|
|
|
|
namespace BeReadyBackend.Endpoints.Users;
|
|
|
|
public class PatchUserDesignationEndpoint(UsersRepository usersRepository, UserService userService, AutoMapper.IMapper mapper) : Endpoint<PatchUserDesignationDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Patch("/Users/Designation");
|
|
}
|
|
|
|
public override async Task HandleAsync(PatchUserDesignationDto req, CancellationToken ct)
|
|
{
|
|
int userId = userService.GetUserIdFromToken();
|
|
|
|
User? user = await usersRepository.SingleOrDefaultAsync(new GetUserByIdSpec(userId), ct);
|
|
|
|
if (user is null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
mapper.Map(req, user);
|
|
|
|
await usersRepository.SaveChangesAsync(ct);
|
|
await Send.NoContentAsync(ct);
|
|
}
|
|
} |