Skip to content
Open
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
Binary file added BakeryBackend/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added BakeryBackend/__pycache__/main.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file added BakeryBackend/__pycache__/models.cpython-313.pyc
Binary file not shown.
Binary file added BakeryBackend/__pycache__/schemas.cpython-313.pyc
Binary file not shown.
40 changes: 29 additions & 11 deletions BakeryBackend/main.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -49,26 +60,33 @@
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",
"features": ["global_exception_handling", "request_logging"]
}


@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"
}
}
Binary file not shown.
Binary file not shown.