Files
mealie/mealie/routes/recipe/all_recipe_routes.py

72 lines
1.9 KiB
Python
Raw Normal View History

2021-01-30 17:24:19 -09:00
from typing import List, Optional
2021-01-31 19:10:21 -09:00
from db.database import db
2021-01-30 17:24:19 -09:00
from db.db_setup import generate_session
from fastapi import APIRouter, Depends, Query
from models.recipe_models import AllRecipeRequest
from sqlalchemy.orm.session import Session
router = APIRouter(tags=["Recipes"])
2021-01-31 19:10:21 -09:00
@router.get("/api/all-recipes/")
2021-01-30 17:24:19 -09:00
def get_all_recipes(
keys: Optional[List[str]] = Query(...),
num: Optional[int] = 100,
2021-01-31 19:10:21 -09:00
session: Session = Depends(generate_session),
2021-01-30 17:24:19 -09:00
):
"""
Returns key data for all recipes based off the query paramters provided.
For example, if slug, image, and name are provided you will recieve a list of
recipes containing the slug, image, and name property. By default, responses
are limited to 100.
2021-01-31 19:10:21 -09:00
At this time you can only query top level values:
- slug
- name
- description
- image
- recipeYield
- totalTime
- prepTime
- performTime
- rating
- orgURL
2021-01-30 17:24:19 -09:00
**Note:** You may experience problems with with query parameters. As an alternative
you may also use the post method and provide a body.
See the *Post* method for more details.
"""
2021-01-31 19:10:21 -09:00
return db.recipes.get_all_limit_columns(session, keys, limit=num)
2021-01-30 17:24:19 -09:00
2021-01-31 19:10:21 -09:00
@router.post("/api/all-recipes/")
2021-01-30 17:24:19 -09:00
def get_all_recipes_post(
2021-01-31 19:10:21 -09:00
body: AllRecipeRequest, session: Session = Depends(generate_session)
2021-01-30 17:24:19 -09:00
):
"""
Returns key data for all recipes based off the body data provided.
For example, if slug, image, and name are provided you will recieve a list of
recipes containing the slug, image, and name property.
2021-01-31 19:10:21 -09:00
At this time you can only query top level values:
- slug
- name
- description
- image
- recipeYield
- totalTime
- prepTime
- performTime
- rating
- orgURL
2021-01-30 17:24:19 -09:00
Refer to the body example for data formats.
"""
2021-01-31 19:10:21 -09:00
return db.recipes.get_all_limit_columns(session, body.properties, body.limit)