Skip to content

Commit

Permalink
Merge pull request #18 from SELab-2/backend
Browse files Browse the repository at this point in the history
Merged backend with develop branch
  • Loading branch information
LGDTimtou authored Mar 4, 2024
2 parents b55fe40 + 9de4354 commit dec3ebf
Show file tree
Hide file tree
Showing 38 changed files with 282 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
projectenv
/venv/
__pycache__
**/__pycache__/
migrations
.env
htmlcov
5 changes: 0 additions & 5 deletions api/.env

This file was deleted.

Binary file removed api/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed api/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed api/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file removed api/__pycache__/middleware.cpython-311.pyc
Binary file not shown.
Binary file removed api/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file removed api/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file removed api/__pycache__/serializers.cpython-311.pyc
Binary file not shown.
Binary file removed api/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file removed api/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file removed api/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file removed api/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file removed api/__pycache__/utils.cpython-310.pyc
Binary file not shown.
Binary file removed api/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Binary file removed api/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file removed api/__pycache__/wsgi.cpython-310.pyc
Binary file not shown.
Binary file removed api/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
11 changes: 8 additions & 3 deletions api/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from django.contrib import admin
from .models import *

from .models.student import *
from .models.lesgever import *
from .models.vak import *
from .models.groep import *
from .models.project import *
from .models.indiening import *
from .models.score import *

admin.site.register(Student)
admin.site.register(Lesgever)
admin.site.register(Vak)
admin.site.register(Groep)
admin.site.register(Project)
admin.site.register(Indiening)
admin.site.register(Score)
admin.site.register(Score)
10 changes: 10 additions & 0 deletions api/models/groep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models


class Groep(models.Model):
group_id = models.AutoField(primary_key=True)
students = models.ManyToManyField('Student', related_name='groups_students', blank=True)
project = models.ForeignKey('Project', on_delete=models.CASCADE)

def __str__(self):
return f"Group {self.group_id}"
12 changes: 12 additions & 0 deletions api/models/indiening.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models


class Indiening(models.Model):
indiening_id = models.AutoField(primary_key=True)
indiener = models.ForeignKey('Groep', on_delete=models.CASCADE)
indieningsbestanden = models.FileField(upload_to='uploads/')
tijdstip = models.DateTimeField(null=False)

def __str__(self):
return self.tijdstip

12 changes: 12 additions & 0 deletions api/models/lesgever.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models


class Lesgever(models.Model):
lesgever_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
email = models.EmailField(default='[email protected]')
subjects = models.ManyToManyField('Vak', related_name='lesgevers_enrolled', blank=True)
is_admin = models.BooleanField(default=False)

def __str__(self):
return self.name
15 changes: 15 additions & 0 deletions api/models/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.db import models
from .vak import Vak


class Project(models.Model):
project_id = models.AutoField(primary_key=True)
titel = models.CharField(max_length=100)
description = models.TextField()
opgavebestanden = models.FileField(upload_to='opgave/')
vak = models.ForeignKey(Vak, on_delete=models.CASCADE)
deadline = models.DateTimeField(null=True)
# indiening restricties

def __str__(self):
return self.titel
10 changes: 10 additions & 0 deletions api/models/score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models


class Score(models.Model):
score = models.SmallIntegerField()
indiening = models.ForeignKey('Indiening', on_delete=models.CASCADE)
groep = models.ForeignKey('Groep', on_delete=models.CASCADE)

def __str__(self):
return self.score
10 changes: 10 additions & 0 deletions api/models/student.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models
from django.contrib.auth.models import User


class Student(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE,primary_key=True,default=None)
subjects = models.ManyToManyField('Vak', related_name='students_enrolled')

def __str__(self):
return self.user.first_name
12 changes: 12 additions & 0 deletions api/models/vak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models


class Vak(models.Model):
vak_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
students = models.ManyToManyField('Student', related_name='subjects_enrolled', blank=True)
teachers = models.ManyToManyField('Lesgever', related_name='subjects_teachers')
projects = models.ManyToManyField('Project', related_name='subjects_projects', blank=True)

def __str__(self):
return self.name
15 changes: 15 additions & 0 deletions api/serializers/groep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers
from api.models.groep import Groep


class GroepSerializer(serializers.ModelSerializer):
class Meta:
model = Groep
fields = '__all__'

