refactor(UserController): remove try-catch block

This commit is contained in:
Developer 02 2025-08-05 19:50:04 +02:00
parent e0683a8d17
commit 5f41e1b604

View File

@ -18,28 +18,18 @@ public class UserController : BaseAuthController<IUserService, UserCreateDto, Us
}
[HttpGet("ByModuleId/{moduleId}")]
public async Task<IActionResult> GetByModuleId([FromRoute] int moduleId, [FromQuery]bool assigned = true)
{
try
public async Task<IActionResult> GetByModuleId([FromRoute] int moduleId, [FromQuery] bool assigned = true)
{
return await (assigned ? _service.ReadByModuleIdAsync(moduleId) : _service.ReadUnassignedByModuleIdAsync(moduleId))
.ThenAsync(Ok, IActionResult(m, n) =>
.ThenAsync(Ok, IActionResult (m, n) =>
{
_logger.LogNotice(n);
return StatusCode(StatusCodes.Status500InternalServerError);
});
}
catch(Exception ex)
{
_logger.LogError(ex, "{Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[HttpGet("ByGroupId/{groupId}")]
public async Task<IActionResult> GetByGroupId([FromRoute] int groupId, [FromQuery] bool assigned = true)
{
try
{
return await (assigned ? _service.ReadByGroupIdAsync(groupId) : _service.ReadUnassignedByGroupIdAsync(groupId))
.ThenAsync(Ok, IActionResult (m, n) =>
@ -48,17 +38,9 @@ public class UserController : BaseAuthController<IUserService, UserCreateDto, Us
return StatusCode(StatusCodes.Status500InternalServerError);
});
}
catch(Exception ex)
{
_logger.LogError(ex, "{Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[HttpPost("ByDir")]
public async Task<IActionResult> CreateByDir(UserPrincipalDto upDto)
{
try
{
return await _service.CreateAsync(upDto).ThenAsync(
Success: id =>
@ -74,17 +56,9 @@ public class UserController : BaseAuthController<IUserService, UserCreateDto, Us
return BadRequest();
});
}
catch(Exception ex)
{
_logger.LogError(ex, "{Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[HttpGet("ByUsername/{username}")]
public virtual async Task<IActionResult> GetByUsername([FromRoute] string username)
{
try
{
return await _service.ReadByUsernameAsync(username).ThenAsync(Ok, IActionResult (m, n) =>
{
@ -92,10 +66,4 @@ public class UserController : BaseAuthController<IUserService, UserCreateDto, Us
return NotFound();
});
}
catch(Exception ex)
{
_logger.LogError(ex, "{Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
}