コード例 #1
0
        public async Task <ActionResult <IList <PersonResponse> > > UpdatePersonDetails([FromRoute] Guid personId,
                                                                                        [FromBody] UpdateAccountDetailsRequest payload)
        {
            try
            {
                var useridString = await _userAccountService.GetAdUserIdForUsername(payload.CurrentUsername);

                var userId        = Guid.Parse(useridString);
                var updatedPerson =
                    await _userAccountService.UpdateUserAccountDetails(userId, payload.FirstName, payload.LastName);

                var updateBookingPersonRequest = new UpdatePersonDetailsRequest
                {
                    FirstName = updatedPerson.FirstName,
                    LastName  = updatedPerson.LastName,
                    Username  = updatedPerson.Email
                };
                await _bookingsApiClient.UpdatePersonDetailsAsync(personId, updateBookingPersonRequest);

                return(Accepted());
            }
            catch (UserApiException e)
            {
                return(StatusCode(e.StatusCode, e.Response));
            }
            catch (BookingsApiException e)
            {
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
コード例 #2
0
        public async Task should_return_bad_request_if_payload_is_invalid()
        {
            var personId = Guid.NewGuid();
            var payload  = new UpdatePersonDetailsRequest()
            {
                Username  = String.Empty,
                FirstName = "New",
                LastName  = "Me"
            };
            var result = await Controller.UpdatePersonDetails(personId, payload);

            result.Result.Should().BeOfType <BadRequestObjectResult>();
        }
コード例 #3
0
        public void GivenIHaveAMalformedUpdatePersonDetailsRequest()
        {
            var hearing = Context.TestData.SeededHearing;
            var person  = hearing.GetPersons().First();
            var request = new UpdatePersonDetailsRequest
            {
                Username  = String.Empty,
                FirstName = "New"
            };

            Context.Uri        = UpdatePersonDetails(person.Id);
            Context.HttpMethod = HttpMethod.Put;
            var jsonBody = RequestHelper.Serialise(request);

            Context.HttpContent = new StringContent(jsonBody, Encoding.UTF8, "application/json");
        }
コード例 #4
0
        public void GivenIHaveANonExistentUpdatePersonDetailsRequest()
        {
            Context.Uri        = UpdatePersonDetails(Guid.NewGuid());
            Context.HttpMethod = HttpMethod.Put;
            var request = new UpdatePersonDetailsRequest
            {
                Username  = "******",
                FirstName = "New",
                LastName  = "Me"
            };

            Context.HttpMethod = HttpMethod.Put;
            var jsonBody = RequestHelper.Serialise(request);

            Context.HttpContent = new StringContent(jsonBody, Encoding.UTF8, "application/json");
        }
コード例 #5
0
        public async Task should_return_not_found_when_command_throws_person_not_found_exception()
        {
            var personId = Guid.NewGuid();
            var payload  = new UpdatePersonDetailsRequest()
            {
                Username  = "******",
                FirstName = "New",
                LastName  = "Me"
            };

            CommandHandlerMock.Setup(x => x.Handle(It.IsAny <UpdatePersonCommand>()))
            .ThrowsAsync(new PersonNotFoundException(personId));
            var result = await Controller.UpdatePersonDetails(personId, payload);

            result.Result.Should().BeOfType <NotFoundObjectResult>();
            var typed = result.Result.As <NotFoundObjectResult>();

            typed.Value.Should().Be($"{personId} does not exist");
        }
コード例 #6
0
        public async Task should_send_update_event_for_each_hearing_person_is_a_participant_in()
        {
            var personId = Guid.NewGuid();
            var payload  = new UpdatePersonDetailsRequest()
            {
                Username  = "******",
                FirstName = "New",
                LastName  = "Me"
            };

            var hearings = CreateListOfVideoHearings(personId, payload.FirstName, payload.LastName, payload.Username);

            QueryHandlerMock
            .Setup(x =>
                   x.Handle <GetHearingsByUsernameQuery, List <VideoHearing> >(It.IsAny <GetHearingsByUsernameQuery>()))
            .ReturnsAsync(hearings);

            var result = await Controller.UpdatePersonDetails(personId, payload);

            result.Result.Should().BeOfType <AcceptedResult>();

            EventPublisherMock.Verify(x => x.PublishAsync(It.IsAny <ParticipantUpdatedIntegrationEvent>()), Times.Once);
        }
コード例 #7
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());
        }