From da8a66ad91189b74b5529ae30979470b6106625d Mon Sep 17 00:00:00 2001 From: Michael Bauer <michael-bauer@posteo.de> Date: Wed, 24 Apr 2024 13:04:48 +0200 Subject: [PATCH] Sketch backend --- aleksis/apps/alsijil/schema/__init__.py | 35 +++++++++++++++++++++++++ aleksis/apps/alsijil/schema/absences.py | 25 ++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 aleksis/apps/alsijil/schema/absences.py diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py index aae1b7060..a5709a12a 100644 --- a/aleksis/apps/alsijil/schema/__init__.py +++ b/aleksis/apps/alsijil/schema/__init__.py @@ -37,6 +37,13 @@ class Query(graphene.ObjectType): groups_by_person = FilterOrderList(GroupType, person=graphene.ID()) courses_of_person = FilterOrderList(CourseType, person=graphene.ID()) + lesson_events_for_absences = FilterOrderList( + PersonAbsencesType??, + persons=graphene.List(graphene.ID, required=True), + start=graphene.Date(required=True), + end=graphene.Date(required=True), + ) + def resolve_documentations_by_course_id(root, info, course_id, **kwargs): documentations = Documentation.objects.filter( Q(course__pk=course_id) | Q(amends__course__pk=course_id) @@ -116,6 +123,34 @@ class Query(graphene.ObjectType): | Q(groups__parent_groups__owners=person) ) + def lesson_events_for_absences( + root, + info, + persons, + start, + end, + **kwargs, + ): + # Do date like resolve_documentations_for_coursebook? + + # Get all lesson events for person + # Make this reusable for mutation + # Pack into (id fullname lesson (start end course subject ...)) + + event_params = { + "" + } + + events = LessonEvent.get_single_events( + start, + end, + request??, + event_params, + with_reference_object=True, + ) + + return class Mutation(graphene.ObjectType): create_or_update_documentations = DocumentationBatchCreateOrUpdateMutation.Field() + create_absences = AbsencesBatchCreateMutation.Field() diff --git a/aleksis/apps/alsijil/schema/absences.py b/aleksis/apps/alsijil/schema/absences.py new file mode 100644 index 000000000..f7c27a92b --- /dev/null +++ b/aleksis/apps/alsijil/schema/absences.py @@ -0,0 +1,25 @@ +import graphene + +class AbsencesBatchCreateMutation(graphene.Mutation): + class Arguments: + persons = graphene.List(graphene.ID) + start = graphene.Date(), + end = graphene.Date(), + comment = graphene.String(), + reason = graphene.ID() + + ok = graphene.Boolean() + + @classmethod + def mutate(cls, root, info, input): # noqa + # Get all lesson events for person (share with query) + # Look up documentations for lesson events + # (share with models.py Documentation get_for_coursebook; + # has lesson event lookup as well & returns real & fake documentations + # => extract & reuse the documentation lookup) + # Create a ParticipationStatus for each documentation + # If there are any LessonEvents without a documentation + # create a Kolego Absence for the whole duration + # Return ok=True if everything went well. + + return AbsencesBatchCreateMutation(ok=BOOL) -- GitLab