Skip to content

Commit

Permalink
Merge branch 'backend' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sPAICEcake committed Mar 6, 2024
2 parents 811b5bb + de53418 commit b7cba9f
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 40 deletions.
4 changes: 0 additions & 4 deletions api/serializers/groep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions api/serializers/indiening.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions api/serializers/lesgever.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions api/serializers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions api/serializers/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions api/serializers/student.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 0 additions & 6 deletions api/serializers/vak.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 14 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -30,4 +34,13 @@
path('api/studenten/', gebruiker_list),
path('api/studenten/<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)
]

urlpatterns = format_suffix_patterns(urlpatterns)
43 changes: 43 additions & 0 deletions api/views/indiening.py
Original file line number Diff line number Diff line change
@@ -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)
43 changes: 43 additions & 0 deletions api/views/project.py
Original file line number Diff line number Diff line change
@@ -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)
43 changes: 43 additions & 0 deletions api/views/score.py
Original file line number Diff line number Diff line change
@@ -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)
41 changes: 41 additions & 0 deletions api/views/student.py
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 16 additions & 13 deletions api/views/vak.py
Original file line number Diff line number Diff line change
@@ -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)
"""

elif request.method == 'DELETE':
vak.delete()
return Response(status=status.HTTP_204_NO_CONTENT)

0 comments on commit b7cba9f

Please sign in to comment.