Skip to content

Commit

Permalink
Fix for ChatWorkshopController
Browse files Browse the repository at this point in the history
  • Loading branch information
min4uk committed Sep 22, 2023
1 parent 902d2d4 commit 932264b
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public Task<IActionResult> GetMessagesForMinistryAdminByRoomIdAsync(Guid id, [Fr
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public Task<IActionResult> GetParentsRoomsAsync([FromQuery]ChatWorkshopFilter filter = null)
public Task<IActionResult> GetParentsRoomsAsync([FromQuery] ChatWorkshopFilter filter = null)
=> this.GetUsersRoomsAsync(parentId => roomService.GetByParentIdAsync(parentId), filter);

/// <summary>
Expand Down Expand Up @@ -319,32 +319,36 @@ async Task<IActionResult> Operation()

private async Task<IActionResult> 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<IActionResult> 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<bool> IsUserHasRightsForApplicationAsync(ApplicationDto application)
Expand Down

0 comments on commit 932264b

Please sign in to comment.