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

            var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

            RestRequest BackendRequest() => CreateBackendDetailRequest(objectId);

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

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

            return(new BackendResponseResult(value));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ListStreetNamesV2(
            [FromQuery] int?offset,
            [FromQuery] int?limit,
            [FromQuery] string sort,
            [FromQuery] string straatnaam,
            [FromQuery] string gemeentenaam,
            [FromQuery] string niscode,
            [FromQuery] string status,
            [FromServices] IActionContextAccessor actionContextAccessor,
            [FromServices] IOptions <StreetNameOptionsV2> responseOptions,
            [FromHeader(Name = HeaderNames.IfNoneMatch)] string ifNoneMatch,
            [FromServices] IsStreetNameOsloApiEnabledToggle featureToggle,
            CancellationToken cancellationToken = default)
        {
            if (!featureToggle.FeatureEnabled)
            {
                return(NotFound());
            }

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

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

            var cacheKey = CreateCacheKeyForRequestQuery($"oslo/streetname-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));
        }
Exemplo n.º 3
0
        public async Task<IActionResult> CountStreetNamesV2(
            [FromQuery] string gemeentenaam,
            [FromServices] IActionContextAccessor actionContextAccessor,
            [FromHeader(Name = HeaderNames.IfNoneMatch)] string ifNoneMatch,
            [FromServices] IsStreetNameOsloApiEnabledToggle featureToggle,
            CancellationToken cancellationToken = default)
        {
            if (!featureToggle.FeatureEnabled)
                return NotFound();

            var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

            IRestRequest BackendRequest() => CreateBackendCountRequest(gemeentenaam);

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