mirror of
https://github.com/rjNemo/graphql_python_template
synced 2026-06-06 02:26:47 +00:00
create close Todo Mutation
This commit is contained in:
parent
0049fe0eee
commit
22e377df36
4 changed files with 30 additions and 2 deletions
|
|
@ -1,3 +1,4 @@
|
|||
from .close_todo import CloseTodo
|
||||
from .create_todo import CreateTodo
|
||||
from .delete_todo import DeleteTodo
|
||||
from .update_todo import UpdateTodo
|
||||
from .update_todo import UpdateTodo
|
||||
|
|
|
|||
15
app/schema/mutations/close_todo.py
Normal file
15
app/schema/mutations/close_todo.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import graphene
|
||||
|
||||
from app.schema.types.todo import TodoType
|
||||
from app.usecases.close_todo import close_todo
|
||||
|
||||
|
||||
class CloseTodo(graphene.Mutation):
|
||||
class Arguments:
|
||||
todo_id = graphene.String(required=True)
|
||||
|
||||
todo = graphene.Field(TodoType)
|
||||
|
||||
def mutate(self, info, todo_id: str):
|
||||
todo = close_todo(todo_id)
|
||||
return CloseTodo(todo=todo)
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
import graphene
|
||||
|
||||
from . import CreateTodo, DeleteTodo, UpdateTodo
|
||||
from . import CreateTodo, DeleteTodo, UpdateTodo, CloseTodo
|
||||
|
||||
|
||||
class Mutations(graphene.ObjectType):
|
||||
create_todo = CreateTodo.Field()
|
||||
update_todo = UpdateTodo.Field()
|
||||
delete_todo = DeleteTodo.Field()
|
||||
close_todo = CloseTodo.Field()
|
||||
|
|
|
|||
11
app/usecases/close_todo.py
Normal file
11
app/usecases/close_todo.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from app.models.todo import Todo
|
||||
from app.repositories.todos import get_todo_by_id, todo_exists
|
||||
|
||||
|
||||
def close_todo(todo_id: str) -> Todo:
|
||||
if not todo_exists(todo_id):
|
||||
return None
|
||||
|
||||
todo = get_todo_by_id(todo_id)
|
||||
todo.is_done = True
|
||||
return todo
|
||||
Loading…
Reference in a new issue