diff --git a/api/serializers/lesgever.py b/api/serializers/lesgever.py deleted file mode 100644 index 7a0423a2..00000000 --- a/api/serializers/lesgever.py +++ /dev/null @@ -1,11 +0,0 @@ -from rest_framework import serializers -from api.models.lesgever import Lesgever - - -class LesgeverSerializer(serializers.ModelSerializer): - class Meta: - model = Lesgever - fields = '__all__' - - def create(self, validated_data): - return Lesgever.objects.create(**validated_data) diff --git a/api/serializers/project.py b/api/serializers/project.py index ada59dc0..d398ddf9 100644 --- a/api/serializers/project.py +++ b/api/serializers/project.py @@ -1,5 +1,5 @@ from rest_framework import serializers -from api.models.project import Student, Lesgever, Vak, Groep, Project, Indiening, Score +from api.models.project import Project class ProjectSerializer(serializers.ModelSerializer): diff --git a/api/serializers/student.py b/api/serializers/student.py deleted file mode 100644 index c88b3254..00000000 --- a/api/serializers/student.py +++ /dev/null @@ -1,11 +0,0 @@ -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/urls.py b/api/urls.py index 3d19119a..bb78fb5d 100644 --- a/api/urls.py +++ b/api/urls.py @@ -20,10 +20,11 @@ from .views.views import microsoft_association, login_redirect, home from .views.gebruiker import gebruiker_list, gebruiker_detail -from .views.vak import * -from .views.project import * -from .views.indiening import * -from .views.score import * +from .views.vak import vak_list, vak_detail +from .views.project import project_list, project_detail +from .views.indiening import indiening_list, indiening_detail +from .views.score import score_list, score_detail +from .views.groep import groep_list, groep_detail urlpatterns = [ path('.well-known/microsoft-identity-association.json', microsoft_association), @@ -31,8 +32,8 @@ path('oauth2/', include('django_auth_adfs.urls')), path('login_redirect/', login_redirect), path('api/', home), - path('api/studenten/', gebruiker_list), - path('api/studenten//', gebruiker_detail), + path('api/gebruikers/', gebruiker_list), + path('api/gebruikers//', gebruiker_detail), path('api/vakken/', vak_list), path('api/vakken/', vak_detail), path('api/projecten', project_list), @@ -40,7 +41,9 @@ path('api/indieningen', indiening_list), path('api/indieningen/', indiening_detail), path('api/scores', score_list), - path('api/scores/', score_detail) + path('api/scores/', score_detail), + path('api/groepen', groep_list), + path('api/groepen/', groep_detail) ] urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/api/utils.py b/api/utils.py index 01f2f9ef..ea18ae67 100644 --- a/api/utils.py +++ b/api/utils.py @@ -5,10 +5,11 @@ API_URLS = { - 'studenten': '/api/studenten', + 'gebruikers': '/api/gebruikers', 'vakken': '/api/vakken', 'groepen': '/api/groepen', 'indieningen': '/api/indieningen', + 'scores': 'api/scores' } diff --git a/api/views/gebruiker.py b/api/views/gebruiker.py index 6466ae0b..83ec9976 100644 --- a/api/views/gebruiker.py +++ b/api/views/gebruiker.py @@ -42,17 +42,18 @@ def gebruiker_list(request): @api_view(['GET', 'PUT']) def gebruiker_detail(request, id): - try: - gebruiker = Gebruiker.objects.get(pk=id) - except Gebruiker.DoesNotExist: - return Response(status=status.HTTP_404_NOT_FOUND) - - if request.method == 'GET': - serializer = GebruikerSerializer(gebruiker) - return Response(serializer.data) - elif request.method == 'PUT': - serializer = GebruikerSerializer(gebruiker, data=request.data) - if serializer.is_valid(): - serializer.save() + if request.user.id == id: + try: + gebruiker = Gebruiker.objects.get(pk=id) + except Gebruiker.DoesNotExist: + return Response(status=status.HTTP_404_NOT_FOUND) + + if request.method == 'GET': + serializer = GebruikerSerializer(gebruiker) return Response(serializer.data) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + elif request.method == 'PUT': + serializer = GebruikerSerializer(gebruiker, 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/student.py b/api/views/groep.py similarity index 54% rename from api/views/student.py rename to api/views/groep.py index 35fb0dcd..4cfbac8e 100644 --- a/api/views/student.py +++ b/api/views/groep.py @@ -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) \ No newline at end of file diff --git a/api/views/indiening.py b/api/views/indiening.py index 79afe4af..2ca2dcff 100644 --- a/api/views/indiening.py +++ b/api/views/indiening.py @@ -1,9 +1,9 @@ -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 + +from api.models.indiening import Indiening +from api.serializers.indiening import IndieningSerializer @api_view(['GET', 'POST']) diff --git a/api/views/project.py b/api/views/project.py index df7476bb..197fe370 100644 --- a/api/views/project.py +++ b/api/views/project.py @@ -1,9 +1,9 @@ -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 + +from api.models.project import Project +from api.serializers.project import ProjectSerializer @api_view(['GET', 'POST']) diff --git a/api/views/score.py b/api/views/score.py index b24430ab..11c88727 100644 --- a/api/views/score.py +++ b/api/views/score.py @@ -1,9 +1,9 @@ -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 + +from api.models.score import Score +from api.serializers.score import ScoreSerializer @api_view(['GET', 'POST']) diff --git a/api/views/vak.py b/api/views/vak.py index a64ad2e8..5e0dffce 100644 --- a/api/views/vak.py +++ b/api/views/vak.py @@ -1,8 +1,9 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework import status -from ..models import Vak -from ..serializers import VakSerializer + +from api.models.vak import Vak +from api.serializers.vak import VakSerializer @api_view(['GET', 'POST'])