Skip to content
Snippets Groups Projects
Verified Commit 0aa0cd1c authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

feat: provide some data on bad requests

parent 465d06ac
No related branches found
No related tags found
No related merge requests found
......@@ -1115,8 +1115,9 @@ class APIScheduleViewSet(viewsets.ModelViewSet):
if request.method == "PATCH":
# only these fields can be updated without generating conflicts
allowed = {"default_playlist_id", "is_repetition", "last_date"}
update_fields = set(request.data.get("schedule").keys())
if set(request.data.get("schedule").keys()).issubset(allowed):
if update_fields.issubset(allowed):
schedule = self.get_object()
default_playlist_id = request.data.get("schedule").get("default_playlist_id")
......@@ -1148,14 +1149,19 @@ class APIScheduleViewSet(viewsets.ModelViewSet):
TimeSlot.objects.filter(schedule=schedule, start__gt=last_end).delete()
else:
return Response(status=status.HTTP_400_BAD_REQUEST)
data = {"last_date": "This field cannot be updated to this date"}
return Response(data, status=status.HTTP_400_BAD_REQUEST)
schedule.save()
serializer = ScheduleSerializer(schedule)
return Response(serializer.data)
else:
return Response(status=status.HTTP_400_BAD_REQUEST)
bad_fields = update_fields.difference(allowed)
data = {field: "This field cannot be updated with PATCH" for field in bad_fields}
return Response(data, status=status.HTTP_400_BAD_REQUEST)
# Only allow updating when with the `schedule` JSON object
if "schedule" not in request.data:
......
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