mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
unorganized routes
This commit is contained in:
parent
832e95f27e
commit
c074d3a85a
5 changed files with 42 additions and 13 deletions
|
@ -36,11 +36,23 @@ class _Recipes(BaseDocument):
|
|||
|
||||
return f"{slug}.{extension}"
|
||||
|
||||
def count_uncategorized(self, session: Session) -> int:
|
||||
return session.query(self.sql_model).filter(RecipeModel.recipe_category == None).count() # noqa: 711
|
||||
def count_uncategorized(self, session: Session, count=True, override_schema=None) -> int:
|
||||
eff_schema = override_schema or self.schema
|
||||
if count:
|
||||
return session.query(self.sql_model).filter(RecipeModel.recipe_category == None).count() # noqa: 711
|
||||
else:
|
||||
return [
|
||||
eff_schema.from_orm(x) for x in session.query(self.sql_model).filter(RecipeModel.tags == None).all()
|
||||
] # noqa: 711
|
||||
|
||||
def count_untagged(self, session: Session) -> int:
|
||||
return session.query(self.sql_model).filter(RecipeModel.tags == None).count() # noqa: 711
|
||||
def count_untagged(self, session: Session, count=True, override_schema=None) -> int:
|
||||
eff_schema = override_schema or self.schema
|
||||
if count:
|
||||
return session.query(self.sql_model).filter(RecipeModel.tags == None).count() # noqa: 711
|
||||
else:
|
||||
return [
|
||||
eff_schema.from_orm(x) for x in session.query(self.sql_model).filter(RecipeModel.tags == None).all()
|
||||
] # noqa: 711
|
||||
|
||||
|
||||
class _Categories(BaseDocument):
|
||||
|
|
|
@ -47,7 +47,7 @@ def export_database(data: BackupJob, session: Session = Depends(generate_session
|
|||
export_users=data.options.users,
|
||||
export_groups=data.options.groups,
|
||||
)
|
||||
create_backup_event("Manual Backup", f"Manual Backup Created '{Path(export_path).name}'", session)
|
||||
create_backup_event("Database Backup", f"Manual Backup Created '{Path(export_path).name}'", session)
|
||||
return {"export_path": export_path}
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
|
|
@ -8,7 +8,7 @@ from sqlalchemy.orm.session import Session
|
|||
router = APIRouter(tags=["Query All Recipes"])
|
||||
|
||||
|
||||
@router.get("/api/recipes/summary")
|
||||
@router.get("/api/recipes/summary", response_model=list[RecipeSummary])
|
||||
async def get_recipe_summary(
|
||||
start=0,
|
||||
limit=9999,
|
||||
|
@ -29,6 +29,16 @@ async def get_recipe_summary(
|
|||
return db.recipes.get_all(session, limit=limit, start=start, override_schema=RecipeSummary)
|
||||
|
||||
|
||||
@router.get("/api/recipes/summary/untagged", response_model=list[RecipeSummary])
|
||||
async def get_untagged_recipes(session: Session = Depends(generate_session)):
|
||||
return db.recipes.count_untagged(session, False, override_schema=RecipeSummary)
|
||||
|
||||
|
||||
@router.get("/api/recipes/summary/uncategorized", response_model=list[RecipeSummary])
|
||||
async def get_untagged_recipes(session: Session = Depends(generate_session)):
|
||||
return db.recipes.count_uncategorized(session, False, override_schema=RecipeSummary)
|
||||
|
||||
|
||||
@router.post("/api/recipes/category")
|
||||
def filter_by_category(categories: list, session: Session = Depends(generate_session)):
|
||||
""" pass a list of categories and get a list of recipes associated with those categories """
|
||||
|
|
|
@ -4,6 +4,7 @@ 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.recipe import Recipe, RecipeURLIn
|
||||
from mealie.services.events import create_recipe_event
|
||||
from mealie.services.image.image import scrape_image, write_image
|
||||
from mealie.services.recipe.media import check_assets, delete_assets
|
||||
from mealie.services.scraper.scraper import create_from_url
|
||||
|
@ -22,6 +23,8 @@ def create_from_json(
|
|||
""" Takes in a JSON string and loads data into the database as a new entry"""
|
||||
recipe: Recipe = db.recipes.create(session, data.dict())
|
||||
|
||||
create_recipe_event("Recipe Created", f"Recipe '{recipe.name}' created", session=session)
|
||||
|
||||
return recipe.slug
|
||||
|
||||
|
||||
|
@ -35,6 +38,7 @@ def parse_recipe_url(
|
|||
|
||||
recipe = create_from_url(url.url)
|
||||
recipe: Recipe = db.recipes.create(session, recipe.dict())
|
||||
create_recipe_event("Recipe Created (URL)", f"Recipe '{recipe.name}' created", session=session)
|
||||
|
||||
return recipe.slug
|
||||
|
||||
|
@ -91,9 +95,12 @@ def delete_recipe(
|
|||
""" Deletes a recipe by slug """
|
||||
|
||||
try:
|
||||
recipes = db.recipes.delete(session, recipe_slug)
|
||||
recipe: Recipe = db.recipes.delete(session, recipe_slug)
|
||||
delete_assets(recipe_slug=recipe_slug)
|
||||
return recipes
|
||||
create_recipe_event(
|
||||
"Recipe Deleted", f"'{recipe.name}' deleted by {current_user.full_name}", session=session
|
||||
)
|
||||
return recipe
|
||||
except Exception:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import uuid
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from mealie.core.security import get_password_hash
|
||||
from mealie.db.database import db
|
||||
from mealie.db.db_setup import generate_session
|
||||
from fastapi import APIRouter, Depends
|
||||
from mealie.routes.deps import get_current_user
|
||||
from mealie.schema.sign_up import SignUpIn, SignUpOut, SignUpToken
|
||||
from mealie.schema.user import UserIn, UserInDB
|
||||
from mealie.services.events import create_sign_up_event
|
||||
from sqlalchemy.orm.session import Session
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
router = APIRouter(prefix="/api/users/sign-ups", tags=["User Signup"])
|
||||
|
||||
|
@ -20,9 +20,7 @@ async def get_all_open_sign_ups(
|
|||
):
|
||||
""" Returns a list of open sign up links """
|
||||
|
||||
all_sign_ups = db.sign_ups.get_all(session)
|
||||
|
||||
return all_sign_ups
|
||||
return db.sign_ups.get_all(session)
|
||||
|
||||
|
||||
@router.post("", response_model=SignUpToken)
|
||||
|
@ -41,6 +39,7 @@ async def create_user_sign_up_key(
|
|||
"name": key_data.name,
|
||||
"admin": key_data.admin,
|
||||
}
|
||||
create_sign_up_event("Sign-up Token Created", f"Created by {current_user.full_name}", session=session)
|
||||
return db.sign_ups.create(session, sign_up)
|
||||
|
||||
|
||||
|
@ -63,6 +62,7 @@ async def create_user_with_token(
|
|||
db.users.create(session, new_user.dict())
|
||||
|
||||
# DeleteToken
|
||||
create_sign_up_event("Sign-up Token Used", f"New User {new_user.full_name}", session=session)
|
||||
db.sign_ups.delete(session, token)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue