Coverage for app/gateway.py: 94%
16 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-02 23:27 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-02 23:27 +0000
1from fastapi import FastAPI, Request
2from fastapi.exceptions import RequestValidationError
3from fastapi.responses import JSONResponse
4from sqlalchemy.exc import SQLAlchemyError
5from app.controllers.auth_controller import auth_controller
6from app.controllers.world_controller import world_controller
7from app.controllers.users_controller import users_controller
8from app.controllers.event_controller import event_controller
9# from app.controllers.campaign_controller import campaigns_controller
11app = FastAPI()
13# ONLY FOR PRODUCTION
14# # Handler for SQLAlchemy "DB" errors
15# @app.exception_handler(SQLAlchemyError)
16# async def sqlalchemy_exception_handler(request: Request, exc: SQLAlchemyError):
17# print(f"Database error: {exc}")
18# return JSONResponse(
19# status_code=400,
20# content={"detail":"A database error occured."}
21# )
22#
23# # Handler for bad client inputs
24# @app.exception_handler(RequestValidationError)
25# async def sqlalchemy_exception_handler(request: Request, exc: RequestValidationError):
26# print(f"Validation error: {exc}")
27# return JSONResponse(
28# status_code=422,
29# content={"detail": exc.errors()}
30# )
31#
32# # Generic catch-all fallback if all else fails
33# @app.exception_handler(Exception)
34# async def generic_exception_handler(request: Request, exc: Exception):
35# print(f"Unexpected error: {exc}")
36# return JSONResponse(
37# status_code=500,
38# content={"detail":"Internal server error"}
39# )
41# core routers
42app.include_router(auth_controller, prefix="/api/auth", tags=["auth"])
43app.include_router(users_controller, prefix="/api/users", tags=["users"])
44app.include_router(world_controller, prefix="/api/worlds", tags=["worlds"])
46# # campaigns
47# app.include_router(campaigns_controller, prefix="/api/campaigns", tags=["campaigns"])
48# app.include_router(campaigns_controller.router, prefix="/api/worlds/{world_id}/campaigns", tags=["campaigns"])
50# # regions
51# app.include_router(mapRegions_controller.router, prefix="/api/regions", tags=["regions"])
52# app.include_router(mapRegions_controller.router, prefix="/api/worlds/{world_id}/regions", tags=["regions"])
55# app.include_router(sessions_controller.router, prefix="/api/sessions", tags=["sessions"])
56# app.include_router(sessions_controller.router, prefix="/api/campaigns/{campaign_id}/sessions", tags=["sessions"])
58# # markers
59# app.include_router(markers_controller.router, prefix="/api/markers", tags=["markers"])
60# app.include_router(markers_controller.router, prefix="/api/worlds/{world_id}/markers", tags=["markers"])
62# # world events
63app.include_router(event_controller, prefix="/api/events", tags=["events"])
64# app.include_router(events_controller.router, prefix="/api/worlds/{world_id}/events", tags=["events"])
66# # lore entries
67# app.include_router(lore_controller.router, prefix="/api/lore", tags=["lore"])
68# app.include_router(lore_controller.router, prefix="/api/regions/{region_id}/lore", tags=["lore"])
71@app.get("/")
72async def root():
73 return {"message:" : "Root"}