Beispiel #1
0
        public async Task<IActionResult> UpdatePersonByIdAsync([FromBody] UpdatePersonRequestObject personRequestObject,
            [FromRoute] PersonQueryObject query)
        {
            // This is only possible because the EnableRequestBodyRewind middleware is specified in the application startup.
            var bodyText = await HttpContext.Request.GetRawBodyStringAsync().ConfigureAwait(false);
            var token = _tokenFactory.Create(_contextWrapper.GetContextRequestHeaders(HttpContext));

            var ifMatch = GetIfMatchFromHeader();

            try
            {
                // We use a request object AND the raw request body text because the incoming request will only contain the fields that changed
                // whereas the request object has all possible updateable fields defined.
                // The implementation will use the raw body text to identify which fields to update and the request object is specified here so that its
                // associated validation will be executed by the MVC pipeline before we even get to this point.
                var person = await _updatePersonUseCase.ExecuteAsync(personRequestObject, bodyText, token, query, ifMatch)
                                                       .ConfigureAwait(false);
                if (person == null) return NotFound(query.Id);

                return NoContent();
            }
            catch (VersionNumberConflictException vncErr)
            {
                return Conflict(vncErr.Message);
            }
        }
Beispiel #2
0
        public async Task <Person> GetPersonByIdAsync(PersonQueryObject query)
        {
            _logger.LogDebug($"Calling IDynamoDBContext.LoadAsync for id {query.Id}");

            var result = await _dynamoDbContext.LoadAsync <PersonDbEntity>(query.Id).ConfigureAwait(false);

            return(result?.ToDomain());
        }
Beispiel #3
0
        public async Task<IActionResult> GetPersonByIdAsync([FromRoute] PersonQueryObject query)
        {
            var person = await _getByIdUseCase.ExecuteAsync(query).ConfigureAwait(false);
            if (null == person) return NotFound(query.Id);

            var eTag = string.Empty;
            if (person.VersionNumber.HasValue)
                eTag = person.VersionNumber.ToString();

            HttpContext.Response.Headers.Add(HeaderConstants.ETag, EntityTagHeaderValue.Parse($"\"{eTag}\"").Tag);

            return Ok(_responseFactory.ToResponse(person));
        }
Beispiel #4
0
        public async Task<PersonResponseObject> ExecuteAsync(UpdatePersonRequestObject personRequestObject, string requestBody,
            Token token, PersonQueryObject query, int? ifMatch)
        {
            var result = await _gateway.UpdatePersonByIdAsync(personRequestObject, requestBody, query, ifMatch).ConfigureAwait(false);
            if (result is null) return null;

            // Only raise the event if something actually changed.
            if (result.NewValues.Any())
            {
                var personSnsMessage = _snsFactory.Update(result, token);
                var topicArn = Environment.GetEnvironmentVariable("PERSON_SNS_ARN");
                await _snsGateway.Publish(personSnsMessage, topicArn).ConfigureAwait(false);
            }

            return _responseFactory.ToResponse(result.UpdatedEntity.ToDomain());
        }
        public ActionResult <QueryResult <Person> > GetPeople(PersonQueryObject personQueryObj)
        {
            var filteredPeople = people
                                 .AsQueryable()
                                 .ApplyContainsFilter(p => p.ForeName, personQueryObj.ForeName)
                                 .ApplyContainsFilter(p => p.SirName, personQueryObj.SirName, StringComparison.OrdinalIgnoreCase)
                                 .ApplyEqualsFilter(p => p.Email, personQueryObj.Email);

            var sortedPeople = filteredPeople
                               .ApplySorting(columnMapping, personQueryObj);

            var result = sortedPeople
                         .ApplyPaging(personQueryObj);

            return(Ok(Json(result).Value));
        }
Beispiel #6
0
        public async Task <UpdateEntityResult <PersonDbEntity> > UpdatePersonByIdAsync(UpdatePersonRequestObject requestObject, string requestBody,
                                                                                       PersonQueryObject query, int?ifMatch)
        {
            var existingPerson = await _dynamoDbContext.LoadAsync <PersonDbEntity>(query.Id).ConfigureAwait(false);

            if (existingPerson == null)
            {
                return(null);
            }

            if (ifMatch != existingPerson.VersionNumber)
            {
                throw new VersionNumberConflictException(ifMatch, existingPerson.VersionNumber);
            }

            var result = _updater.UpdateEntity(existingPerson, requestBody, requestObject);

            if (result.NewValues.Any())
            {
                _logger.LogDebug($"Calling IDynamoDBContext.SaveAsync to update id {query.Id}");
                result.UpdatedEntity.LastModified = DateTime.UtcNow;
                await _dynamoDbContext.SaveAsync(result.UpdatedEntity).ConfigureAwait(false);
            }

            return(result);
        }
        public async Task <Person> ExecuteAsync(PersonQueryObject query)
        {
            var person = await _gateway.GetPersonByIdAsync(query).ConfigureAwait(false);

            return(person);
        }