From cfa8c1b854db7216efd90f9c0c03d03ec97e93e3 Mon Sep 17 00:00:00 2001 From: Ernest Litvinenko Date: Wed, 10 Jul 2024 19:09:37 +0300 Subject: [PATCH] bugfix --- core/transport/graphql/schema.py | 20 +++++++++++++++++--- core/transport/rest/tasks/handlers.py | 1 + main.py | 3 --- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/transport/graphql/schema.py b/core/transport/graphql/schema.py index a607ef2..b5876ce 100644 --- a/core/transport/graphql/schema.py +++ b/core/transport/graphql/schema.py @@ -45,7 +45,8 @@ class MarshTemperaturePropertyQL(Enum): class Query: @strawberry.field - def tasks(self, user_id: str, is_planned: typing.Optional[bool] = False, is_completed: typing.Optional[bool] = False) -> list['AppTaskQL']: + def tasks(self, user_id: str, is_planned: typing.Optional[bool] = False, + is_completed: typing.Optional[bool] = False) -> list['AppTaskQL']: tasks = task_storage.fetch_tasks_with_subtasks(user_id) if is_planned: @@ -72,6 +73,15 @@ class Query: except StopIteration: return None + @strawberry.field + def count_planned_tasks(self, user_id: str) -> int: + return len( + [x for x in task_storage.fetch_tasks_with_subtasks(int(user_id)) if x.status == x.status.NOT_DEFINED]) + + @strawberry.field + def count_completed_tasks(self, user_id: str) -> int: + return len([x for x in task_storage.fetch_tasks_with_subtasks(int(user_id)) if x.status == x.status.COMPLETED]) + @strawberry.field def notes(self, user_id: str) -> list['AppNoteQL']: return note_storage.fetch_all_notes_for_user(int(user_id)) @@ -84,6 +94,10 @@ class Query: except StopIteration: return None + @strawberry.field + def subtasks(self, user_id: str) -> list['SubtaskQL']: + return [s for t in task_storage.fetch_tasks_with_subtasks(int(user_id)) for s in t.subtasks] + @strawberry.experimental.pydantic.type(model=Location) class LocationQL: @@ -105,7 +119,7 @@ class SubtaskQL: start_fact: strawberry.auto end_fact: strawberry.auto status: StatusEnumQl - task_type: int + task_type: str text: str station: typing.Optional[MSTQL] = None @@ -151,7 +165,7 @@ class AppTaskQL: start_fact: strawberry.auto end_fact: strawberry.auto status: StatusEnumQl - task_type: int + task_type: str text: strawberry.auto events: list[AppEventQL] diff --git a/core/transport/rest/tasks/handlers.py b/core/transport/rest/tasks/handlers.py index 3e2888d..63fcacf 100644 --- a/core/transport/rest/tasks/handlers.py +++ b/core/transport/rest/tasks/handlers.py @@ -29,6 +29,7 @@ async def get_tasks(user: ProfileDB = Depends(get_user_from_token)) -> list[DBAp @router.post("") async def upd_task(req: UpdTaskRequest, user: ProfileDB = Depends(get_user_from_token)) -> list[DBAppTask]: + print(req) def check_task_in_progress(e: UpdTaskData, t: DBAppTask): t.subtasks.sort(key=lambda u: u.start_pln) try: diff --git a/main.py b/main.py index a6074ce..9ad6eaa 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,4 @@ -from importlib import reload - from fastapi import FastAPI, Request -from fastapi.responses import JSONResponse from fastapi.exceptions import RequestValidationError from core.transport.rest import router