Mazani letu (zatim jen zaklad), nastaveni cover fotky
This commit is contained in:
@@ -1,23 +1,36 @@
|
||||
from typing import List, Optional
|
||||
from typing import List
|
||||
import strawberry
|
||||
from strawberry.file_uploads import Upload
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import select, or_
|
||||
from database import models
|
||||
from graphql_schema.dataloaders.photos import poi_photos_dataloader
|
||||
from graphql_schema.entities.photo import Photo
|
||||
from graphql_schema.sqlalchemy_to_strawberry_type import strawberry_sqlalchemy_type, strawberry_sqlalchemy_input
|
||||
|
||||
|
||||
@strawberry_sqlalchemy_type(models.PointOfInterest)
|
||||
class PointOfInterest:
|
||||
pass
|
||||
async def load_photos(root):
|
||||
return await poi_photos_dataloader.load(root.id)
|
||||
|
||||
photos: List[Photo] = strawberry.field(resolver=load_photos)
|
||||
|
||||
|
||||
def get_base_query(user_id: int):
|
||||
return (
|
||||
def get_base_query(user_id: int, only_my: bool = False):
|
||||
query = (
|
||||
select(models.PointOfInterest)
|
||||
.filter(models.PointOfInterest.created_by_id == user_id)
|
||||
.filter(models.PointOfInterest.deleted.is_(False))
|
||||
)
|
||||
|
||||
if only_my:
|
||||
query = query.filter(models.PointOfInterest.created_by_id == user_id)
|
||||
else:
|
||||
query = query.filter(or_(
|
||||
models.PointOfInterest.created_by_id == user_id,
|
||||
models.PointOfInterest.is_public.is_(True)
|
||||
))
|
||||
|
||||
return query
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class PointOfInterestQueries:
|
||||
@@ -48,8 +61,6 @@ class CreatePointOfInterestMutation:
|
||||
|
||||
@strawberry.mutation
|
||||
async def create_point_of_interest(root, info, input: CreatePointOfInterestInput) -> PointOfInterest:
|
||||
# TODO: kontrola organizace
|
||||
|
||||
input_data = input.to_dict()
|
||||
return await models.PointOfInterest.create(
|
||||
info.context.db,
|
||||
@@ -62,16 +73,16 @@ class CreatePointOfInterestMutation:
|
||||
|
||||
@strawberry.type
|
||||
class EditPointOfInterestMutation:
|
||||
@strawberry_sqlalchemy_input(models.PointOfInterest, exclude_fields=['photo_filename'])
|
||||
@strawberry_sqlalchemy_input(models.PointOfInterest, exclude_fields=['id'])
|
||||
class EditPointOfInterestInput:
|
||||
photo: Optional[Upload]
|
||||
pass
|
||||
|
||||
@strawberry.mutation
|
||||
async def edit_PointOfInterest(root, info, id: int, input: EditPointOfInterestInput) -> PointOfInterest:
|
||||
async def edit_point_of_interest(root, info, id: int, input: EditPointOfInterestInput) -> PointOfInterest:
|
||||
# TODO: kontrola organizace
|
||||
# TODO: kontrola opravneni na akci
|
||||
|
||||
poi = await models.PointOfInterest.get_one(info.context.db, id)
|
||||
poi = (await get_base_query(info.context.user_id, only_my=True).filter(models.Photo.id == id)).one()
|
||||
return await models.PointOfInterest.update(info.context.db, obj=poi, data=input.to_dict())
|
||||
|
||||
|
||||
@@ -80,6 +91,6 @@ class DeletePointOfInterestMutation:
|
||||
|
||||
@strawberry.mutation
|
||||
async def delete_point_of_interest(self, info, id: int) -> PointOfInterest:
|
||||
# TODO: kontrola opravneni na akci
|
||||
poi = (await get_base_query(info.context.user_id, only_my=True).filter(models.Photo.id == id)).one()
|
||||
|
||||
return await models.PointOfInterest.update(info.context.db, id=id, data=dict(deleted=True))
|
||||
return await models.PointOfInterest.update(info.context.db, obj=poi, data=dict(deleted=True))
|
||||
|
||||
Reference in New Issue
Block a user