Skip to content

Commit

Permalink
Merge pull request #32 from SELab-2/user_notification_link
Browse files Browse the repository at this point in the history
User field notifications
  • Loading branch information
Topvennie authored Mar 1, 2024
2 parents 4dc4980 + 4e7d131 commit 45a05cb
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
5 changes: 5 additions & 0 deletions backend/api/serializers/admin_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

class AdminSerializer(serializers.ModelSerializer):

faculties = serializers.HyperlinkedRelatedField(
many=True,
read_only=True,
view_name='faculty-detail'
)

class Meta:
model = Admin
Expand Down
6 changes: 6 additions & 0 deletions backend/api/serializers/assistant_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class AssistantSerializer(serializers.ModelSerializer):
read_only=True,
)

faculties = serializers.HyperlinkedRelatedField(
many=True,
read_only=True,
view_name='faculty-detail'
)

class Meta:
model = Assistant
fields = [
Expand Down
6 changes: 6 additions & 0 deletions backend/api/serializers/student_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class StudentSerializer(serializers.ModelSerializer):
read_only=True,
)

faculties = serializers.HyperlinkedRelatedField(
many=True,
read_only=True,
view_name='faculty-detail'
)

class Meta:
model = Student
fields = [
Expand Down
6 changes: 6 additions & 0 deletions backend/api/serializers/teacher_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class TeacherSerializer(serializers.ModelSerializer):
read_only=True,
)

faculties = serializers.HyperlinkedRelatedField(
many=True,
read_only=True,
view_name='faculty-detail'
)

class Meta:
model = Teacher
fields = [
Expand Down
28 changes: 22 additions & 6 deletions backend/authentication/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django.contrib.auth.models import update_last_login
from rest_framework.serializers import CharField, EmailField, ModelSerializer, ValidationError, Serializer
from rest_framework.serializers import (
CharField, EmailField, ModelSerializer, ValidationError,
Serializer, HyperlinkedIdentityField, HyperlinkedRelatedField
)
from rest_framework_simplejwt.tokens import RefreshToken, AccessToken
from rest_framework_simplejwt.settings import api_settings
from authentication.signals import user_created, user_login
Expand Down Expand Up @@ -65,23 +68,36 @@ def validate(self, data):
'refresh': str(RefreshToken.for_user(user))
}


class UserSerializer(ModelSerializer):
"""Serializer for the user model
This serializer validates the user fields for creation and updating.
"""
id = CharField()
username = CharField()
email = EmailField()

email = EmailField()

faculties = HyperlinkedRelatedField(
many=True,
read_only=True,
view_name='faculty-detail'
)

notifications = HyperlinkedIdentityField(
view_name='notification-detail',
read_only=True,
)

class Meta:
model = User
fields = [
'id', 'username', 'email',
'first_name', 'last_name',
'faculty',
'last_enrolled', 'last_login', 'create_time'
'faculties',
'last_enrolled', 'last_login', 'create_time',
'notifications'
]

def get_or_create(self, validated_data: dict) -> User:
"""Create or fetch the user based on the validated data."""
return User.objects.get_or_create(**validated_data)
return User.objects.get_or_create(**validated_data)

0 comments on commit 45a05cb

Please sign in to comment.