diff --git a/BakeryBackend/__pycache__/__init__.cpython-313.pyc b/BakeryBackend/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..ad0a497 Binary files /dev/null and b/BakeryBackend/__pycache__/__init__.cpython-313.pyc differ diff --git a/BakeryBackend/__pycache__/database.cpython-313.pyc b/BakeryBackend/__pycache__/database.cpython-313.pyc new file mode 100644 index 0000000..e4f175e Binary files /dev/null and b/BakeryBackend/__pycache__/database.cpython-313.pyc differ diff --git a/BakeryBackend/__pycache__/exception_handlers.cpython-313.pyc b/BakeryBackend/__pycache__/exception_handlers.cpython-313.pyc new file mode 100644 index 0000000..b7142b5 Binary files /dev/null and b/BakeryBackend/__pycache__/exception_handlers.cpython-313.pyc differ diff --git a/BakeryBackend/__pycache__/exceptions.cpython-313.pyc b/BakeryBackend/__pycache__/exceptions.cpython-313.pyc new file mode 100644 index 0000000..db4e2c2 Binary files /dev/null and b/BakeryBackend/__pycache__/exceptions.cpython-313.pyc differ diff --git a/BakeryBackend/__pycache__/main.cpython-313.pyc b/BakeryBackend/__pycache__/main.cpython-313.pyc new file mode 100644 index 0000000..05df794 Binary files /dev/null and b/BakeryBackend/__pycache__/main.cpython-313.pyc differ diff --git a/BakeryBackend/__pycache__/middleware.cpython-313.pyc b/BakeryBackend/__pycache__/middleware.cpython-313.pyc new file mode 100644 index 0000000..aa83855 Binary files /dev/null and b/BakeryBackend/__pycache__/middleware.cpython-313.pyc differ diff --git a/BakeryBackend/__pycache__/models.cpython-313.pyc b/BakeryBackend/__pycache__/models.cpython-313.pyc new file mode 100644 index 0000000..5bce592 Binary files /dev/null and b/BakeryBackend/__pycache__/models.cpython-313.pyc differ diff --git a/BakeryBackend/__pycache__/schemas.cpython-313.pyc b/BakeryBackend/__pycache__/schemas.cpython-313.pyc new file mode 100644 index 0000000..bd5450b Binary files /dev/null and b/BakeryBackend/__pycache__/schemas.cpython-313.pyc differ diff --git a/BakeryBackend/main.py b/BakeryBackend/main.py index 8f554ea..0f43f4f 100644 --- a/BakeryBackend/main.py +++ b/BakeryBackend/main.py @@ -1,5 +1,6 @@ from fastapi import FastAPI from fastapi.exceptions import RequestValidationError +from fastapi.middleware.cors import CORSMiddleware from sqlalchemy.exc import SQLAlchemyError from pydantic import ValidationError as PydanticValidationError @@ -28,15 +29,25 @@ pydantic_validation_error_handler ) -# Create all database tables -Base.metadata.create_all(bind=engine) - # Initialize FastAPI app -app = FastAPI(title="Bakery Backend with Favorites") +app = FastAPI( + title="Bakery Backend with Favorites", + description="API for managing user favorites in Frostiq Bakery", + version="1.0.0" +) # Add middleware app.add_middleware(RequestMiddleware) +# Add CORS middleware to allow frontend apps +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], # Change to specific frontend URLs in production + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + # Register exception handlers app.add_exception_handler(Exception, general_exception_handler) app.add_exception_handler(RequestValidationError, validation_exception_handler) @@ -49,13 +60,20 @@ app.add_exception_handler(BusinessLogicError, business_logic_error_handler) app.add_exception_handler(PydanticValidationError, pydantic_validation_error_handler) -# Include routers -app.include_router(favorites.router) +# Include routers with Swagger UI tags +app.include_router(favorites.router, prefix="/favorites", tags=["Favorites"]) -@app.get("/") +# Startup event: create all tables +@app.on_event("startup") +async def startup_event(): + """Create all database tables on app startup.""" + Base.metadata.create_all(bind=engine) + + +# Health check endpoint +@app.get("/", tags=["Health"]) async def root(): - """Health check endpoint""" return { "message": "Bakery Backend API is running!", "status": "healthy", @@ -63,12 +81,12 @@ async def root(): } -@app.get("/health") +# Detailed health check endpoint +@app.get("/health", tags=["Health"]) async def health_check(): - """Detailed health check endpoint""" return { "status": "healthy", "timestamp": "2025-01-01T00:00:00Z", "version": "1.0.0", "database": "connected" - } \ No newline at end of file + } diff --git a/BakeryBackend/routers/__pycache__/__init__.cpython-313.pyc b/BakeryBackend/routers/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..cb9a1ea Binary files /dev/null and b/BakeryBackend/routers/__pycache__/__init__.cpython-313.pyc differ diff --git a/BakeryBackend/routers/__pycache__/favorites.cpython-313.pyc b/BakeryBackend/routers/__pycache__/favorites.cpython-313.pyc new file mode 100644 index 0000000..f22302a Binary files /dev/null and b/BakeryBackend/routers/__pycache__/favorites.cpython-313.pyc differ