mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-11 21:05:15 -05:00
Feature/additional endpoints (#257)
* new recipe summary route * add categories to cards * add pillow * show tags instead of categories * additional debug info * add todays meal image url * about page * fix reactive tag * changelog + docs * bump version Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
@@ -5,7 +5,7 @@ from typing import Optional, Union
|
||||
|
||||
from pydantic import BaseSettings, Field, validator
|
||||
|
||||
APP_VERSION = "v0.4.0"
|
||||
APP_VERSION = "v0.4.1"
|
||||
DB_VERSION = "v0.4.0"
|
||||
|
||||
CWD = Path(__file__).parent
|
||||
|
||||
@@ -15,17 +15,10 @@ class BaseDocument:
|
||||
self.schema: BaseModel
|
||||
|
||||
# TODO: Improve Get All Query Functionality
|
||||
def get_all(self, session: Session, limit: int = None, order_by: str = None) -> List[dict]:
|
||||
def get_all(self, session: Session, limit: int = None, order_by: str = None, override_schema=None) -> List[dict]:
|
||||
eff_schema = override_schema or self.schema
|
||||
|
||||
if self.orm_mode:
|
||||
return [self.schema.from_orm(x) for x in session.query(self.sql_model).limit(limit).all()]
|
||||
|
||||
# list = [x.dict() for x in session.query(self.sql_model).limit(limit).all()]
|
||||
|
||||
# if limit == 1:
|
||||
# return list[0]
|
||||
|
||||
# return list
|
||||
return [eff_schema.from_orm(x) for x in session.query(self.sql_model).limit(limit).all()]
|
||||
|
||||
def get_all_limit_columns(self, session: Session, fields: List[str], limit: int = None) -> List[SqlAlchemyBase]:
|
||||
"""Queries the database for the selected model. Restricts return responses to the
|
||||
|
||||
@@ -3,15 +3,35 @@ import json
|
||||
from fastapi import APIRouter, Depends
|
||||
from mealie.core.config import APP_VERSION, LOGGER_FILE, app_dirs, settings
|
||||
from mealie.routes.deps import get_current_user
|
||||
from mealie.schema.debug import AppInfo
|
||||
from mealie.schema.debug import AppInfo, DebugInfo
|
||||
|
||||
router = APIRouter(prefix="/api/debug", tags=["Debug"])
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def get_debug_info(current_user=Depends(get_current_user)):
|
||||
""" Returns general information about the application for debugging """
|
||||
|
||||
return DebugInfo(
|
||||
production=settings.PRODUCTION,
|
||||
version=APP_VERSION,
|
||||
demo_status=settings.IS_DEMO,
|
||||
api_port=settings.API_PORT,
|
||||
api_docs=settings.API_DOCS,
|
||||
db_type=settings.DATABASE_TYPE,
|
||||
sqlite_file=settings.SQLITE_FILE,
|
||||
default_group=settings.DEFAULT_GROUP,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/version")
|
||||
async def get_mealie_version():
|
||||
""" Returns the current version of mealie"""
|
||||
return AppInfo(version=APP_VERSION, demo_status=settings.IS_DEMO)
|
||||
return AppInfo(
|
||||
version=APP_VERSION,
|
||||
demo_status=settings.IS_DEMO,
|
||||
production=settings.PRODUCTION,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/last-recipe-json")
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from mealie.db.database import db
|
||||
from mealie.db.db_setup import generate_session
|
||||
from mealie.routes.deps import get_current_user
|
||||
from mealie.schema.meal import MealPlanIn, MealPlanInDB
|
||||
from mealie.schema.snackbar import SnackResponse
|
||||
from mealie.schema.user import GroupInDB, UserInDB
|
||||
from mealie.services.image import image
|
||||
from mealie.services.meal_services import get_todays_meal, process_meals
|
||||
from sqlalchemy.orm.session import Session
|
||||
from starlette.responses import FileResponse
|
||||
|
||||
router = APIRouter(prefix="/api/meal-plans", tags=["Meal Plan"])
|
||||
|
||||
@@ -74,3 +76,22 @@ def get_today(session: Session = Depends(generate_session), current_user: UserIn
|
||||
recipe = get_todays_meal(session, group_in_db)
|
||||
|
||||
return recipe.slug
|
||||
|
||||
|
||||
@router.get("/today/image", tags=["Meal Plan"])
|
||||
def get_today(session: Session = Depends(generate_session), group_name: str = "Home"):
|
||||
"""
|
||||
Returns the image for todays meal-plan.
|
||||
"""
|
||||
|
||||
group_in_db: GroupInDB = db.groups.get(session, group_name, "name")
|
||||
recipe = get_todays_meal(session, group_in_db)
|
||||
|
||||
if recipe:
|
||||
recipe_image = image.read_image(recipe.slug, image_type=image.IMG_OPTIONS.ORIGINAL_IMAGE)
|
||||
else:
|
||||
raise HTTPException(404, "no meal for today")
|
||||
if recipe_image:
|
||||
return FileResponse(recipe_image)
|
||||
else:
|
||||
raise HTTPException(404, "file not found")
|
||||
|
||||
@@ -3,13 +3,24 @@ from typing import List, Optional
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from mealie.db.database import db
|
||||
from mealie.db.db_setup import generate_session
|
||||
from mealie.schema.recipe import AllRecipeRequest
|
||||
from mealie.schema.recipe import AllRecipeRequest, RecipeSummary
|
||||
from slugify import slugify
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
router = APIRouter(tags=["Query All Recipes"])
|
||||
|
||||
|
||||
@router.get("/api/recipes/summary")
|
||||
async def get_recipe_summary(
|
||||
skip=0,
|
||||
end=9999,
|
||||
session: Session = Depends(generate_session),
|
||||
):
|
||||
""" Returns the summary data for recipes in the database """
|
||||
|
||||
return db.recipes.get_all(session, limit=end, override_schema=RecipeSummary)
|
||||
|
||||
|
||||
@router.get("/api/recipes")
|
||||
def get_all_recipes(
|
||||
keys: Optional[List[str]] = Query(...),
|
||||
|
||||
@@ -98,7 +98,6 @@ async def get_recipe_img(recipe_slug: str, image_type: ImageType = ImageType.ori
|
||||
which_image = IMG_OPTIONS.TINY_IMAGE
|
||||
|
||||
recipe_image = read_image(recipe_slug, image_type=which_image)
|
||||
print(recipe_image)
|
||||
if recipe_image:
|
||||
return FileResponse(recipe_image)
|
||||
else:
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
from pathlib import Path
|
||||
from fastapi_camelcase import CamelModel
|
||||
|
||||
|
||||
class AppInfo(CamelModel):
|
||||
production: bool
|
||||
version: str
|
||||
demo_status: bool
|
||||
|
||||
class DebugInfo(AppInfo):
|
||||
api_port: int
|
||||
api_docs: bool
|
||||
db_type: str
|
||||
sqlite_file: Path
|
||||
default_group: str
|
||||
@@ -34,12 +34,30 @@ class Nutrition(BaseModel):
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class Recipe(BaseModel):
|
||||
class RecipeSummary(BaseModel):
|
||||
name: str
|
||||
description: Optional[str]
|
||||
slug: Optional[str] = ""
|
||||
image: Optional[Any]
|
||||
recipeYield: Optional[str]
|
||||
|
||||
description: Optional[str]
|
||||
recipeCategory: Optional[List[str]] = []
|
||||
tags: Optional[List[str]] = []
|
||||
rating: Optional[int]
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
@classmethod
|
||||
def getter_dict(_cls, name_orm: RecipeModel):
|
||||
return {
|
||||
**GetterDict(name_orm),
|
||||
"recipeCategory": [x.name for x in name_orm.recipeCategory],
|
||||
"tags": [x.name for x in name_orm.tags],
|
||||
}
|
||||
|
||||
|
||||
class Recipe(RecipeSummary):
|
||||
recipeYield: Optional[str]
|
||||
recipeIngredient: Optional[list[str]]
|
||||
recipeInstructions: Optional[list[RecipeStep]]
|
||||
nutrition: Optional[Nutrition]
|
||||
@@ -50,11 +68,8 @@ class Recipe(BaseModel):
|
||||
performTime: Optional[str] = None
|
||||
|
||||
# Mealie Specific
|
||||
slug: Optional[str] = ""
|
||||
tags: Optional[List[str]] = []
|
||||
dateAdded: Optional[datetime.date]
|
||||
notes: Optional[List[RecipeNote]] = []
|
||||
rating: Optional[int]
|
||||
orgURL: Optional[str]
|
||||
extras: Optional[dict] = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user