mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2024-11-17 06:19:26 +08:00
Add viewsets for listing teachers and technicians
This commit is contained in:
parent
372e466744
commit
9d2f777ffc
4 changed files with 68 additions and 6 deletions
|
@ -18,7 +18,7 @@ class CustomUserSerializer(BaseUserSerializer):
|
||||||
|
|
||||||
class Meta(BaseUserSerializer.Meta):
|
class Meta(BaseUserSerializer.Meta):
|
||||||
model = CustomUser
|
model = CustomUser
|
||||||
fields = ('username', 'email', 'avatar', 'first_name',
|
fields = ('id', 'username', 'email', 'avatar', 'first_name',
|
||||||
'last_name', 'is_teacher', 'is_technician')
|
'last_name', 'is_teacher', 'is_technician')
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,3 +56,4 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class ClearanceSerializer(serializers.Serializer):
|
class ClearanceSerializer(serializers.Serializer):
|
||||||
cleared = serializers.CharField()
|
cleared = serializers.CharField()
|
||||||
|
uncleared_transactions = serializers.IntegerField()
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from accounts.views import ClearanceViewSet
|
from accounts import views
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include('djoser.urls')),
|
path('', include('djoser.urls')),
|
||||||
path('', include('djoser.urls.jwt')),
|
path('', include('djoser.urls.jwt')),
|
||||||
path('clearance/', ClearanceViewSet.as_view()),
|
path('clearance/', views.ClearanceViewSet.as_view()),
|
||||||
|
path('teachers/', views.TeacherViewSet.as_view()),
|
||||||
|
path('technicians/', views.TechnicianViewSet.as_view()),
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,8 +2,9 @@ from transactions.models import Transaction
|
||||||
from accounts.permissions import IsStudent
|
from accounts.permissions import IsStudent
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
from accounts.serializers import ClearanceSerializer
|
from accounts.serializers import ClearanceSerializer, CustomUserSerializer
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from accounts.models import CustomUser
|
||||||
|
|
||||||
|
|
||||||
class ClearanceViewSet(generics.GenericAPIView):
|
class ClearanceViewSet(generics.GenericAPIView):
|
||||||
|
@ -20,7 +21,30 @@ class ClearanceViewSet(generics.GenericAPIView):
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
status_list = ["Approved", "Borrowed", "Returned: Pending Checking",
|
status_list = ["Approved", "Borrowed", "Returned: Pending Checking",
|
||||||
"With Breakages: Pending Resolution"]
|
"With Breakages: Pending Resolution"]
|
||||||
|
uncleared_transactions = 0
|
||||||
for transaction in queryset:
|
for transaction in queryset:
|
||||||
if transaction.transaction_status in status_list:
|
if transaction.transaction_status in status_list:
|
||||||
return Response({"cleared": "Uncleared"})
|
uncleared_transactions += 1
|
||||||
return Response({"cleared": "Cleared"})
|
if uncleared_transactions > 0:
|
||||||
|
return Response({"cleared": "Uncleared", "uncleared_transactions": uncleared_transactions})
|
||||||
|
return Response({"cleared": "Cleared", "uncleared_transactions": 0})
|
||||||
|
|
||||||
|
|
||||||
|
class TeacherViewSet(generics.ListAPIView):
|
||||||
|
# Returns list of users who are teachers
|
||||||
|
http_method_names = ['get']
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
serializer_class = CustomUserSerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return CustomUser.objects.filter(is_teacher=True)
|
||||||
|
|
||||||
|
|
||||||
|
class TechnicianViewSet(generics.ListAPIView):
|
||||||
|
# Returns list of users who are technicians
|
||||||
|
http_method_names = ['get']
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
serializer_class = CustomUserSerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return CustomUser.objects.filter(is_technician=True)
|
||||||
|
|
|
@ -99,6 +99,38 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/TokenVerify'
|
$ref: '#/components/schemas/TokenVerify'
|
||||||
description: ''
|
description: ''
|
||||||
|
/api/v1/accounts/teachers/:
|
||||||
|
get:
|
||||||
|
operationId: api_v1_accounts_teachers_list
|
||||||
|
tags:
|
||||||
|
- api
|
||||||
|
security:
|
||||||
|
- jwtAuth: []
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/CustomUser'
|
||||||
|
description: ''
|
||||||
|
/api/v1/accounts/technicians/:
|
||||||
|
get:
|
||||||
|
operationId: api_v1_accounts_technicians_list
|
||||||
|
tags:
|
||||||
|
- api
|
||||||
|
security:
|
||||||
|
- jwtAuth: []
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/CustomUser'
|
||||||
|
description: ''
|
||||||
/api/v1/accounts/users/:
|
/api/v1/accounts/users/:
|
||||||
get:
|
get:
|
||||||
operationId: api_v1_accounts_users_list
|
operationId: api_v1_accounts_users_list
|
||||||
|
@ -1147,8 +1179,11 @@ components:
|
||||||
properties:
|
properties:
|
||||||
cleared:
|
cleared:
|
||||||
type: string
|
type: string
|
||||||
|
uncleared_transactions:
|
||||||
|
type: integer
|
||||||
required:
|
required:
|
||||||
- cleared
|
- cleared
|
||||||
|
- uncleared_transactions
|
||||||
CustomUser:
|
CustomUser:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
Loading…
Reference in a new issue