Skip to content

Commit

Permalink
Merge pull request #36 from E-Learn-ESI-SBA/fix
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
poysa213 authored Jun 7, 2024
2 parents a2a4dc6 + 9820b28 commit 3d44768
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
3 changes: 2 additions & 1 deletion authentication/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class UserViewSet(ModelViewSet):
serializer_class = UserSerializer
queryset = User.objects.all()
lookup_field = "id"
# permission_classes = [IsAuthenticated]
permission_classes = [IsAuthenticated]

@action(detail=True, methods=['get'])
def profile(self, request, id=None):
user = self.get_object()
Expand Down
8 changes: 5 additions & 3 deletions students/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class StudentViewSet(viewsets.ModelViewSet):
permission_classes = [IsAuthenticated]

def get_serializer_class(self):
print(self.request.data)
if self.action == 'create':
return CreateStudentSerializer
elif self.action in ['update', 'partial_update']:
Expand Down Expand Up @@ -74,14 +73,17 @@ def update(self, request, *args, **kwargs):

)
userStringify = json.dumps(user, separators=(',', ':'))
kafka_produce(settings.USER_MUTATION_TOPIC, userStringify)
thread = Thread(target=kafka_produce, args=[settings.USER_MUTATION_TOPIC, userStringify])
thread.start()
# kafka_produce(settings.USER_MUTATION_TOPIC, userStringify)
return response



class CreateManyStudentsView(APIView):
serializer_class = CreateStudentSerializer

permission_classes = [IsAuthenticated]

def post(self, request):
print(request.data)
serializer = self.serializer_class(data=request.data, many=True)
Expand Down
37 changes: 17 additions & 20 deletions teachers/api/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf import settings

from rest_framework.permissions import IsAuthenticated
from rest_framework import viewsets, generics, status
from rest_framework.views import APIView
from rest_framework.response import Response
Expand All @@ -9,7 +10,6 @@
from authentication.utils import create_permit_user
from authentication.interfaces import UserClaim
from authentication.models import User
from rest_framework.permissions import IsAuthenticated
import json
from kafka_runner.producer import kafka_produce

Expand Down Expand Up @@ -43,33 +43,30 @@ def create(self, request, *args, **kwargs):
return response
def update(self, request, *args, **kwargs):
response = super().update(request, *args, **kwargs)
# data = response.data["user"]
user = User.objects.filter(id=request.user.id).first()
print("data")
print(user.id)
print("data")
# print(request.user.id)
# user = User.objects.get(id=request.data["id"])
# user = UserClaim(
# username=data['username'],
# email=data['email'],
# role="teacher",
# id=data['id'],
# avatar=data['avatar'],
# group=data['group'],
# year=data['year']
# )
# userStringify = json.dumps(user, separators=(',', ':'))
data = response.data["user"]
teacher = Teacher.objects.filter(user__email=data["email"]).first()
user = UserClaim(
username=data.get('username', None),
email=data.get('email', None),
role="teacher",
id=data.get('id', None),
avatar=data.get('avatar_url', None),
)
userStringify = json.dumps(user, separators=(',', ':'))
thread = Thread(target=kafka_produce, args=[settings.USER_MUTATION_TOPIC, userStringify])
thread.start()
# kafka_produce(settings.USER_MUTATION_TOPIC, userStringify)
return response



class TeacherListView(generics.ListAPIView):
queryset = User.objects.all()
serializer_class = MinimalUserSerializer
# permission_classes = [IsAuthenticated]
permission_classes = [IsAuthenticated]

class CreateManyTeachersView(APIView):
serializer_class = CreateTeacherSerializer
permission_classes = [IsAuthenticated]
def post(self, request):
serializer = self.serializer_class(data=request.data, many=True)
if serializer.is_valid():
Expand Down

0 comments on commit 3d44768

Please sign in to comment.