diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/ChatWorkshopController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/ChatWorkshopController.cs index 91a7721639..4daa540f7e 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/ChatWorkshopController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/ChatWorkshopController.cs @@ -209,7 +209,7 @@ public Task GetMessagesForMinistryAdminByRoomIdAsync(Guid id, [Fr [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public Task GetParentsRoomsAsync([FromQuery]ChatWorkshopFilter filter = null) + public Task GetParentsRoomsAsync([FromQuery] ChatWorkshopFilter filter = null) => this.GetUsersRoomsAsync(parentId => roomService.GetByParentIdAsync(parentId), filter); /// @@ -319,32 +319,36 @@ async Task Operation() private async Task GetOrCreateRoomByApplicationIdAsync(Guid applicationId) { - logger.LogInformation($"User {GettingUserProperties.GetUserId(HttpContext)} is trying to get chat room by {nameof(applicationId)} = {applicationId}"); - var application = await applicationService.GetById(applicationId); - - if (application is null) + async Task Operation() { - logger.LogWarning($"User {GettingUserProperties.GetUserId(HttpContext)} is trying to get chat room by {nameof(applicationId)} = {applicationId} but it is not exist"); - return BadRequest(); - } + logger.LogInformation($"User {GettingUserProperties.GetUserId(HttpContext)} is trying to get chat room by {nameof(applicationId)} = {applicationId}"); + var application = await applicationService.GetById(applicationId); - var userHasRights = await IsUserHasRightsForApplicationAsync(application); + if (application is null) + { + return NoContent(); + } - if (!userHasRights) - { - logger.LogWarning($"User {GettingUserProperties.GetUserId(HttpContext)} is trying to get chat room by {nameof(applicationId)} = {applicationId} with no rights"); - return BadRequest(); - } + var userHasRights = await IsUserHasRightsForApplicationAsync(application); - var chatroom = roomService.CreateOrReturnExistingAsync(application.WorkshopId, application.ParentId); + if (!userHasRights) + { + logger.LogWarning($"User {GettingUserProperties.GetUserId(HttpContext)} is trying to get chat room by {nameof(applicationId)} = {applicationId} with no rights"); + return BadRequest(); + } - if (chatroom is null) - { - logger.LogWarning($"User {GettingUserProperties.GetUserId(HttpContext)} is trying to get chat room by {nameof(applicationId)} = {applicationId} but get null"); - return BadRequest(); + var chatroom = roomService.CreateOrReturnExistingAsync(application.WorkshopId, application.ParentId); + + if (chatroom is null) + { + logger.LogWarning($"User {GettingUserProperties.GetUserId(HttpContext)} is trying to get chat room by {nameof(applicationId)} = {applicationId} but get null"); + return BadRequest(); + } + + return Ok(chatroom); } - return Ok(chatroom); + return await HandleOperationAsync(Operation); } private async Task IsUserHasRightsForApplicationAsync(ApplicationDto application)