mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2024-11-17 06:19:26 +08:00
Add clearance viewset for student
This commit is contained in:
parent
5c8a99675d
commit
372e466744
5 changed files with 56 additions and 9 deletions
|
@ -52,3 +52,7 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
class ClearanceSerializer(serializers.Serializer):
|
||||||
|
cleared = serializers.CharField()
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
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
|
||||||
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()),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
from django.shortcuts import render
|
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 rest_framework.response import Response
|
||||||
|
|
||||||
# Create your views here.
|
|
||||||
|
class ClearanceViewSet(generics.GenericAPIView):
|
||||||
|
# Check all transactions associated with the student. If any are uncleared or not finalized, return uncleared
|
||||||
|
http_method_names = ['get']
|
||||||
|
permission_classes = [IsAuthenticated, IsStudent]
|
||||||
|
serializer_class = ClearanceSerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
user = self.request.user
|
||||||
|
return Transaction.objects.filter(borrower=user)
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
queryset = self.get_queryset()
|
||||||
|
status_list = ["Approved", "Borrowed", "Returned: Pending Checking",
|
||||||
|
"With Breakages: Pending Resolution"]
|
||||||
|
for transaction in queryset:
|
||||||
|
if transaction.transaction_status in status_list:
|
||||||
|
return Response({"cleared": "Uncleared"})
|
||||||
|
return Response({"cleared": "Cleared"})
|
||||||
|
|
|
@ -4,6 +4,20 @@ info:
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
description: A Project
|
description: A Project
|
||||||
paths:
|
paths:
|
||||||
|
/api/v1/accounts/clearance/:
|
||||||
|
get:
|
||||||
|
operationId: api_v1_accounts_clearance_retrieve
|
||||||
|
tags:
|
||||||
|
- api
|
||||||
|
security:
|
||||||
|
- jwtAuth: []
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Clearance'
|
||||||
|
description: ''
|
||||||
/api/v1/accounts/jwt/create/:
|
/api/v1/accounts/jwt/create/:
|
||||||
post:
|
post:
|
||||||
operationId: api_v1_accounts_jwt_create_create
|
operationId: api_v1_accounts_jwt_create_create
|
||||||
|
@ -1051,7 +1065,7 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Transaction'
|
$ref: '#/components/schemas/Transaction'
|
||||||
description: ''
|
description: ''
|
||||||
/api/v1/transactions/student:
|
/api/v1/transactions/student/:
|
||||||
get:
|
get:
|
||||||
operationId: api_v1_transactions_student_list
|
operationId: api_v1_transactions_student_list
|
||||||
tags:
|
tags:
|
||||||
|
@ -1067,7 +1081,7 @@ paths:
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/Transaction'
|
$ref: '#/components/schemas/Transaction'
|
||||||
description: ''
|
description: ''
|
||||||
/api/v1/transactions/teacher:
|
/api/v1/transactions/teacher/:
|
||||||
get:
|
get:
|
||||||
operationId: api_v1_transactions_teacher_list
|
operationId: api_v1_transactions_teacher_list
|
||||||
tags:
|
tags:
|
||||||
|
@ -1128,6 +1142,13 @@ components:
|
||||||
description: |-
|
description: |-
|
||||||
* `Glassware` - Glassware
|
* `Glassware` - Glassware
|
||||||
* `Miscellaneous` - Miscellaneous
|
* `Miscellaneous` - Miscellaneous
|
||||||
|
Clearance:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
cleared:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- cleared
|
||||||
CustomUser:
|
CustomUser:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -15,8 +15,7 @@ class TransactionViewSet(viewsets.ModelViewSet):
|
||||||
|
|
||||||
|
|
||||||
class TransactionByStudentViewSet(generics.ListAPIView):
|
class TransactionByStudentViewSet(generics.ListAPIView):
|
||||||
# Only allow GET, POST/CREATE
|
# Viewset for GET only
|
||||||
# Transactions cannot be deleted
|
|
||||||
http_method_names = ['get']
|
http_method_names = ['get']
|
||||||
permission_classes = [IsAuthenticated, IsStudent]
|
permission_classes = [IsAuthenticated, IsStudent]
|
||||||
serializer_class = TransactionSerializer
|
serializer_class = TransactionSerializer
|
||||||
|
@ -29,8 +28,7 @@ class TransactionByStudentViewSet(generics.ListAPIView):
|
||||||
|
|
||||||
|
|
||||||
class TransactionByTeacherViewSet(generics.ListAPIView):
|
class TransactionByTeacherViewSet(generics.ListAPIView):
|
||||||
# Only allow GET, POST/CREATE
|
# Viewset for GET only
|
||||||
# Transactions cannot be deleted
|
|
||||||
http_method_names = ['get']
|
http_method_names = ['get']
|
||||||
permission_classes = [IsAuthenticated, IsTeacher]
|
permission_classes = [IsAuthenticated, IsTeacher]
|
||||||
serializer_class = TransactionSerializer
|
serializer_class = TransactionSerializer
|
||||||
|
|
Loading…
Reference in a new issue