diff --git a/api/app/server.py b/api/app/server.py index e92577e..7626d36 100644 --- a/api/app/server.py +++ b/api/app/server.py @@ -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": {}}, diff --git a/api/tests/test_http.py b/api/tests/test_http.py index e9b0d5a..3cf21f1 100644 --- a/api/tests/test_http.py +++ b/api/tests/test_http.py @@ -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")