mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2024-11-16 22:09:27 +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):
|
||||
model = CustomUser
|
||||
fields = ('username', 'email', 'avatar', 'first_name',
|
||||
fields = ('id', 'username', 'email', 'avatar', 'first_name',
|
||||
'last_name', 'is_teacher', 'is_technician')
|
||||
|
||||
|
||||
|
@ -56,3 +56,4 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
|
|||
|
||||
class ClearanceSerializer(serializers.Serializer):
|
||||
cleared = serializers.CharField()
|
||||
uncleared_transactions = serializers.IntegerField()
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from accounts.views import ClearanceViewSet
|
||||
from accounts import views
|
||||
urlpatterns = [
|
||||
path('', include('djoser.urls')),
|
||||
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 rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import generics
|
||||
from accounts.serializers import ClearanceSerializer
|
||||
from accounts.serializers import ClearanceSerializer, CustomUserSerializer
|
||||
from rest_framework.response import Response
|
||||
from accounts.models import CustomUser
|
||||
|
||||
|
||||
class ClearanceViewSet(generics.GenericAPIView):
|
||||
|
@ -20,7 +21,30 @@ class ClearanceViewSet(generics.GenericAPIView):
|
|||
queryset = self.get_queryset()
|
||||
status_list = ["Approved", "Borrowed", "Returned: Pending Checking",
|
||||
"With Breakages: Pending Resolution"]
|
||||
uncleared_transactions = 0
|
||||
for transaction in queryset:
|
||||
if transaction.transaction_status in status_list:
|
||||
return Response({"cleared": "Uncleared"})
|
||||
return Response({"cleared": "Cleared"})
|
||||
uncleared_transactions += 1
|
||||
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:
|
||||
$ref: '#/components/schemas/TokenVerify'
|
||||
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/:
|
||||
get:
|
||||
operationId: api_v1_accounts_users_list
|
||||
|
@ -1147,8 +1179,11 @@ components:
|
|||
properties:
|
||||
cleared:
|
||||
type: string
|
||||
uncleared_transactions:
|
||||
type: integer
|
||||
required:
|
||||
- cleared
|
||||
- uncleared_transactions
|
||||
CustomUser:
|
||||
type: object
|
||||
properties:
|
||||
|
|
Loading…
Reference in a new issue