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:
Matthias Bilger
2022-03-15 23:28:42 +01:00
committed by GitHub
parent c8c02036a3
commit e109391e9a
12 changed files with 129 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import random
import shutil
from typing import Optional
from mealie.assets import users as users_assets
from mealie.schema.user.user import PrivateUser, User
@@ -34,3 +35,9 @@ class RepositoryUsers(RepositoryGeneric[PrivateUser, User]):
# Delete the user's directory
shutil.rmtree(PrivateUser.get_directory(id))
return entry
def get_by_username(self, username: str, limit=1) -> Optional[User]:
dbuser = self.session.query(User).filter(User.username == username).one_or_none()
if dbuser is None:
return None
return self.schema.from_orm(dbuser)