예제 #1
0
        public async Task <ActionResult <ConferenceResponseVho> > GetConferenceByIdVHOAsync(Guid conferenceId)
        {
            if (conferenceId == Guid.Empty)
            {
                _logger.LogWarning("Unable to get conference when id is not provided");
                ModelState.AddModelError(nameof(conferenceId), $"Please provide a valid {nameof(conferenceId)}");

                return(BadRequest(ModelState));
            }

            ConferenceDetailsResponse conference;

            try
            {
                conference = await _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId);
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, $"Unable to retrieve conference: ${conferenceId}");

                return(StatusCode(e.StatusCode, e.Response));
            }

            var exceededTimeLimit = !ConferenceHelper.HasNotPassed(conference.CurrentStatus, conference.ClosedDateTime);

            if (exceededTimeLimit)
            {
                _logger.LogInformation(
                    $"Unauthorised to view conference details {conferenceId} because user is not " +
                    "Officer nor a participant of the conference, or the conference has been closed for over 30 minutes");

                return(Unauthorized());
            }

            // these are roles that are filtered against when lists participants on the UI
            var displayRoles = new List <Role>
            {
                Role.Judge,
                Role.Individual,
                Role.Representative,
                Role.VideoHearingsOfficer,
                Role.JudicialOfficeHolder
            };

            conference.Participants = conference
                                      .Participants
                                      .Where(x => displayRoles.Contains((Role)x.UserRole)).ToList();

            var conferenceResponseVhoMapper = _mapperFactory.Get <ConferenceDetailsResponse, ConferenceResponseVho>();
            var response = conferenceResponseVhoMapper.Map(conference);

            await _conferenceCache.AddConferenceAsync(conference);

            return(Ok(response));
        }
예제 #2
0
        public async Task <ActionResult <ConferenceResponse> > GetConferenceByIdAsync(Guid conferenceId)
        {
            _logger.LogDebug("GetConferenceById");
            if (conferenceId == Guid.Empty)
            {
                _logger.LogWarning("Unable to get conference when id is not provided");
                ModelState.AddModelError(nameof(conferenceId), $"Please provide a valid {nameof(conferenceId)}");
                return(BadRequest(ModelState));
            }

            var username = User.Identity.Name.ToLower().Trim();

            ConferenceDetailsResponse conference;

            try
            {
                _logger.LogTrace($"Retrieving conference details for conference: ${conferenceId}");
                conference = await _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId);
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, $"Unable to retrieve conference: ${conferenceId}");
                return(StatusCode(e.StatusCode, e.Response));
            }

            var exceededTimeLimit = !ConferenceHelper.HasNotPassed(conference.Current_status, conference.Closed_date_time);

            if (conference.Participants.All(x => x.Username.ToLower().Trim() != username) || exceededTimeLimit)
            {
                _logger.LogInformation(
                    $"Unauthorised to view conference details {conferenceId} because user is neither a VH " +
                    "Officer nor a participant of the conference, or the conference has been closed for over 30 minutes");
                return(Unauthorized());
            }

            // these are roles that are filtered against when lists participants on the UI
            var displayRoles = new List <Role>
            {
                Role.Judge,
                Role.Individual,
                Role.Representative
            };

            conference.Participants = conference.Participants
                                      .Where(x => displayRoles.Contains((Role)x.User_role)).ToList();

            var response = ConferenceResponseMapper.MapConferenceDetailsToResponseModel(conference);
            await _conferenceCache.AddConferenceAsync(conference);

            return(Ok(response));
        }
예제 #3
0
        public async Task <ActionResult <IEnumerable <ConferenceForIndividualResponse> > > GetConferencesForIndividual()
        {
            _logger.LogDebug("GetConferencesForIndividual");
            try
            {
                var username = User.Identity.Name;
                var conferencesForIndividual = await _videoApiClient.GetConferencesTodayForIndividualByUsernameAsync(username);

                conferencesForIndividual = conferencesForIndividual.Where(c => ConferenceHelper.HasNotPassed(c.Status, c.Closed_date_time)).ToList();
                var response = conferencesForIndividual
                               .Select(ConferenceForIndividualResponseMapper.MapConferenceSummaryToModel).ToList();
                return(Ok(response));
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, "Unable to get conferences for user");
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
예제 #4
0
        public async Task <ActionResult <List <ConferenceForVhOfficerResponse> > > GetConferencesForVhOfficerAsync([FromQuery] VhoConferenceFilterQuery query)
        {
            _logger.LogDebug("GetConferencesForVhOfficer");
            try
            {
                var conferences = await _videoApiClient.GetConferencesTodayForAdminAsync(query.UserNames);

                conferences = conferences.Where(c => ConferenceHelper.HasNotPassed(c.Status, c.Closed_date_time))
                              .ToList();
                conferences = conferences.OrderBy(x => x.Closed_date_time).ToList();

                var responses = conferences.Select(ConferenceForVhOfficerResponseMapper
                                                   .MapConferenceSummaryToResponseModel).ToList();

                return(Ok(responses));
            }
            catch (VideoApiException e)
            {
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
예제 #5
0
        public async Task <ActionResult <List <ConferenceForVhOfficerResponse> > > GetConferencesForVhOfficerAsync([FromQuery] VhoConferenceFilterQuery query)
        {
            _logger.LogDebug("GetConferencesForVhOfficer");
            try
            {
                var conferences = await _videoApiClient.GetConferencesTodayForAdminAsync(query.UserNames);

                var conferenceForVhOfficerResponseMapper = _mapperFactory.Get <ConferenceForAdminResponse, ConferenceForVhOfficerResponse>();
                var responses = conferences
                                .Where(c => ConferenceHelper.HasNotPassed(c.Status, c.ClosedDateTime))
                                .OrderBy(x => x.ClosedDateTime)
                                .Select(conferenceForVhOfficerResponseMapper.Map)
                                .ToList();

                return(Ok(responses));
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, "Unable to get conferences for vh officer");
                return(StatusCode(e.StatusCode, e.Response));
            }
        }