Error logging, uprava dotazovani na seznam letu u kopilota

This commit is contained in:
Michal Kváček
2023-11-07 17:45:26 +01:00
parent e3ab6ba7f0
commit bd5b84c9e7
17 changed files with 88 additions and 136 deletions
+5
View File
@@ -4,6 +4,7 @@ from fastapi import HTTPException
from starlette.status import HTTP_401_UNAUTHORIZED
from database import models
from decorators.endpoints import authenticated_user_only
from decorators.error_logging import error_logging
from graphql_schema.entities.resolvers.base import BaseMutationResolver
from graphql_schema.entities.resolvers.event import EventQueryResolver
from graphql_schema.entities.types.mutation_input import CreateEventInput, EditEventInput
@@ -13,6 +14,7 @@ from graphql_schema.entities.types.types import Event
@strawberry.type
class EventQueries:
@strawberry.field()
@error_logging
async def events(root, info, username: Optional[str] = None) -> List[Event]:
if not info.context.user_id and not username:
raise HTTPException(HTTP_401_UNAUTHORIZED)
@@ -24,6 +26,7 @@ class EventQueries:
)
@strawberry.field()
@error_logging
async def event(root, info, id: int, username: Optional[str] = None) -> Event:
if not info.context.user_id and not username:
raise HTTPException(HTTP_401_UNAUTHORIZED)
@@ -38,11 +41,13 @@ class EventQueries:
@strawberry.type
class EventMutation:
@strawberry.mutation
@error_logging
@authenticated_user_only()
async def create_event(root, info, input: CreateEventInput) -> Event:
return await BaseMutationResolver(Event, models.Event).create(input.to_dict(), info.context.user_id)
@strawberry.mutation
@error_logging
@authenticated_user_only()
async def edit_event(root, info, id: int, input: EditEventInput) -> Event:
return await BaseMutationResolver(Event, models.Event).update(id, input, info.context.user_id)