Skip to content

repositories

Handles all database-specific logic using SQLAlchemy.

RecipeRepository

RecipeRepository(session: Session)

Concrete implementation of RecipeRepositoryPort using SQLAlchemy.

add_image

add_image(
    recipe_id: UUID,
    user_id: UUID,
    caption: str | None = None,
    display_order: int | None = 0,
) -> ImageEntity

Create and persist an Image linked to a recipe visible to user_id.

add_recipe

add_recipe(data: RecipeCreate, owner_id: UUID) -> RecipeEntity

Persist a recipe from creation data and return a domain entity.

add_recipes

add_recipes(data: list[RecipeCreate], owner_id: UUID) -> list[RecipeEntity]

Persist multiple recipes in a single atomic transaction.

delete_image

delete_image(image_id: UUID, user_id: UUID) -> bool

Delete an Image record by ID, only if its recipe is visible to user_id.

delete_recipe

delete_recipe(recipe_id: UUID, user_id: UUID) -> bool

Delete a recipe and all related entities, scoped to user.

get_recipe_by_id

get_recipe_by_id(recipe_id: UUID, user_id: UUID) -> RecipeEntity | None

Retrieve a recipe with all relationships loaded, visible to user.

image_belongs_to_user

image_belongs_to_user(image_id: UUID, user_id: UUID) -> bool

Check if an image belongs to a recipe visible to the given user.

search_recipes

search_recipes(
    user_id: UUID,
    recipe_id: UUID | None = None,
    title: str | None = None,
    category: str | None = None,
    is_veggie: bool | None = None,
    season: str | None = None,
    limit: int | None = None,
    offset: int = 0,
    ownership: str | None = None,
) -> PaginatedResult

Search recipes with dynamic filtering and pagination, visible to user.

RecipeShareRepository

RecipeShareRepository(session: Session)

Concrete implementation of RecipeShareRepositoryPort using SQLAlchemy.

get_user_role_for_recipe

get_user_role_for_recipe(recipe_id: UUID, user_id: UUID) -> str | None

Return 'owner', 'editor', 'reader', or None.

UserRepository

UserRepository(session: Session)

Concrete implementation of UserRepositoryPort using SQLAlchemy.