mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2024-11-16 22:09:27 +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()
|
||||
|
||||
return user
|
||||
|
||||
|
||||
class ClearanceSerializer(serializers.Serializer):
|
||||
cleared = serializers.CharField()
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
from accounts.views import ClearanceViewSet
|
||||
urlpatterns = [
|
||||
path('', include('djoser.urls')),
|
||||
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
|
||||
description: A Project
|
||||
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/:
|
||||
post:
|
||||
operationId: api_v1_accounts_jwt_create_create
|
||||
|
@ -1051,7 +1065,7 @@ paths:
|
|||
schema:
|
||||
$ref: '#/components/schemas/Transaction'
|
||||
description: ''
|
||||
/api/v1/transactions/student:
|
||||
/api/v1/transactions/student/:
|
||||
get:
|
||||
operationId: api_v1_transactions_student_list
|
||||
tags:
|
||||
|
@ -1067,7 +1081,7 @@ paths:
|
|||
items:
|
||||
$ref: '#/components/schemas/Transaction'
|
||||
description: ''
|
||||
/api/v1/transactions/teacher:
|
||||
/api/v1/transactions/teacher/:
|
||||
get:
|
||||
operationId: api_v1_transactions_teacher_list
|
||||
tags:
|
||||
|
@ -1128,6 +1142,13 @@ components:
|
|||
description: |-
|
||||
* `Glassware` - Glassware
|
||||
* `Miscellaneous` - Miscellaneous
|
||||
Clearance:
|
||||
type: object
|
||||
properties:
|
||||
cleared:
|
||||
type: string
|
||||
required:
|
||||
- cleared
|
||||
CustomUser:
|
||||
type: object
|
||||
properties:
|
||||
|
|
|
@ -15,8 +15,7 @@ class TransactionViewSet(viewsets.ModelViewSet):
|
|||
|
||||
|
||||
class TransactionByStudentViewSet(generics.ListAPIView):
|
||||
# Only allow GET, POST/CREATE
|
||||
# Transactions cannot be deleted
|
||||
# Viewset for GET only
|
||||
http_method_names = ['get']
|
||||
permission_classes = [IsAuthenticated, IsStudent]
|
||||
serializer_class = TransactionSerializer
|
||||
|
@ -29,8 +28,7 @@ class TransactionByStudentViewSet(generics.ListAPIView):
|
|||
|
||||
|
||||
class TransactionByTeacherViewSet(generics.ListAPIView):
|
||||
# Only allow GET, POST/CREATE
|
||||
# Transactions cannot be deleted
|
||||
# Viewset for GET only
|
||||
http_method_names = ['get']
|
||||
permission_classes = [IsAuthenticated, IsTeacher]
|
||||
serializer_class = TransactionSerializer
|
||||
|
|
Loading…
Reference in a new issue