-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kleine fixes en groepen view toegevoegd
- Loading branch information
ticoucke
committed
Mar 6, 2024
1 parent
b7cba9f
commit 087a526
Showing
11 changed files
with
58 additions
and
72 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
from django.http import JsonResponse | ||
from rest_framework.decorators import api_view | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
|
||
|
||
from api.models import Student | ||
from api.serializers import StudentSerializer | ||
#from ..utils import json_error | ||
from api.models.groep import Groep | ||
from api.serializers.groep import GroepSerializer | ||
|
||
|
||
@api_view(['GET', 'POST']) | ||
def student_list(request): | ||
def groep_list(request, format=None): | ||
|
||
if request.method == 'GET': | ||
students = Student.objects.all() | ||
serializer = StudentSerializer(students, many=True) | ||
lesgevers = Groep.objects.all() | ||
serializer = GroepSerializer(lesgevers, many=True) | ||
return Response(serializer.data) | ||
|
||
elif request.method == 'POST': | ||
serializer = StudentSerializer(data=request.data) | ||
serializer = GroepSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
|
||
@api_view(['GET', 'PUT']) | ||
def student_detail(request, id): | ||
@api_view(['GET', 'PUT', 'DELETE']) | ||
def groep_detail(request, id, format=None): | ||
try: | ||
student = Student.objects.get(pk=id) | ||
except Student.DoesNotExist: | ||
groep = Groep.objects.get(pk=id) | ||
except Groep.DoesNotExist: | ||
return Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
if request.method == 'GET': | ||
serializer = StudentSerializer(student) | ||
serializer = GroepSerializer(groep) | ||
return Response(serializer.data) | ||
|
||
elif request.method == 'PUT': | ||
serializer = StudentSerializer(student, data=request.data) | ||
serializer = GroepSerializer(groep, data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
elif request.method == 'DELETE': | ||
groep.delete() | ||
return Response(status=status.HTTP_204_NO_CONTENT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters