Skip to content
Snippets Groups Projects
Commit 8c55f4db authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Introduce API Post Endpoint for indication of interest in AK

This endpoint checks for validity of the request and increments the AK interest counter if currently allowed
parent 96a608f3
No related branches found
No related tags found
1 merge request!111add interest window
Pipeline #48606 failed
...@@ -26,11 +26,13 @@ if apps.is_installed("AKScheduling"): ...@@ -26,11 +26,13 @@ if apps.is_installed("AKScheduling"):
api_router.register('scheduling-constraint-violations', ConstraintViolationsViewSet, api_router.register('scheduling-constraint-violations', ConstraintViolationsViewSet,
basename='scheduling-constraint-violations') basename='scheduling-constraint-violations')
extra_paths = [ extra_paths.append(path('api/scheduling-events/', EventsView.as_view(), name='scheduling-events'))
path('api/scheduling-events/', EventsView.as_view(), name='scheduling-events'), extra_paths.append(path('api/scheduling-room-availabilities/', RoomAvailabilitiesView.as_view(),
path('api/scheduling-room-availabilities/', RoomAvailabilitiesView.as_view(), name='scheduling-room-availabilities'))
name='scheduling-room-availabilities'), if apps.is_installed("AKSubmission"):
] from AKSubmission.api import increment_interest_counter
extra_paths.append(path('api/ak/<pk>/indicate-interest/', increment_interest_counter, name='submission-ak-indicate-interest'))
event_specific_paths = [ event_specific_paths = [
path('api/', include(api_router.urls), name='api'), path('api/', include(api_router.urls), name='api'),
......
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from django.utils.datetime_safe import datetime
from AKModel.models import AK
def ak_interest_indication_active(event, current_timestamp):
"""
Check whether indication of interest is currently allowed for a given event
:param event: event to check for
:type event: Event
:param current_timestamp: current timestamp
:type current_timestamp: datetime
:return: True if indication is allowed, False if not
:rtype: Bool
"""
return event.active and (event.interest_start is None or (event.interest_start <= current_timestamp and (
event.interest_end is None or current_timestamp <= event.interest_end)))
@api_view(['POST'])
def increment_interest_counter(request, event_slug, pk, **kwargs):
"""
Increment interest counter for AK
"""
ak = AK.objects.get(pk=pk)
if ak:
# Check whether interest indication is currently allowed
current_timestamp = datetime.now().astimezone(ak.event.timezone)
if ak_interest_indication_active(ak.event, current_timestamp):
ak.interest_counter += 1
ak.save()
return Response(status=status.HTTP_200_OK)
return Response(status=status.HTTP_403_FORBIDDEN)
return Response(status=status.HTTP_404_NOT_FOUND)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment