mirror of
https://github.com/rjNemo/graphql_python_template
synced 2026-06-06 02:26:47 +00:00
fix multiple assignments
This commit is contained in:
parent
6cfd322939
commit
3ead154903
1 changed files with 8 additions and 0 deletions
|
|
@ -1,8 +1,13 @@
|
||||||
|
from app.models import User, Todo
|
||||||
from app.repositories.users import add_todo_to_user
|
from app.repositories.users import add_todo_to_user
|
||||||
from app.usecases.todo import read_todo_by_id
|
from app.usecases.todo import read_todo_by_id
|
||||||
from app.usecases.user.read_user_by_id import read_user_by_id
|
from app.usecases.user.read_user_by_id import read_user_by_id
|
||||||
|
|
||||||
|
|
||||||
|
def is_already_assigned(user: User, todo: Todo) -> bool:
|
||||||
|
return any([task == todo for task in user.tasks])
|
||||||
|
|
||||||
|
|
||||||
def assign_todo_to_user(user_id: str, todo_id: str) -> bool:
|
def assign_todo_to_user(user_id: str, todo_id: str) -> bool:
|
||||||
user, is_success = read_user_by_id(user_id)
|
user, is_success = read_user_by_id(user_id)
|
||||||
if not is_success:
|
if not is_success:
|
||||||
|
|
@ -12,4 +17,7 @@ def assign_todo_to_user(user_id: str, todo_id: str) -> bool:
|
||||||
if not is_success:
|
if not is_success:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if is_already_assigned(user, todo):
|
||||||
|
return False
|
||||||
|
|
||||||
return add_todo_to_user(todo, user)
|
return add_todo_to_user(todo, user)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue