fix: контроллеры
добавлен try catch в контроллер пользователя, рефактор контроллер авторизации
This commit is contained in:
parent
078b469752
commit
43b00bfc2f
@ -4,12 +4,12 @@ using Contracts.ViewModels;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Services.Support.Exceptions;
|
using Services.Support.Exceptions;
|
||||||
|
|
||||||
namespace Controllers.Controllers
|
namespace Controllers.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class AuthController : ControllerBase
|
||||||
{
|
{
|
||||||
[ApiController]
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
public class AuthController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly IAuthService _authService;
|
private readonly IAuthService _authService;
|
||||||
|
|
||||||
public AuthController(IAuthService authService)
|
public AuthController(IAuthService authService)
|
||||||
@ -60,5 +60,4 @@ namespace Controllers.Controllers
|
|||||||
return StatusCode(500, ex.Message);
|
return StatusCode(500, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -3,42 +3,71 @@ using Contracts.SearchModels;
|
|||||||
using Contracts.Services;
|
using Contracts.Services;
|
||||||
using Contracts.ViewModels;
|
using Contracts.ViewModels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Services.Support.Exceptions;
|
||||||
|
|
||||||
namespace Controllers.Controllers
|
namespace Controllers.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class UserController : ControllerBase
|
||||||
{
|
{
|
||||||
[ApiController]
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
public class UserController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
|
|
||||||
public UserController(IUserService userService)
|
public UserController(IUserService userService)
|
||||||
{
|
{
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<UserViewModel>> GetUser([FromQuery] UserSearch search)
|
public async Task<ActionResult<UserViewModel>> GetUser([FromQuery] UserSearch search)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var user = await _userService.GetDetails(search);
|
var user = await _userService.GetDetails(search);
|
||||||
|
|
||||||
return Ok(user);
|
return Ok(user);
|
||||||
}
|
}
|
||||||
|
catch (UserNotFoundException ex)
|
||||||
|
{
|
||||||
|
return NotFound(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPut]
|
[HttpPatch]
|
||||||
public async Task<ActionResult<UserViewModel>> UpdateUser([FromBody] UserDto user)
|
public async Task<ActionResult<UserViewModel>> UpdateUser([FromBody] UserDto user)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var updatedUser = await _userService.UpdateUserData(user);
|
var updatedUser = await _userService.UpdateUserData(user);
|
||||||
|
|
||||||
return Ok(updatedUser);
|
return Ok(updatedUser);
|
||||||
}
|
}
|
||||||
|
catch (UserNotFoundException ex)
|
||||||
|
{
|
||||||
|
return NotFound(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpDelete]
|
[HttpDelete]
|
||||||
public async Task<ActionResult<UserViewModel>> DeleteUser([FromQuery] UserSearch search)
|
public async Task<ActionResult<UserViewModel>> DeleteUser([FromQuery] UserSearch search)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var deletedUser = await _userService.Delete(search);
|
var deletedUser = await _userService.Delete(search);
|
||||||
|
|
||||||
return Ok(deletedUser);
|
return Ok(deletedUser);
|
||||||
}
|
}
|
||||||
|
catch (UserNotFoundException ex)
|
||||||
|
{
|
||||||
|
return NotFound(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user