feat(api): Отключена ручаня валидация в контроллере

This commit is contained in:
Mikhail Trubnikov
2026-05-19 16:52:33 +10:00
parent d8af0253b1
commit 8f61bbb73e
13 changed files with 102 additions and 99 deletions

View File

@@ -15,6 +15,7 @@ using PARR.Core.Repositories.Interfaces;
using PARR.Domain.Common.Pagination;
using PARR.Domain.Common.Roles;
using PARR.Domain.Entities;
using PARR.Domain.Exceptions;
namespace PARR.API.Controllers.V1
{
@@ -26,21 +27,21 @@ namespace PARR.API.Controllers.V1
{
private readonly IMapper mapper;
private readonly IUserRepository userService;
private readonly IValidator<UserRequest> validator;
//private readonly IValidator<UserRequest> validator;
private readonly IUriService uriService;
private readonly ILogger<UserController> logger;
public UserController(
IMapper mapper,
IUserRepository userService,
IValidator<UserRequest> validator,
//IValidator<UserRequest> validator,
IUriService uriService,
ILogger<UserController> logger
)
{
this.mapper = mapper;
this.userService = userService;
this.validator = validator;
//this.validator = validator;
this.uriService = uriService;
this.logger = logger;
}
@@ -122,14 +123,16 @@ namespace PARR.API.Controllers.V1
[HttpPost(ApiRoutes.User.Create)]
public async Task<IActionResult> Create([FromBody] UserRequest request)
{
var resultValidate = await validator.ValidateAsync(request);
if (!resultValidate.IsValid)
return BadRequest(new Response(resultValidate.Errors));
//var resultValidate = await validator.ValidateAsync(request);
//if (!resultValidate.IsValid)
// return BadRequest(new Response(resultValidate.Errors));
var existIp = await userService.Get().FirstOrDefaultAsync(t => t.Ip == request.Ip);
if (existIp != null)
//throw new AlreadyExistsException($"Ip {request.Ip} занят другим пользователем.");
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.Ip), Message = $"Ip {request.Ip} занят другим пользователем." } }));
var user = new User
{
Id = Guid.NewGuid(),
@@ -158,9 +161,9 @@ namespace PARR.API.Controllers.V1
[HttpPut(ApiRoutes.User.Update)]
public async Task<IActionResult> Update([FromRoute] Guid id, [FromBody] UserRequest request)
{
var resultValidate = await validator.ValidateAsync(request);
if (!resultValidate.IsValid)
return BadRequest(new Response(resultValidate.Errors));
//var resultValidate = await validator.ValidateAsync(request);
//if (!resultValidate.IsValid)
// return BadRequest(new Response(resultValidate.Errors));
var orig = await userService.Get()
.Include(t => t.Roles).ThenInclude(t => t.Role)