feat(api): Отключена ручаня валидация в контроллере
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user