forked from sanchezvem/pyrofetes-backend
Refactor all code
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.User.Request;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
using PyroFetes.Models;
|
||||
@@ -8,9 +7,7 @@ using PyroFetes.Specifications.Users;
|
||||
|
||||
namespace PyroFetes.Endpoints.Users;
|
||||
|
||||
public class PatchUserPasswordEndpoint(
|
||||
UsersRepository usersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchUserPasswordDto, GetUserDto>
|
||||
public class PatchUserPasswordEndpoint(UsersRepository usersRepository,AutoMapper.IMapper mapper) : Endpoint<PatchUserPasswordDto, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -20,9 +17,9 @@ public class PatchUserPasswordEndpoint(
|
||||
|
||||
public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct)
|
||||
{
|
||||
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||
|
||||
if (user == null)
|
||||
User? user = await usersRepository.SingleOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||
|
||||
if (user is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
@@ -30,7 +27,7 @@ public class PatchUserPasswordEndpoint(
|
||||
|
||||
user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + user.Salt);
|
||||
await usersRepository.UpdateAsync(user, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user