Skip to content

Commit

Permalink
api: setup swagger documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jone committed Sep 6, 2024
1 parent a4ad840 commit ea4d69b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 16 additions & 3 deletions api/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,35 @@

from fastapi import FastAPI
from fastapi import Query
from fastapi import Request
from fastapi.responses import RedirectResponse

from app.elastic import Elastic
from app.settings import settings


app = FastAPI(debug=settings.fastapi_debug)
app = FastAPI(
debug=settings.fastapi_debug,
title="GeoPhotoRadar API",
docs_url="/api/docs",
redoc_url="/api/redoc",
)


@app.get("/api", include_in_schema=False)
async def root():
return RedirectResponse("/api/docs")


@app.get("/api/health")
async def health(request: Request):
async def health():
"""The health endpoint is used for health checks, indicating whether
the API is running."""
return {"status": "ok"}


@app.get("/api/photos")
async def photos(latitude: float = Query(...), longitude: float = Query(...), radius: float = Query(...)):
"""The photos endpoint queries the database for fotos in a specific radious of a location."""
query = {
"bool": {
"must": {"match_all": {}},
Expand Down
4 changes: 4 additions & 0 deletions api/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class TestHealthEndpoint(TestCase):
def test_root_redirects_to_docs(self):
response = self.client.get("/api", follow_redirects=False)
self.assertEqual(response.status_code, 307)
self.assertEqual("/api/docs", response.headers.get("location"))

def test_health(self):
response = self.client.get("/api/health")
Expand Down

0 comments on commit ea4d69b

Please sign in to comment.