"""System endpoints are defined here.""" import fastapi from starlette import status from {{project_slug}}.db.connection.manager import PostgresConnectionManager from {{project_slug}}.dependencies import connection_manager_dep from {{project_slug}}.logic import system as system_logic from {{project_slug}}.schemas import PingResponse from .routers import system_router @system_router.get("/", status_code=status.HTTP_307_TEMPORARY_REDIRECT, include_in_schema=False) @system_router.get("/api", status_code=status.HTTP_307_TEMPORARY_REDIRECT, include_in_schema=False) async def redirect_to_swagger_docs(): """Redirects to **/api/docs** from **/** and **/api**.""" return fastapi.responses.RedirectResponse("/api/docs", status_code=status.HTTP_307_TEMPORARY_REDIRECT) @system_router.get( "/health_check/ping", response_model=PingResponse, status_code=status.HTTP_200_OK, ) async def ping(): """ Check that application is alive. """ return PingResponse() @system_router.get( "/health_check/ping_db", response_model=PingResponse, status_code=status.HTTP_200_OK, ) async def ping_db( readonly: bool = False, connection_manager: PostgresConnectionManager = fastapi.Depends(connection_manager_dep.from_request), ): """Check that database connection is valid.""" return await system_logic.ping_db(connection_manager, readonly)