Skip to content

Commit b05a75a

Browse files
committed
Allow filtering for schedules by priority in application event endpoint
1 parent fb7e3cf commit b05a75a

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

api/graphql/types/application_event/types.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ApplicationEventNode(DjangoAuthNode):
3232
min_duration = Duration()
3333
max_duration = Duration()
3434

35-
application_event_schedules = ApplicationEventScheduleNode.ListField()
35+
application_event_schedules = ApplicationEventScheduleNode.ListField(priority=graphene.List(graphene.Int))
3636
event_reservation_units = EventReservationUnitNode.ListField(preferred_order=graphene.Int())
3737

3838
class Meta:
@@ -71,6 +71,12 @@ def filter_queryset(cls, queryset: models.QuerySet, user: AnyUser) -> models.Que
7171
| models.Q(application__user=user)
7272
).distinct()
7373

74+
def resolve_application_event_schedules(root: ApplicationEvent, info: GQLInfo, **kwargs: Any) -> models.QuerySet:
75+
priority: list[int] | None = kwargs.get("priority")
76+
if priority is not None:
77+
return root.application_event_schedules.filter(priority__in=priority)
78+
return root.application_event_schedules.all()
79+
7480
def resolve_event_reservation_units(root: ApplicationEvent, info: GQLInfo, **kwargs: Any) -> models.QuerySet:
7581
preferred_order: int | None = kwargs.get("preferred_order")
7682
if preferred_order is not None:

tests/test_graphql_api/test_application_event/test_filtering.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from tests.factories import (
66
AgeGroupFactory,
77
ApplicationEventFactory,
8+
ApplicationEventScheduleFactory,
89
ApplicationFactory,
910
CityFactory,
1011
ReservationPurposeFactory,
@@ -491,6 +492,39 @@ def test_application_event__filter__by_priority__multiple(graphql):
491492
assert response.node(1) == {"pk": event_2.pk}
492493

493494

495+
def test_application_event__filter__schedule_priority(graphql):
496+
# given:
497+
# - There is an application event with schedules of different priorities
498+
# - A superuser is using the system
499+
schedule_high = ApplicationEventScheduleFactory.create(priority=PriorityChoice.HIGH)
500+
ApplicationEventScheduleFactory.create(
501+
application_event=schedule_high.application_event, priority=PriorityChoice.MEDIUM
502+
)
503+
schedule_low = ApplicationEventScheduleFactory.create(
504+
application_event=schedule_high.application_event, priority=PriorityChoice.LOW
505+
)
506+
graphql.login_user_based_on_type(UserType.SUPERUSER)
507+
508+
# when:
509+
# - User tries to filter application event schedules with a specific priority
510+
query = events_query(
511+
fields="pk applicationEventSchedules { pk priority }",
512+
application_event_schedules__priority=[PriorityChoice.HIGH.value, PriorityChoice.LOW.value],
513+
)
514+
response = graphql(query)
515+
516+
# then:
517+
# - The response contains no errors
518+
# - The response contains the right application event with only the requested schedules
519+
assert response.has_errors is False, response
520+
assert len(response.edges) == 1, response
521+
assert response.node(0)["pk"] == schedule_high.application_event.pk
522+
assert response.node(0)["applicationEventSchedules"] == [
523+
{"pk": schedule_high.pk, "priority": PriorityChoice.HIGH},
524+
{"pk": schedule_low.pk, "priority": PriorityChoice.LOW},
525+
]
526+
527+
494528
def test_application_event__filter__by_preferred_order(graphql):
495529
# given:
496530
# - There is a draft application with application events with different preferred orders

0 commit comments

Comments
 (0)