refactor(GroupOfUserController): remove try-catch block
This commit is contained in:
parent
d252859b11
commit
dda2f25b57
@ -14,68 +14,44 @@ public class GroupOfUserController : BaseAuthController<IGroupOfUserService, Gro
|
||||
public GroupOfUserController(ILogger<GroupOfUserController> logger, IGroupOfUserService service, IUserService userService) : base(logger, service, userService)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete]
|
||||
public async Task<IActionResult> Delete([FromQuery] int groupId, [FromQuery] int userId)
|
||||
{
|
||||
try
|
||||
return await _service.DeleteAsyncByGroupUserId(groupId, userId).ThenAsync(Ok, IActionResult (m, n) =>
|
||||
{
|
||||
return await _service.DeleteAsyncByGroupUserId(groupId, userId).ThenAsync(Ok, IActionResult (m, n) =>
|
||||
{
|
||||
_logger.LogNotice(n);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
_logger.LogNotice(n);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public override Task<IActionResult> GetAll() => base.GetAll();
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery]bool withUser = false, [FromQuery]bool withGroup = false, [FromQuery] string? username = null)
|
||||
public async Task<IActionResult> GetAll([FromQuery] bool withUser = false, [FromQuery] bool withGroup = false, [FromQuery] string? username = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (username is not null)
|
||||
return await _service.ReadByUsernameAsync(username).ThenAsync(Ok, IActionResult (m, n) =>
|
||||
{
|
||||
_logger.LogNotice(n);
|
||||
return NotFound();
|
||||
});
|
||||
|
||||
return await _service.ReadAllAsyncWith(withUser, withGroup).ThenAsync(Ok, IActionResult (m, n) =>
|
||||
if (username is not null)
|
||||
return await _service.ReadByUsernameAsync(username).ThenAsync(Ok, IActionResult (m, n) =>
|
||||
{
|
||||
_logger.LogNotice(n);
|
||||
return NotFound();
|
||||
});
|
||||
}
|
||||
catch(Exception ex)
|
||||
|
||||
return await _service.ReadAllAsyncWith(withUser, withGroup).ThenAsync(Ok, IActionResult (m, n) =>
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
_logger.LogNotice(n);
|
||||
return NotFound();
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("Has")]
|
||||
public async Task<IActionResult> HasGroup([FromQuery] string username, [FromQuery] string groupname)
|
||||
{
|
||||
try
|
||||
return await _service.HasGroup(username, groupname).ThenAsync(Ok, (m, n) =>
|
||||
{
|
||||
return await _service.HasGroup(username, groupname).ThenAsync(Ok, (m, n) =>
|
||||
{
|
||||
_logger.LogNotice(n);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
});
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
_logger.LogNotice(n);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user