Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The goal of this project is to provide a Python-based starter API, which comes p
To override default environment variables, add a `.env` file to the `comet-api` directory and update as needed (optional):

```
API_PREFIX=[SOME_ROUTE] # Ex: '/api'
ROOT_PATH=[SOME_ROUTE] # Ex: '/api'
DATABASE_URL=[SOME_URL] # Ex: 'postgresql://username:password@localhost:5432/database_name'
OIDC_CONFIG_URL=[SOME_URL] # Ex: 'https://keycloak.auth.metrostar.cloud/auth/realms/dev/.well-known/openid-configuration'
LOG_LEVEL=[LOG_LEVEL] # Ex: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL' (Default: 'INFO')
Expand Down
3 changes: 1 addition & 2 deletions app/admin/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from starlette import status

from app.auth import validate_jwt
from app.config import settings

router = APIRouter(
prefix=f"{settings.API_PREFIX}/admin",
prefix="/admin",
tags=["Admin"],
)

Expand Down
7 changes: 3 additions & 4 deletions app/applicants/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
ApplicantResponse,
ApplicantUpdate,
)
from app.config import settings
from app.db import get_db

router = APIRouter(
prefix=f"{settings.API_PREFIX}/applicants",
prefix="/applicants",
tags=["Applicants"],
responses={404: {"description": "Endpoint not found"}},
)
Expand All @@ -24,7 +23,7 @@
db_session = Annotated[Session, Depends(get_db)]


@router.get("/", status_code=status.HTTP_200_OK, response_model=ApplicantListResponse)
@router.get("", status_code=status.HTTP_200_OK, response_model=ApplicantListResponse)
async def get_applicants(db: db_session, page_number: int = 0, page_size: int = 100):
"""Retrieve a paginated list of all applicants.

Expand All @@ -39,7 +38,7 @@ async def get_applicants(db: db_session, page_number: int = 0, page_size: int =
return service.get_items(db, page_number, page_size)


@router.post("/", status_code=status.HTTP_201_CREATED, response_model=ApplicantResponse)
@router.post("", status_code=status.HTTP_201_CREATED, response_model=ApplicantResponse)
async def create_applicant(applicant: ApplicantCreate, db: db_session):
"""Create a new applicant.

Expand Down
7 changes: 3 additions & 4 deletions app/cases/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
CaseUpdate,
CaseWithApplicant,
)
from app.config import settings
from app.db import get_db

router = APIRouter(
prefix=f"{settings.API_PREFIX}/cases",
prefix="/cases",
tags=["Cases"],
responses={404: {"description": "Endpoint not found"}},
)
Expand All @@ -25,7 +24,7 @@
db_session = Annotated[Session, Depends(get_db)]


@router.get("/", status_code=status.HTTP_200_OK, response_model=CaseListResponse)
@router.get("", status_code=status.HTTP_200_OK, response_model=CaseListResponse)
async def get_cases(db: db_session, page_number: int = 0, page_size: int = 100):
"""Retrieve a paginated list of all cases.

Expand All @@ -40,7 +39,7 @@ async def get_cases(db: db_session, page_number: int = 0, page_size: int = 100):
return service.get_items(db, page_number, page_size)


@router.post("/", status_code=status.HTTP_201_CREATED, response_model=CaseResponse)
@router.post("", status_code=status.HTTP_201_CREATED, response_model=CaseResponse)
async def create_case(case: CaseCreate, db: db_session):
"""Create a new case.

Expand Down
2 changes: 1 addition & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Settings(BaseSettings):

model_config = SettingsConfigDict(env_file=".env")

API_PREFIX: str = ""
ROOT_PATH: str = ""
DATABASE_URL: str = "sqlite:///./db.sqlite3"
OIDC_CONFIG_URL: str | None = None
LOG_LEVEL: str = "INFO"
Expand Down
6 changes: 2 additions & 4 deletions app/health/router.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from fastapi import APIRouter
from starlette import status

from app.config import settings

router = APIRouter(
prefix=f"{settings.API_PREFIX}/health",
prefix="/health",
tags=["Health"],
)


@router.get("/", status_code=status.HTTP_200_OK)
@router.get("", status_code=status.HTTP_200_OK)
def get_health():
"""Health check endpoint.
Expand Down
6 changes: 5 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from app.admin.router import router as admin_router
from app.applicants.router import router as applicants_router
from app.cases.router import router as cases_router
from app.config import settings
from app.db import Base, engine
from app.health.router import router as health_router
from app.utils import setup_logging
Expand All @@ -16,8 +17,11 @@
setup_logging()
logger = logging.getLogger(__name__)

# Set root path if specified in settings
root_path = settings.ROOT_PATH if settings.ROOT_PATH else ""

# Create the app
app = FastAPI()
app = FastAPI(root_path=root_path)
logger.info("FastAPI application initialized")

# Set up CORS middleware
Expand Down