public async Task <IActionResult> GetMunicipalityV2(
            [FromRoute] int objectId,
            [FromServices] IActionContextAccessor actionContextAccessor,
            [FromHeader(Name = HeaderNames.IfNoneMatch)] string ifNoneMatch,
            [FromServices] IsMunicipalityOsloApiEnabledToggle featureToggle,
            CancellationToken cancellationToken = default)
        {
            if (!featureToggle.FeatureEnabled)
            {
                return(NotFound());
            }

            var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

            RestRequest BackendRequest() => CreateBackendDetailRequest(objectId);

            var cacheKey = $"oslo/municipality:{objectId}";

            var value = await(CacheToggle.FeatureEnabled
                ? GetFromCacheThenFromBackendAsync(
                                  contentFormat.ContentType,
                                  BackendRequest,
                                  cacheKey,
                                  CreateDefaultHandleBadRequest(),
                                  cancellationToken)
                : GetFromBackendAsync(
                                  contentFormat.ContentType,
                                  BackendRequest,
                                  CreateDefaultHandleBadRequest(),
                                  cancellationToken));

            return(new BackendResponseResult(value));
        }
Exemple #2
0
        public async Task <IActionResult> ListMunicipalitiesV2(
            [FromQuery] int?offset,
            [FromQuery] int?limit,
            [FromQuery] string sort,
            [FromQuery] string gemeentenaam,
            [FromQuery] string status,
            [FromServices] IActionContextAccessor actionContextAccessor,
            [FromServices] IOptions <MunicipalityOptionsV2> responseOptions,
            [FromHeader(Name = HeaderNames.IfNoneMatch)] string ifNoneMatch,
            [FromServices] IsMunicipalityOsloApiEnabledToggle featureToggle,
            CancellationToken cancellationToken = default)
        {
            if (!featureToggle.FeatureEnabled)
            {
                return(NotFound());
            }

            var        contentFormat = DetermineFormat(actionContextAccessor.ActionContext);
            const Taal taal          = Taal.NL;

            var isFlemishRegion = GetIsFlemishRegionQueryParameter();

            IRestRequest BackendRequest() => CreateBackendListRequest(
                offset,
                limit,
                taal,
                gemeentenaam,
                sort,
                status,
                isFlemishRegion);

            var cacheKey = CreateCacheKeyForRequestQuery($"oslo/municipality-list:{taal}");

            var value = await(CacheToggle.FeatureEnabled
                ? GetFromCacheThenFromBackendAsync(
                                  contentFormat.ContentType,
                                  BackendRequest,
                                  cacheKey,
                                  CreateDefaultHandleBadRequest(),
                                  cancellationToken)
                : GetFromBackendAsync(
                                  contentFormat.ContentType,
                                  BackendRequest,
                                  CreateDefaultHandleBadRequest(),
                                  cancellationToken));

            return(BackendListResponseResult.Create(value, Request.Query, responseOptions.Value.VolgendeUrl));
        }
        public async Task <IActionResult> CountMunicipalitiesV2(
            [FromServices] IActionContextAccessor actionContextAccessor,
            [FromHeader(Name = HeaderNames.IfNoneMatch)] string ifNoneMatch,
            [FromServices] IsMunicipalityOsloApiEnabledToggle featureToggle,
            CancellationToken cancellationToken = default)
        {
            if (!featureToggle.FeatureEnabled)
            {
                return(NotFound());
            }

            var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

            IRestRequest BackendRequest() => CreateBackendCountRequest();

            return(new BackendResponseResult(
                       await GetFromBackendAsync(
                           contentFormat.ContentType,
                           BackendRequest,
                           CreateDefaultHandleBadRequest(),
                           cancellationToken)));
        }