City-of-Helsinki / maritime-maas

MIT License
0 stars 3 forks source link

MAAS-87 | Seat availability API endpoint #73

Closed tuomas777 closed 3 years ago

tuomas777 commented 3 years ago

Implemented API endpoint /bookings/availability/ for fetching information about available seats for given departures. Availability requests are proxied to ticket systems that provide the given departures. In those requests departure IDs are converted to trip source IDs and dates. If a departure's availability cannot be determined for any reason, the departure is excluded from the results.

NOTE: departures can span multiple ticket systems, which all need to be queried. Currently those requests are executed synchronously, so the current implementation won't happily scale to many ticket systems.

Example request from a MaaS client to us:

POST /v1/bookings/availability/

{
  "departure_ids": [
      "443d0610-63ec-5d7a-92ba-43d6d5f66cbd",
      "5e068dbf-1172-5488-88d3-6dcb2976d294"
  ]
}

Response:

[
  {
    "departure_id": "5e068dbf-1172-5488-88d3-6dcb2976d294",
    "available": 3,
    "total": 38
  },
  {
    "departure_id": "443d0610-63ec-5d7a-92ba-43d6d5f66cbd",
    "available": 2,
    "total": null
  }
]

Behind the scenes, that causes a request from us to a ticket system:

POST <ticket system availability endpoint URL>

{
  "departures": [
    {
      "trip_id": "foo_1",
      "date": "2021-10-22"
    },
    {
      "trip_id": "foo_2",
      "date": "2021-10-23"
    }
  ]
}

Response:

[
  {
    "trip_id": "foo_1",
    "date": "2021-10-22",
    "available": 3,
    "total": 38
  },
  {
    "trip_id": "foo_2",
    "date": "2021-10-23",
    "available": 2
  }
]
codecov-commenter commented 3 years ago

Codecov Report

Merging #73 (5e482e3) into main (b5a5743) will increase coverage by 0.26%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #73      +/-   ##
==========================================
+ Coverage   89.64%   89.90%   +0.26%     
==========================================
  Files          48       48              
  Lines        1564     1605      +41     
  Branches      125      131       +6     
==========================================
+ Hits         1402     1443      +41     
  Misses        128      128              
  Partials       34       34              
Impacted Files Coverage Δ
bookings/api.py 100.00% <100.00%> (ø)
bookings/serializers.py 97.43% <100.00%> (+0.10%) :arrow_up:
bookings/ticketing_system.py 96.00% <100.00%> (+0.21%) :arrow_up:
maas/models.py 90.24% <100.00%> (+0.24%) :arrow_up:
mock_ticket_api/api.py 88.00% <100.00%> (+2.63%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b5a5743...5e482e3. Read the comment docs.