def create(self, validated_data):
return Groep.objects.create(**validated_data)

def update(self, instance, validated_data):
# Implement update method for Groep model
pass
15 changes: 15 additions & 0 deletions api/serializers/indiening.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers
from api.models.indiening import Indiening


class IndieningSerializer(serializers.ModelSerializer):
class Meta:
model = Indiening
fields = '__all__'

def create(self, validated_data):
return Indiening.objects.create(**validated_data)

def update(self, instance, validated_data):
# Implement update method for Indiening model
pass
17 changes: 17 additions & 0 deletions api/serializers/lesgever.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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)

def update(self, instance, validated_data):
instance.name = validated_data.get('name', instance.name)
# Update other fields similarly
instance.save()
return instance
15 changes: 15 additions & 0 deletions api/serializers/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers
from api.models.project import Student, Lesgever, Vak, Groep, Project, Indiening, Score


class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = '__all__'

def create(self, validated_data):
return Project.objects.create(**validated_data)

def update(self, instance, validated_data):
# Implement update method for Project model
pass
15 changes: 15 additions & 0 deletions api/serializers/score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers
from api.models.score import Score


class ScoreSerializer(serializers.ModelSerializer):
class Meta:
model = Score
fields = '__all__'

def create(self, validated_data):
return Score.objects.create(**validated_data)

def update(self, instance, validated_data):
# Implement update method for Score model
pass
41 changes: 41 additions & 0 deletions api/serializers/student.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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)

def update(self, instance, validated_data):
# Update the regular fields
instance.name = validated_data.get('name', instance.name)
instance.email = validated_data.get('email', instance.email)
# Update the subjects list
subjects_data = validated_data.pop('subjects', None)
if subjects_data is not None:
instance.subjects.clear() # Remove existing subjects
for subject_data in subjects_data:
instance.subjects.add(subject_data)

instance.save()
return instance

# gebruiksvoorbeelden

# serializing objects
#serializer = ProfSerializer(prof)
#serializer.data
#json = JSONRenderer().render(serializer.data)
#json

#deserializing objects
#stream = io.BytesIO(json)
#data = JSONParser().parse(stream)
#serializer = ProfSerializer(data=data)
#serializer.is_valid()
#serializer.validated_data
#serializer.save()
17 changes: 17 additions & 0 deletions api/serializers/vak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from rest_framework import serializers
from api.models.vak import Vak


class VakSerializer(serializers.ModelSerializer):
class Meta:
model = Vak
fields = '__all__'

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
Binary file removed api/views/__pycache__/student.cpython-311.pyc
Binary file not shown.
Binary file removed api/views/__pycache__/views.cpython-311.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions api/views/lesgever.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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.lesgever import Lesgever
from api.serializers.lesgever import LesgeverSerializer


@api_view(['GET', 'POST'])
def lesgever_list(request):
if request.method == 'GET':
lesgevers = Lesgever.objects.all()
serializer = LesgeverSerializer(lesgevers, many=True)
return JsonResponse({'lesgevers': serializer.data})
elif request.method == 'POST':
serializer = LesgeverSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
18 changes: 18 additions & 0 deletions api/views/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
from rest_framework import status


<<<<<<< HEAD
from api.models.student import Student
from api.serializers.student import StudentSerializer
from ..utils import json_error
=======
from ..models import Student
from ..serializers.student import StudentSerializer
>>>>>>> develop


@api_view(['GET', 'POST'])
Expand All @@ -19,6 +25,17 @@ def student_list(request):
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
<<<<<<< HEAD


"""if request.user.is_superuser:
students = Student.objects.all()
serializer = StudentSerializer(students, many=True)
return JsonResponse({'studenten': serializer.data})
else:
return json_error('no_perm')"""
=======
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


Expand All @@ -38,3 +55,4 @@ def student_detail(request, id):
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
>>>>>>> develop
19 changes: 19 additions & 0 deletions api/views/vak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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.vak import Vak
from api.serializers.vak import VakSerializer


@api_view(['GET', 'POST'])
def lesgever_list(request):
if request.method == 'GET':
lesgevers = Vak.objects.all()
serializer = VakSerializer(lesgevers, many=True)
return JsonResponse({'lesgevers': 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)

0 comments on commit dec3ebf

Please sign in to comment.