public async Task <IActionResult> Count( [FromServices] LegacyContext context, [FromServices] AddressQueryContext queryContext, CancellationToken cancellationToken = default) { var filtering = Request.ExtractFilteringRequest <AddressFilter>(); var sorting = Request.ExtractSortingRequest(); var pagination = new NoPaginationRequest(); return(Ok( new TotaalAantalResponse { Aantal = filtering.ShouldFilter ? await new AddressListQuery(queryContext) .Fetch(filtering, sorting, pagination) .Items .CountAsync(cancellationToken) : Convert.ToInt32(context .AddressListViewCount .First() .Count) })); }
public async Task <IActionResult> List( [FromServices] LegacyContext context, [FromServices] AddressQueryContext queryContext, [FromServices] IOptions <ResponseOptions> responseOptions, Taal?taal, CancellationToken cancellationToken = default) { var filtering = Request.ExtractFilteringRequest <AddressFilter>(); var sorting = Request.ExtractSortingRequest(); var pagination = Request.ExtractPaginationRequest(); var pagedAddresses = new AddressListQuery(queryContext) .Fetch(filtering, sorting, pagination); Response.AddPagedQueryResultHeaders(pagedAddresses); var addresses = await pagedAddresses.Items .Select(a => new { a.PersistentLocalId, a.StreetNameId, a.HouseNumber, a.BoxNumber, a.PostalCode, a.VersionTimestamp }) .ToListAsync(cancellationToken); var streetNameIds = addresses .Select(x => x.StreetNameId) .Distinct() .ToList(); var streetNames = await queryContext .StreetNameLatestItems .Where(x => streetNameIds.Contains(x.StreetNameId)) .ToListAsync(cancellationToken); var nisCodes = streetNames .Select(x => x.NisCode) .Distinct() .ToList(); var municipalities = await queryContext .MunicipalityLatestItems .Where(x => nisCodes.Contains(x.NisCode)) .ToListAsync(cancellationToken); var addressListItemResponses = addresses .Select(a => { var streetName = streetNames.Single(x => x.StreetNameId == a.StreetNameId); var municipality = municipalities.Single(x => x.NisCode == streetName.NisCode); return(new AddressListItemResponse( a.PersistentLocalId, responseOptions.Value.Naamruimte, responseOptions.Value.DetailUrl, a.HouseNumber, a.BoxNumber, AddressMapper.GetVolledigAdres(a.HouseNumber, a.BoxNumber, a.PostalCode, streetName, municipality), a.VersionTimestamp.ToBelgianDateTimeOffset())); }) .ToList(); return(Ok(new AddressListResponse { Adressen = addressListItemResponses, Volgende = pagedAddresses.PaginationInfo.BuildNextUri(responseOptions.Value.VolgendeUrl) })); }