Add highlight mutation

This commit is contained in:
Ramon Wenger 2019-10-02 11:39:40 +02:00
parent 584b48a6a6
commit 4247164067
3 changed files with 43 additions and 1 deletions

View File

@ -0,0 +1,5 @@
mutation UpdateContentHighlight($input: UpdateContentHighlightInput!) {
updateContentHighlight(input: $input) {
success
}
}

View File

@ -10,6 +10,7 @@ from books.models import ContentBlock, Chapter, SchoolClass
from books.schema.inputs import ContentBlockInput
from books.schema.queries import ContentBlockNode
from core.utils import set_hidden_for, set_visible_for
from notes.models import ContentBlockHighlight
from .utils import handle_content_block, set_user_defined_block_type
@ -145,3 +146,37 @@ class DeleteContentBlock(relay.ClientIDMutation):
return cls(success=True)
except ContentBlock.DoesNotExist:
return cls(success=False, errors='Content block not found')
class UpdateContentHighlight(relay.ClientIDMutation):
class Input:
id = graphene.String(required=True)
content_block = graphene.ID(required=True)
highlight = graphene.Boolean(required=True)
success = graphene.Boolean()
errors = graphene.String()
@classmethod
def mutate_and_get_payload(cls, root, info, **kwargs):
id = kwargs.get('id')
user = info.context.user
content_block_id = kwargs.get('content_block')
highlight = kwargs.get('highlight')
content_block = get_object(ContentBlock, content_block_id)
if highlight:
ContentBlockHighlight.objects.create(
content_block=content_block,
id=id,
user=user
)
else:
ContentBlockHighlight.objects.get(
content_block=content_block,
id=id,
user=user
).delete()
return cls(success=True)

View File

@ -1,4 +1,5 @@
from books.schema.mutations.contentblock import MutateContentBlock, AddContentBlock, DeleteContentBlock
from books.schema.mutations.contentblock import MutateContentBlock, AddContentBlock, DeleteContentBlock, \
UpdateContentHighlight
from books.schema.mutations.module import UpdateSolutionVisibility, UpdateLastModule
@ -8,3 +9,4 @@ class BookMutations(object):
delete_content_block = DeleteContentBlock.Field()
update_solution_visibility = UpdateSolutionVisibility.Field()
update_last_module = UpdateLastModule.Field()
update_content_highlight = UpdateContentHighlight.Field()