refactor(UserController): remove try-catch block
This commit is contained in:
parent
e0683a8d17
commit
5f41e1b604
@ -19,8 +19,6 @@ public class UserController : BaseAuthController<IUserService, UserCreateDto, Us
|
|||||||
|
|
||||||
[HttpGet("ByModuleId/{moduleId}")]
|
[HttpGet("ByModuleId/{moduleId}")]
|
||||||
public async Task<IActionResult> GetByModuleId([FromRoute] int moduleId, [FromQuery] bool assigned = true)
|
public async Task<IActionResult> GetByModuleId([FromRoute] int moduleId, [FromQuery] bool assigned = true)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
return await (assigned ? _service.ReadByModuleIdAsync(moduleId) : _service.ReadUnassignedByModuleIdAsync(moduleId))
|
return await (assigned ? _service.ReadByModuleIdAsync(moduleId) : _service.ReadUnassignedByModuleIdAsync(moduleId))
|
||||||
.ThenAsync(Ok, IActionResult (m, n) =>
|
.ThenAsync(Ok, IActionResult (m, n) =>
|
||||||
@ -29,17 +27,9 @@ public class UserController : BaseAuthController<IUserService, UserCreateDto, Us
|
|||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("ByGroupId/{groupId}")]
|
[HttpGet("ByGroupId/{groupId}")]
|
||||||
public async Task<IActionResult> GetByGroupId([FromRoute] int groupId, [FromQuery] bool assigned = true)
|
public async Task<IActionResult> GetByGroupId([FromRoute] int groupId, [FromQuery] bool assigned = true)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
return await (assigned ? _service.ReadByGroupIdAsync(groupId) : _service.ReadUnassignedByGroupIdAsync(groupId))
|
return await (assigned ? _service.ReadByGroupIdAsync(groupId) : _service.ReadUnassignedByGroupIdAsync(groupId))
|
||||||
.ThenAsync(Ok, IActionResult (m, n) =>
|
.ThenAsync(Ok, IActionResult (m, n) =>
|
||||||
@ -48,17 +38,9 @@ public class UserController : BaseAuthController<IUserService, UserCreateDto, Us
|
|||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("ByDir")]
|
[HttpPost("ByDir")]
|
||||||
public async Task<IActionResult> CreateByDir(UserPrincipalDto upDto)
|
public async Task<IActionResult> CreateByDir(UserPrincipalDto upDto)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
return await _service.CreateAsync(upDto).ThenAsync(
|
return await _service.CreateAsync(upDto).ThenAsync(
|
||||||
Success: id =>
|
Success: id =>
|
||||||
@ -74,17 +56,9 @@ public class UserController : BaseAuthController<IUserService, UserCreateDto, Us
|
|||||||
return BadRequest();
|
return BadRequest();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("ByUsername/{username}")]
|
[HttpGet("ByUsername/{username}")]
|
||||||
public virtual async Task<IActionResult> GetByUsername([FromRoute] string username)
|
public virtual async Task<IActionResult> GetByUsername([FromRoute] string username)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
return await _service.ReadByUsernameAsync(username).ThenAsync(Ok, IActionResult (m, n) =>
|
return await _service.ReadByUsernameAsync(username).ThenAsync(Ok, IActionResult (m, n) =>
|
||||||
{
|
{
|
||||||
@ -92,10 +66,4 @@ public class UserController : BaseAuthController<IUserService, UserCreateDto, Us
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user