private string CreateValueSetResourceUri(DomainRouteParameters domainParameters, PaginationParameters parameters, ResourceUriType type) { switch (type) { case ResourceUriType.PreviousPage: return(Url.Link(nameof(GetValueSets), new { searchQuery = parameters.SearchQuery, domain = domainParameters.Domain, pageNumber = parameters.PageNumber - 1, pageSize = parameters.PageSize })); case ResourceUriType.NextPage: return(Url.Link(nameof(GetValueSets), new { searchQuery = parameters.SearchQuery, domain = domainParameters.Domain, pageNumber = parameters.PageNumber + 1, pageSize = parameters.PageSize })); default: return(Url.Link(nameof(GetValueSets), new { searchQuery = parameters.SearchQuery, domain = domainParameters.Domain, pageNumber = parameters.PageNumber, pageSize = parameters.PageSize })); } }
public ActionResult <IEnumerable <ValueSetForRetrievalDto> > GetValueSetVersions( [FromRoute] DomainRouteParameters routeParameters, [FromQuery] ValueSetVersionPaginationParameters paginationParameters) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Get the items from the database var valueSetVersionEntities = _valueSetVersionRepository.GetValueSetVersions(paginationParameters); // Get pagination metadata var previousPageLink = CreateValueSetResourceUri(routeParameters, paginationParameters, ResourceUriType.PreviousPage); var nextPageLink = CreateValueSetResourceUri(routeParameters, paginationParameters, ResourceUriType.NextPage); var paginationMetadata = new { totalCount = valueSetVersionEntities.TotalCount, pageSize = valueSetVersionEntities.PageSize, currentPage = valueSetVersionEntities.CurrentPage, totalPages = valueSetVersionEntities.TotalPages, previousPageLink = valueSetVersionEntities.HasPrevious ? previousPageLink : string.Empty, nextPageLink = valueSetVersionEntities.HasNext ? nextPageLink : string.Empty }; Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata)); var valueSetVersionssToReturn = Mapper.Map <IEnumerable <ValueSetVersionForRetrievalDto> >(valueSetVersionEntities); return(Ok(valueSetVersionssToReturn)); }
public IActionResult Get( [FromRoute] DomainRouteParameters routeParameters, [FromRoute][ModelBinder(BinderType = typeof(ArrayModelBinder))] IEnumerable <string> ids) { if (ids == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var guids = new List <Guid>(ids.Count()); foreach (var id in ids) { guids.Add(new Guid(id)); // TODO: Fix this so we can model bind to GUIDs, or perhaps just try to parse as a GUID and return a 400 if it isn't a valid GUID. If the former, note the ArrayModelBinder doesn't support that at the moment... should look into a fix. } var valueSetEntities = _valueSetRepository.GetValueSets(guids); if (ids.Count() != valueSetEntities.Count()) { return(NotFound()); // even one ID that isn't found should generate a 404 } var valueSetsToReturn = Mapper.Map <IEnumerable <ValueSetForRetrievalDto> >(valueSetEntities); return(Ok(valueSetsToReturn)); }