| @@ -5,8 +5,8 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| public interface IUserService | |||
| { | |||
| Task<IEnumerable<User?>> GetAll(); | |||
| Task<User?> GetById(int id); | |||
| Task<User?> GetByEmail(string email); | |||
| Task<User> GetById(int id); | |||
| Task<User> GetByEmail(string email); | |||
| Task CreateUser(CreateUserRequestDto model); | |||
| Task<bool?> ToggleEnable(User user); | |||
| Task RemoveUser(User user); | |||
| @@ -36,14 +36,30 @@ | |||
| return result; | |||
| } | |||
| #region REFACTORING CODE HERE TO CHECK IF USER IS NULL | |||
| public async Task<User?> GetById(int id) | |||
| public async Task<User> GetById(int id) | |||
| { | |||
| _logger.LogInformation($"Start searching user with id = {id}"); | |||
| var result = await _userManager.FindByIdAsync(id.ToString()); | |||
| if (result == null) | |||
| { | |||
| throw new EntityNotFoundException("User not found"); | |||
| } | |||
| return result; | |||
| } | |||
| public async Task<User> GetByEmail(string email) | |||
| { | |||
| _logger.LogInformation($"Start searching user with mail = {email}"); | |||
| var result = await _userManager.FindByEmailAsync(email); | |||
| if (result == null) | |||
| { | |||
| throw new EntityNotFoundException("User not found"); | |||
| } | |||
| return result; | |||
| } | |||
| public async Task<User?> GetByEmail(string email) => | |||
| await _userManager.FindByEmailAsync(email); | |||
| #endregion | |||
| public async Task CreateUser(CreateUserRequestDto model) | |||
| { | |||
| @@ -30,11 +30,6 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| { | |||
| var user = await _userService.GetById(id); | |||
| if (user == null) | |||
| { | |||
| return BadRequest("User not found"); | |||
| } | |||
| await _userService.ToggleEnable(user); | |||
| return Ok(user.Id); | |||
| @@ -46,11 +41,6 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| { | |||
| var user = await _userService.GetById(id); | |||
| if (user == null) | |||
| { | |||
| return BadRequest("User not found"); | |||
| } | |||
| await _userService.RemoveUser(user); | |||
| return Ok(user.Id); | |||
| @@ -62,11 +52,6 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| { | |||
| var user = await _userService.GetById(id); | |||
| if (user == null) | |||
| { | |||
| return BadRequest("User not found"); | |||
| } | |||
| return Ok(_mapper.Map<User, UserDetailsResponseDTO>(user)); | |||
| } | |||