Skip to content

Commit

Permalink
kleine fixes en groepen view toegevoegd
Browse files Browse the repository at this point in the history
  • Loading branch information
ticoucke committed Mar 6, 2024
1 parent b7cba9f commit 087a526
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 72 deletions.
11 changes: 0 additions & 11 deletions api/serializers/lesgever.py

This file was deleted.

2 changes: 1 addition & 1 deletion api/serializers/project.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
11 changes: 0 additions & 11 deletions api/serializers/student.py

This file was deleted.

17 changes: 10 additions & 7 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@

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),
path('admin/', admin.site.urls),
path('oauth2/', include('django_auth_adfs.urls')),
path('login_redirect/', login_redirect),
path('api/', home),
path('api/studenten/', gebruiker_list),
path('api/studenten/<int:id>/', gebruiker_detail),
path('api/gebruikers/', gebruiker_list),
path('api/gebruikers/<int:id>/', gebruiker_detail),
path('api/vakken/', vak_list),
path('api/vakken/<int:id>', vak_detail),
path('api/projecten', project_list),
path('api/projecten/<int:id>', project_detail),
path('api/indieningen', indiening_list),
path('api/indieningen/<int:id>', indiening_detail),
path('api/scores', score_list),
path('api/scores/<int:id>', score_detail)
path('api/scores/<int:id>', score_detail),
path('api/groepen', groep_list),
path('api/groepen/<int:id>', groep_detail)
]

urlpatterns = format_suffix_patterns(urlpatterns)
3 changes: 2 additions & 1 deletion api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@


API_URLS = {
'studenten': '/api/studenten',
'gebruikers': '/api/gebruikers',
'vakken': '/api/vakken',
'groepen': '/api/groepen',
'indieningen': '/api/indieningen',
'scores': 'api/scores'
}


Expand Down
27 changes: 14 additions & 13 deletions api/views/gebruiker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
36 changes: 19 additions & 17 deletions api/views/student.py → api/views/groep.py
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)
6 changes: 3 additions & 3 deletions api/views/indiening.py
Original file line number Diff line number Diff line change
@@ -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'])
Expand Down
6 changes: 3 additions & 3 deletions api/views/project.py
Original file line number Diff line number Diff line change
@@ -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'])
Expand Down
6 changes: 3 additions & 3 deletions api/views/score.py
Original file line number Diff line number Diff line change
@@ -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'])
Expand Down
5 changes: 3 additions & 2 deletions api/views/vak.py
Original file line number Diff line number Diff line change
@@ -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'])
Expand Down

0 comments on commit 087a526

Please sign in to comment.