diff --git a/api/serializers/groep.py b/api/serializers/groep.py index fa686aa7..1a952555 100644 --- a/api/serializers/groep.py +++ b/api/serializers/groep.py @@ -9,7 +9,3 @@ class Meta: def create(self, validated_data): return Groep.objects.create(**validated_data) - - def update(self, instance, validated_data): - # Implement update method for Groep model - pass diff --git a/api/serializers/indiening.py b/api/serializers/indiening.py index e33f3f8d..a52b760b 100644 --- a/api/serializers/indiening.py +++ b/api/serializers/indiening.py @@ -9,7 +9,3 @@ class Meta: def create(self, validated_data): return Indiening.objects.create(**validated_data) - - def update(self, instance, validated_data): - # Implement update method for Indiening model - pass diff --git a/api/serializers/lesgever.py b/api/serializers/lesgever.py index 5b9c3062..7a0423a2 100644 --- a/api/serializers/lesgever.py +++ b/api/serializers/lesgever.py @@ -9,9 +9,3 @@ class Meta: def create(self, validated_data): return Lesgever.objects.create(**validated_data) - - def update(self, instance, validated_data): - instance.name = validated_data.get('name', instance.name) - # Update other fields similarly - instance.save() - return instance diff --git a/api/serializers/project.py b/api/serializers/project.py index 541bb701..ada59dc0 100644 --- a/api/serializers/project.py +++ b/api/serializers/project.py @@ -10,6 +10,3 @@ class Meta: def create(self, validated_data): return Project.objects.create(**validated_data) - def update(self, instance, validated_data): - # Implement update method for Project model - pass diff --git a/api/serializers/score.py b/api/serializers/score.py index 4daacc12..a7899445 100644 --- a/api/serializers/score.py +++ b/api/serializers/score.py @@ -10,6 +10,3 @@ class Meta: def create(self, validated_data): return Score.objects.create(**validated_data) - def update(self, instance, validated_data): - # Implement update method for Score model - pass diff --git a/api/serializers/student.py b/api/serializers/student.py new file mode 100644 index 00000000..c88b3254 --- /dev/null +++ b/api/serializers/student.py @@ -0,0 +1,11 @@ +from rest_framework import serializers +from api.models.student import Student + + +class StudentSerializer(serializers.ModelSerializer): + class Meta: + model = Student + fields = '__all__' + + def create(self, validated_data): + return Student.objects.create(**validated_data) diff --git a/api/serializers/vak.py b/api/serializers/vak.py index f88a0536..f42f9d9e 100644 --- a/api/serializers/vak.py +++ b/api/serializers/vak.py @@ -9,9 +9,3 @@ class Meta: def create(self, validated_data): return Vak.objects.create(**validated_data) - - def update(self, instance, validated_data): - instance.name = validated_data.get('name', instance.name) - # Update other fields similarly - instance.save() - return instance diff --git a/api/urls.py b/api/urls.py index cf55b13f..3d19119a 100644 --- a/api/urls.py +++ b/api/urls.py @@ -16,10 +16,14 @@ """ from django.contrib import admin from django.urls import path, include +from rest_framework.urlpatterns import format_suffix_patterns from .views.views import microsoft_association, login_redirect, home from .views.gebruiker import gebruiker_list, gebruiker_detail -from .views.vak import vak_list +from .views.vak import * +from .views.project import * +from .views.indiening import * +from .views.score import * urlpatterns = [ path('.well-known/microsoft-identity-association.json', microsoft_association), @@ -30,4 +34,13 @@ path('api/studenten/', gebruiker_list), path('api/studenten//', gebruiker_detail), path('api/vakken/', vak_list), + path('api/vakken/', vak_detail), + path('api/projecten', project_list), + path('api/projecten/', project_detail), + path('api/indieningen', indiening_list), + path('api/indieningen/', indiening_detail), + path('api/scores', score_list), + path('api/scores/', score_detail) ] + +urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/api/views/indiening.py b/api/views/indiening.py new file mode 100644 index 00000000..79afe4af --- /dev/null +++ b/api/views/indiening.py @@ -0,0 +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 ..models import Indiening +from ..serializers import IndieningSerializer + + +@api_view(['GET', 'POST']) +def indiening_list(request, format=None): + + if request.method == 'GET': + lesgevers = Indiening.objects.all() + serializer = IndieningSerializer(lesgevers, many=True) + return Response(serializer.data) + + elif request.method == 'POST': + serializer = IndieningSerializer(data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) + +@api_view(['GET', 'PUT', 'DELETE']) +def indiening_detail(request, id, format=None): + try: + indiening = Indiening.objects.get(pk=id) + except Indiening.DoesNotExist: + return Response(status=status.HTTP_404_NOT_FOUND) + + if request.method == 'GET': + serializer = IndieningSerializer(indiening) + return Response(serializer.data) + + elif request.method == 'PUT': + serializer = IndieningSerializer(indiening, 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': + indiening.delete() + return Response(status=status.HTTP_204_NO_CONTENT) diff --git a/api/views/project.py b/api/views/project.py new file mode 100644 index 00000000..df7476bb --- /dev/null +++ b/api/views/project.py @@ -0,0 +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 ..models import Project +from ..serializers import ProjectSerializer + + +@api_view(['GET', 'POST']) +def project_list(request, format=None): + + if request.method == 'GET': + lesgevers = Project.objects.all() + serializer = ProjectSerializer(lesgevers, many=True) + return Response(serializer.data) + + elif request.method == 'POST': + serializer = ProjectSerializer(data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) + +@api_view(['GET', 'PUT', 'DELETE']) +def project_detail(request, id, format=None): + try: + project = Project.objects.get(pk=id) + except Project.DoesNotExist: + return Response(status=status.HTTP_404_NOT_FOUND) + + if request.method == 'GET': + serializer = ProjectSerializer(project) + return Response(serializer.data) + + elif request.method == 'PUT': + serializer = ProjectSerializer(project, 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': + project.delete() + return Response(status=status.HTTP_204_NO_CONTENT) diff --git a/api/views/score.py b/api/views/score.py new file mode 100644 index 00000000..b24430ab --- /dev/null +++ b/api/views/score.py @@ -0,0 +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 ..models import Score +from ..serializers import ScoreSerializer + + +@api_view(['GET', 'POST']) +def score_list(request, format=None): + + if request.method == 'GET': + lesgevers = Score.objects.all() + serializer = ScoreSerializer(lesgevers, many=True) + return Response(serializer.data) + + elif request.method == 'POST': + serializer = ScoreSerializer(data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) + +@api_view(['GET', 'PUT', 'DELETE']) +def score_detail(request, id, format=None): + try: + score = Score.objects.get(pk=id) + except Score.DoesNotExist: + return Response(status=status.HTTP_404_NOT_FOUND) + + if request.method == 'GET': + serializer = ScoreSerializer(score) + return Response(serializer.data) + + elif request.method == 'PUT': + serializer = ScoreSerializer(score, 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': + score.delete() + return Response(status=status.HTTP_204_NO_CONTENT) diff --git a/api/views/student.py b/api/views/student.py new file mode 100644 index 00000000..35fb0dcd --- /dev/null +++ b/api/views/student.py @@ -0,0 +1,41 @@ +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 + + +@api_view(['GET', 'POST']) +def student_list(request): + if request.method == 'GET': + students = Student.objects.all() + serializer = StudentSerializer(students, many=True) + return Response(serializer.data) + elif request.method == 'POST': + serializer = StudentSerializer(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): + try: + student = Student.objects.get(pk=id) + except Student.DoesNotExist: + return Response(status=status.HTTP_404_NOT_FOUND) + + if request.method == 'GET': + serializer = StudentSerializer(student) + return Response(serializer.data) + elif request.method == 'PUT': + serializer = StudentSerializer(student, data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data) + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) diff --git a/api/views/vak.py b/api/views/vak.py index 907ae2a7..a64ad2e8 100644 --- a/api/views/vak.py +++ b/api/views/vak.py @@ -1,39 +1,42 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework import status -from api.models.vak import Vak -from api.serializers.vak import VakSerializer +from ..models import Vak +from ..serializers import VakSerializer @api_view(['GET', 'POST']) -def vak_list(request): +def vak_list(request, format=None): + if request.method == 'GET': lesgevers = Vak.objects.all() serializer = VakSerializer(lesgevers, many=True) return Response(serializer.data) + elif request.method == 'POST': serializer = VakSerializer(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 vak_detail(request, id): + +@api_view(['GET', 'PUT', 'DELETE']) +def vak_detail(request, id, format=None): try: - student = Vak.objects.get(pk=id) + vak = Vak.objects.get(pk=id) except Vak.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': - serializer = StudentSerializer(student) + serializer = VakSerializer(vak) return Response(serializer.data) + elif request.method == 'PUT': - serializer = StudentSerializer(student, data=request.data) + serializer = VakSerializer(vak, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - """ \ No newline at end of file + + elif request.method == 'DELETE': + vak.delete() + return Response(status=status.HTTP_204_NO_CONTENT)