48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from typing import List, Optional
|
|
from uuid import UUID
|
|
from sqlalchemy.orm import Session
|
|
from models.menu import Menu
|
|
from schemas.menu import MenuSchema
|
|
|
|
def get_menus(db: Session) -> List[MenuSchema]:
|
|
"""
|
|
Retrieves a list of all menus from the database.
|
|
|
|
Args:
|
|
db (Session): The database session.
|
|
|
|
Returns:
|
|
List[MenuSchema]: A list of MenuSchema objects representing all menus.
|
|
"""
|
|
menus = db.query(Menu).all()
|
|
return [MenuSchema.from_orm(menu) for menu in menus]
|
|
|
|
def get_menu_by_id(db: Session, menu_id: UUID) -> Optional[MenuSchema]:
|
|
"""
|
|
Retrieves a menu by its ID from the database.
|
|
|
|
Args:
|
|
db (Session): The database session.
|
|
menu_id (UUID): The ID of the menu to retrieve.
|
|
|
|
Returns:
|
|
Optional[MenuSchema]: The MenuSchema object representing the menu, or None if not found.
|
|
"""
|
|
menu = db.query(Menu).filter(Menu.id == menu_id).first()
|
|
return MenuSchema.from_orm(menu) if menu else None
|
|
|
|
def get_meals_by_menu(db: Session, menu_id: UUID) -> List[MenuSchema]:
|
|
"""
|
|
Retrieves a list of meals associated with a specific menu from the database.
|
|
|
|
Args:
|
|
db (Session): The database session.
|
|
menu_id (UUID): The ID of the menu to retrieve meals for.
|
|
|
|
Returns:
|
|
List[MenuSchema]: A list of MenuSchema objects representing the meals associated with the menu.
|
|
"""
|
|
menu = db.query(Menu).filter(Menu.id == menu_id).first()
|
|
if menu:
|
|
return [MenuSchema.from_orm(meal.menu) for meal in menu.meals]
|
|
return [] |