mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-15 12:23:12 -05:00
Added validators for users and recipes (#1052)
* Added validators for users and recipes provide a simple get api, allowing to test for existence of - user by username - recipe by slug - group by name (not tested yet) * updated formatting * Use group_id+slug for recipes, use ValidationRespone * Fixed Flake8 errors and warnings * add missing field for TestUser init
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from random import randint
|
||||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
from uuid import UUID
|
||||
|
||||
from sqlalchemy import and_, func
|
||||
@@ -143,3 +143,13 @@ class RepositoryRecipes(RepositoryGeneric[Recipe, RecipeModel]):
|
||||
.order_by(func.random()) # Postgres and SQLite specific
|
||||
.limit(limit)
|
||||
]
|
||||
|
||||
def get_by_slug(self, group_id: UUID, slug: str, limit=1) -> Optional[Recipe]:
|
||||
dbrecipe = (
|
||||
self.session.query(RecipeModel)
|
||||
.filter(RecipeModel.group_id == group_id, RecipeModel.slug == slug)
|
||||
.one_or_none()
|
||||
)
|
||||
if dbrecipe is None:
|
||||
return None
|
||||
return self.schema.from_orm(dbrecipe)
|
||||
|
||||
Reference in New Issue
Block a user