コード例 #1
0
        public async Task <ActionResult <PersonResponse> > SearchForNonJudgePersonsByContactEmail([FromQuery] string contactEmail)
        {
            if (!contactEmail.IsValidEmail())
            {
                ModelState.AddModelError(nameof(contactEmail), $"Please provide a valid {nameof(contactEmail)}");
                return(BadRequest(ModelState));
            }

            var personQuery = new GetPersonByContactEmailQuery(contactEmail);
            var person      = await _queryHandler.Handle <GetPersonByContactEmailQuery, Person>(personQuery);

            if (person == null)
            {
                return(NotFound($"Person with {contactEmail} does not exist"));
            }

            var hearingsQuery = new GetHearingsByUsernameQuery(person.Username);
            var hearings      = await _queryHandler.Handle <GetHearingsByUsernameQuery, List <VideoHearing> >(hearingsQuery);

            var judicialHearings = hearings.SelectMany(v => v.Participants.Where(p => p.PersonId == person.Id))
                                   .Any(x => x.HearingRole.UserRole.IsJudge);

            if (judicialHearings)
            {
                return(Unauthorized("Only searches for non Judge persons are allowed"));
            }

            var mapper   = new PersonToResponseMapper();
            var response = mapper.MapPersonToResponse(person);

            return(Ok(response));
        }
コード例 #2
0
        public async Task <IActionResult> GetHearingsByUsername([FromQuery] string username)
        {
            var query    = new GetHearingsByUsernameQuery(username);
            var hearings = await _queryHandler.Handle <GetHearingsByUsernameQuery, List <VideoHearing> >(query);

            var hearingMapper = new HearingToDetailsResponseMapper();
            var response      = hearings.Select(hearingMapper.MapHearingToDetailedResponse).ToList();

            return(Ok(response));
        }
コード例 #3
0
        public async Task <IActionResult> GetPersonSuitabilityAnswers(string username)
        {
            if (!username.IsValidEmail())
            {
                ModelState.AddModelError(nameof(username), $"Please provide a valid {nameof(username)}");
                return(BadRequest(ModelState));
            }

            var query    = new GetHearingsByUsernameQuery(username);
            var hearings = await _queryHandler.Handle <GetHearingsByUsernameQuery, List <VideoHearing> >(query);

            var personSuitabilityAnswers = hearings.Select(hearing => BuildResponse(hearing, username)).Where(s => s != null).ToList();

            return(Ok(personSuitabilityAnswers));
        }
        public async Task Should_return_hearings_for_username()
        {
            var hearing1 = await Hooks.SeedVideoHearing();

            var hearing2 = await Hooks.SeedVideoHearing();

            var hearing3 = await Hooks.SeedVideoHearing();

            var username = hearing2.GetPersons().First().Username;

            var query = new GetHearingsByUsernameQuery(username);

            var result = await _handler.Handle(query);

            result.Any().Should().BeTrue();
            result.Any(x => x.Id == hearing2.Id).Should().BeTrue();
            result.Any(x => x.Id == hearing1.Id).Should().BeFalse();
            result.Any(x => x.Id == hearing3.Id).Should().BeFalse();
        }
コード例 #5
0
        public async Task <ActionResult <IList <PersonResponse> > > UpdatePersonDetails([FromRoute] Guid personId, [FromBody] UpdatePersonDetailsRequest payload)
        {
            var validation = await new UpdatePersonDetailsRequestValidation().ValidateAsync(payload);

            if (!validation.IsValid)
            {
                ModelState.AddFluentValidationErrors(validation.Errors);
                return(BadRequest(ModelState));
            }

            try
            {
                var command = new UpdatePersonCommand(personId, payload.FirstName, payload.LastName, payload.Username);
                await _commandHandler.Handle(command);
            }
            catch (PersonNotFoundException e)
            {
                _logger.LogError(e, "Failed to update a person because the person {Person} does not exist", personId);
                return(NotFound($"{personId} does not exist"));
            }

            // get all hearings for user
            var query    = new GetHearingsByUsernameQuery(payload.Username);
            var hearings = await _queryHandler.Handle <GetHearingsByUsernameQuery, List <VideoHearing> >(query);

            // raise an update event for each hearing to ensure consistency between video and bookings api
            var anonymisedText            = "@hmcts.net";
            var nonAnonymisedParticipants = hearings
                                            .Where(x => x.Status == BookingStatus.Created &&
                                                   x.GetCases().Any(c => !c.Name.EndsWith(anonymisedText))).SelectMany(c => c.Participants)
                                            .Where(p => p.PersonId == personId && !p.DisplayName.EndsWith(anonymisedText)).ToList();

            _logger.LogDebug("Updating {Count} non-anonymised participants", nonAnonymisedParticipants.Count);

            foreach (var participant in nonAnonymisedParticipants)
            {
                // map to updated participant event
                await _eventPublisher.PublishAsync(new ParticipantUpdatedIntegrationEvent(participant.HearingId, participant));
            }

            return(Accepted());
        }
        public async Task Should_return_hearings_with_linked_participants_for_username()
        {
            var seededHearing = await Hooks.SeedVideoHearingLinkedParticipants(null);

            var username = seededHearing.GetPersons().First().Username;
            var query    = new GetHearingsByUsernameQuery(username);

            var hearings = await _handler.Handle(query);

            hearings.Any().Should().BeTrue();

            var participants = hearings[0].GetParticipants();

            participants.Any().Should().BeTrue();
            var individuals = participants.Where(x => x.GetType() == typeof(Individual))
                              .ToList();

            individuals[0].LinkedParticipants.Should().NotBeNull();
            individuals[0].LinkedParticipants[0].Type.Should().Be(LinkedParticipantType.Interpreter);
            individuals[1].LinkedParticipants.Should().NotBeNull();
            individuals[1].LinkedParticipants[0].Type.Should().Be(LinkedParticipantType.Interpreter);
        }