Files
simple-mensa/api/dependencies.py
T
Matteo Benedetto d592e0f32b feat: Refactor API structure and implement core functionalities
- Updated requirements to include asyncpg, pyyaml, aiofiles, and httpx.
- Modified schema.sql to add 'tipo_pasto' column in 'pasti' table.
- Created .gitignore file to exclude unnecessary files and directories.
- Added README.md for API implementation details and directory structure.
- Introduced config.yaml for centralized configuration management.
- Implemented core modules for database management, authentication, and exception handling.
- Developed models for 'pietanze', 'pasti', and 'prenotazioni' with validation.
- Created routes for CRUD operations on 'pietanze' with pagination and filtering.
- Established logging and error handling mechanisms throughout the application.
- Set up FastAPI application with CORS and health check endpoint.
2025-06-05 18:31:36 +02:00

36 lines
974 B
Python

from fastapi import Depends, Query
from typing import Optional
import yaml
import logging
logger = logging.getLogger(__name__)
def load_config() -> dict:
"""Load configuration from YAML file"""
try:
with open('api/config.yaml', 'r') as file:
return yaml.safe_load(file)
except Exception as e:
logger.error(f"Failed to load configuration: {e}")
raise
# Global configuration
config = load_config()
def get_config() -> dict:
"""Dependency to get application configuration"""
return config
class PaginationParams:
def __init__(
self,
skip: int = Query(0, ge=0, description="Number of items to skip"),
limit: int = Query(20, ge=1, le=100, description="Number of items to return")
):
self.skip = skip
self.limit = limit
def get_pagination_params(params: PaginationParams = Depends()) -> PaginationParams:
"""Dependency for pagination parameters"""
return params