Skip to content

Commit 062fd74

Browse files
feat: update get_feeds endpoint to support string pagination parameters (#1108)
1 parent 61b3874 commit 062fd74

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

docs/OperationsAPI.yaml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ info:
33
version: 1.0.0
44
title: Mobility Database Catalog Operations
55
description: |
6-
API for the Mobility Database Catalog Operations. See [https://mobilitydatabase.org/](https://mobilitydatabase.org/).
6+
API for the Mobility Database Catalog Operations. See [https://mobilitydatabase.org/](https://mobilitydatabase.org/).
77
This API was designed for internal use and is not intended to be used by the general public.
88
The Mobility Database Operation API uses Auth2.0 authentication.
99
termsOfService: https://mobilitydatabase.org/terms-and-conditions
@@ -33,29 +33,29 @@ paths:
3333
required: false
3434
schema:
3535
type: string
36-
enum: [wip, published]
36+
enum: [ wip, published ]
3737
- name: data_type
3838
in: query
3939
description: Filter feeds by data type.
4040
required: false
4141
schema:
4242
type: string
43-
enum: [gtfs, gtfs_rt]
43+
enum: [ gtfs, gtfs_rt ]
4444
- name: offset
4545
in: query
4646
description: Number of items to skip for pagination.
4747
required: false
4848
schema:
49-
type: integer
50-
default: 0
49+
type: string
50+
default: "0"
5151
- name: limit
5252
in: query
5353
description: Maximum number of items to return.
5454
required: false
5555
schema:
56-
type: integer
57-
default: 50
58-
maximum: 100
56+
type: string
57+
default: "50"
58+
example: "100"
5959
responses:
6060
200:
6161
description: List of feeds retrieved successfully.
@@ -86,7 +86,7 @@ paths:
8686
- "operations"
8787
operationId: updateGtfsFeed
8888
security:
89-
- ApiKeyAuth: []
89+
- ApiKeyAuth: [ ]
9090
requestBody:
9191
description: Payload to update the specified GTFS feed.
9292
required: true
@@ -118,7 +118,7 @@ paths:
118118
- "operations"
119119
operationId: updateGtfsRtFeed
120120
security:
121-
- ApiKeyAuth: []
121+
- ApiKeyAuth: [ ]
122122
requestBody:
123123
description: Payload to update the specified GTFS-RT feed.
124124
required: true
@@ -179,7 +179,7 @@ components:
179179
$ref: "#/components/schemas/SourceInfo"
180180
operational_status:
181181
type: string
182-
enum: [wip, published]
182+
enum: [ wip, published ]
183183
description: Current operational status of the feed.
184184
created_at:
185185
type: string
@@ -245,10 +245,10 @@ components:
245245
type: integer
246246
description: Total number of feeds matching the criteria.
247247
offset:
248-
type: integer
248+
type: string
249249
description: Current offset for pagination.
250250
limit:
251-
type: integer
251+
type: string
252252
description: Maximum number of items per page.
253253
feeds:
254254
type: array
@@ -285,13 +285,13 @@ components:
285285
example: Los Angeles Department of Transportation (LADOT, DASH, Commuter Express)
286286
feed_name:
287287
description: >
288-
An optional description of the data feed, e.g to specify if the data feed is an aggregate of
288+
An optional description of the data feed, e.g to specify if the data feed is an aggregate of
289289
multiple providers, or which network is represented by the feed.
290290
type: string
291291
example: Bus
292292
note:
293-
description: A note to clarify complex use cases for consumers.
294-
type: string
293+
description: A note to clarify complex use cases for consumers.
294+
type: string
295295
feed_contact_email:
296296
description: Use to contact the feed producer.
297297
type: string
@@ -344,13 +344,13 @@ components:
344344
example: Los Angeles Department of Transportation (LADOT, DASH, Commuter Express)
345345
feed_name:
346346
description: >
347-
An optional description of the data feed, e.g to specify if the data feed is an aggregate of
347+
An optional description of the data feed, e.g to specify if the data feed is an aggregate of
348348
multiple providers, or which network is represented by the feed.
349349
type: string
350350
example: Bus
351351
note:
352-
description: A note to clarify complex use cases for consumers.
353-
type: string
352+
description: A note to clarify complex use cases for consumers.
353+
type: string
354354
feed_contact_email:
355355
description: Use to contact the feed producer.
356356
type: string
@@ -396,7 +396,7 @@ components:
396396
properties:
397397
producer_url:
398398
description: >
399-
URL where the producer is providing the dataset.
399+
URL where the producer is providing the dataset.
400400
Refer to the authentication information to know how to access this URL.
401401
type: string
402402
format: url
@@ -405,7 +405,7 @@ components:
405405
$ref: "#/components/schemas/Authentication_type"
406406
authentication_info_url:
407407
description: >
408-
Contains a URL to a human-readable page describing how the authentication should be performed and how credentials can be created.
408+
Contains a URL to a human-readable page describing how the authentication should be performed and how credentials can be created.
409409
This field is required for `authentication_type=1` and `authentication_type=2`.
410410
type: string
411411
format: url
@@ -500,4 +500,4 @@ components:
500500
in: header
501501

502502
security:
503-
- ApiKeyAuth: []
503+
- ApiKeyAuth: [ ]

functions-python/operations_api/src/feeds_operations/impl/feeds_operations_impl.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from deepdiff import DeepDiff
2121
from fastapi import HTTPException
2222
from pydantic import Field
23+
from sqlalchemy.orm import Session
2324
from starlette.responses import Response
2425

2526
from feeds_operations.impl.models.get_feeds_response import GetFeeds200Response
@@ -39,13 +40,12 @@
3940
from feeds_operations_gen.models.update_request_gtfs_rt_feed import (
4041
UpdateRequestGtfsRtFeed,
4142
)
43+
from shared.database.database import with_db_session, refresh_materialized_view
4244
from shared.database_gen.sqlacodegen_models import Gtfsfeed, t_feedsearch
4345
from shared.helpers.query_helper import (
4446
query_feed_by_stable_id,
4547
get_feeds_query,
4648
)
47-
from sqlalchemy.orm import Session
48-
from shared.database.database import with_db_session, refresh_materialized_view
4949
from .request_validator import validate_request
5050

5151
logging.basicConfig(level=logging.INFO)
@@ -72,20 +72,23 @@ def process_feed(self, feed) -> GtfsFeedResponse | GtfsRtFeedResponse:
7272
@with_db_session
7373
async def get_feeds(
7474
self,
75-
db_session: Session,
7675
operation_status: Optional[str] = None,
7776
data_type: Optional[str] = None,
78-
offset: int = 0,
79-
limit: int = 50,
77+
offset: str = "0",
78+
limit: str = "50",
79+
db_session: Session = None,
8080
) -> GetFeeds200Response:
8181
"""Get a list of feeds with optional filtering and pagination."""
8282
try:
83+
limit_int = int(limit) if limit else 50
84+
offset_int = int(offset) if offset else 0
85+
8386
query = get_feeds_query(
8487
db_session=db_session,
8588
operation_status=operation_status,
8689
data_type=data_type,
87-
limit=limit,
88-
offset=offset,
90+
limit=limit_int,
91+
offset=offset_int,
8992
)
9093

9194
logging.info("Executing query with data_type: %s", data_type)
@@ -100,7 +103,7 @@ async def get_feeds(
100103
feed_list.append(processed_feed)
101104

102105
response = GetFeeds200Response(
103-
total=total, offset=offset, limit=limit, feeds=feed_list
106+
total=total, offset=offset_int, limit=limit_int, feeds=feed_list
104107
)
105108
logging.info("Returning response with %d feeds", len(feed_list))
106109
return response

0 commit comments

Comments
 (0)