fix: контроллеры
добавлен try catch в контроллер пользователя, рефактор контроллер авторизации
This commit is contained in:
parent
078b469752
commit
43b00bfc2f
@ -4,8 +4,8 @@ using Contracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Services.Support.Exceptions;
|
||||
|
||||
namespace Controllers.Controllers
|
||||
{
|
||||
namespace Controllers.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class AuthController : ControllerBase
|
||||
@ -61,4 +61,3 @@ namespace Controllers.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,10 @@ using Contracts.SearchModels;
|
||||
using Contracts.Services;
|
||||
using Contracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Services.Support.Exceptions;
|
||||
|
||||
namespace Controllers.Controllers;
|
||||
|
||||
namespace Controllers.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class UserController : ControllerBase
|
||||
@ -16,29 +17,57 @@ namespace Controllers.Controllers
|
||||
{
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<UserViewModel>> GetUser([FromQuery] UserSearch search)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await _userService.GetDetails(search);
|
||||
|
||||
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)
|
||||
{
|
||||
try
|
||||
{
|
||||
var updatedUser = await _userService.UpdateUserData(user);
|
||||
|
||||
return Ok(updatedUser);
|
||||
}
|
||||
catch (UserNotFoundException ex)
|
||||
{
|
||||
return NotFound(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public async Task<ActionResult<UserViewModel>> DeleteUser([FromQuery] UserSearch search)
|
||||
{
|
||||
try
|
||||
{
|
||||
var deletedUser = await _userService.Delete(search);
|
||||
|
||||
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