You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.8 KiB
53 lines
1.8 KiB
from rest_framework import generics, permissions
|
|
from drf_yasg.utils import swagger_auto_schema
|
|
from drf_yasg import openapi
|
|
|
|
from apps.certificate.models import Certificate
|
|
from apps.certificate.serializers import CertificateRequestSerializer, CertificateSerializer
|
|
from utils.pagination import StandardResultsSetPagination
|
|
|
|
|
|
|
|
class CertificateRequestView(generics.CreateAPIView):
|
|
queryset = Certificate.objects.all()
|
|
serializer_class = CertificateRequestSerializer
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
@swagger_auto_schema(
|
|
operation_description="Request a certificate for completed course",
|
|
tags=["Imam-Javad - Certificate"],
|
|
responses={
|
|
201: openapi.Response(
|
|
description="Certificate request created successfully"
|
|
)
|
|
}
|
|
)
|
|
def post(self, request, *args, **kwargs):
|
|
return super().post(request, *args, **kwargs)
|
|
|
|
def perform_create(self, serializer):
|
|
serializer.save(student=self.request.user)
|
|
|
|
|
|
|
|
class UserCertificatesListView(generics.ListAPIView):
|
|
serializer_class = CertificateSerializer
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
pagination_class = StandardResultsSetPagination
|
|
|
|
@swagger_auto_schema(
|
|
operation_description="Get list of user's certificates",
|
|
tags=["Imam-Javad - Certificate"],
|
|
responses={
|
|
200: openapi.Response(
|
|
description="List of user certificates",
|
|
schema=CertificateSerializer(many=True)
|
|
)
|
|
}
|
|
)
|
|
def get(self, request, *args, **kwargs):
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
def get_queryset(self):
|
|
return Certificate.objects.filter(student=self.request.user).order_by('-created_at')
|
|
|