Skip to content

18 fastapi wire api endpoints to oriondb - #42

Merged
Carbonic-Acidd merged 17 commits into
mainfrom
18-fastapi-wire-api-endpoints-to-oriondb
Oct 15, 2026
Merged

Carbonic-Acidd merged 17 commits into
mainfrom
18-fastapi-wire-api-endpoints-to-oriondb

Conversation

@Carbonic-Acidd

@Carbonic-Acidd Carbonic-Acidd commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Connects GET /api/races and GET /api/races/{id}/laps/{lap}/positions to OrionDB, replacing hardcoded stubs with live queries to races and estimated_positions.

  • Database Connection: Added shared DB connection setup (orion/connection.py) and table schemas (orion/schema.py).
  • Backend Refactor: Replaced stub methods with real queries across the controller, service, and repository layers.
  • Error Handling: Added validation returning 422 for bad inputs, 404 for missing races, and 500/503 for DB errors.
  • Cleanup: Marked remaining stubs with # STUB

Technical Description

Added a FastAPI database dependency backed by a shared SQLAlchemy engine and injected connections into the wired route handlers. The race repository now queries the races table, while the positions repository queries estimated_positions by race and lap, with optional latitude/longitude bounds and timestamp ordering.

The service layer checks that a requested race exists before querying positions, allowing a valid race with no position data to return [] while an invalid race returns 404. Database-specific exceptions are converted into OrionDB errors and then into clean HTTP responses by FastAPI.

How Has This Been Tested?

Automated and Live Tests that cover

  • Database connection
  • /api/health/db connectivity and database configuration failures
  • Ensuring the front end and backend doing GET /api/races return [] for an empty database
  • 404 responses for unknown race IDs
  • Race and position response shapes matching the existing frontend stubs
  • Database connection and schema failures returning clear 500/503 responses
  • Remaining stub endpoints continuing to return valid responses

Ticket Review

Answer the following:

  1. What went well
  • The layered architecture (controller -> services -> repository) made implementing the Connection easy.
  1. What was difficult
  • Because the ORION DB lacks any data, live verification was limited to empty state paths.
  1. If you could start over what would you do differently
  • I would've spent more time initially planning everything out instead of trying to build each part at once, leading to a lot of back and forth.

@Carbonic-Acidd Carbonic-Acidd linked an issue Oct 8, 2026 that may be closed by this pull request
Comment thread backend/orion/schema.py Outdated
Comment thread backend/repositories/race_repository.py Outdated
Comment thread backend/repositories/run_repository.py Outdated
Comment thread backend/controllers/race_controller.py Outdated
Comment thread backend/controllers/run_controller.py Outdated
Comment thread backend/orion/schema.py Outdated
Comment thread backend/repositories/run_repository.py Outdated
@shreya-m9

Copy link
Copy Markdown
Collaborator

Looks good to me!

@shreya-m9
shreya-m9 self-requested a review October 14, 2026 22:25

@shreya-m9 shreya-m9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@TKDPenguin TKDPenguin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just make sure you handle the merge conflict before you merge

@Carbonic-Acidd
Carbonic-Acidd merged commit 147108c into main Oct 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FastAPI] Wire API endpoints to OrionDB

4 participants