From 8f381062f88dd9c18cd1367f3c039898ee007302 Mon Sep 17 00:00:00 2001 From: Gowtham Sai <66207607+gowtham3105@users.noreply.github.com> Date: Mon, 12 Sep 2022 01:07:02 +0530 Subject: [PATCH] withDraw Application api --- CDC_Backend/APIs/studentUrls.py | 1 + CDC_Backend/APIs/studentViews.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CDC_Backend/APIs/studentUrls.py b/CDC_Backend/APIs/studentUrls.py index f532849..45b3619 100644 --- a/CDC_Backend/APIs/studentUrls.py +++ b/CDC_Backend/APIs/studentUrls.py @@ -9,4 +9,5 @@ urlpatterns = [ path("addResume/", studentViews.addResume, name="Upload Resume"), path("deleteResume/", studentViews.deleteResume, name="Upload Resume"), path("submitApplication/", studentViews.submitApplication, name="Submit Application"), + path("deleteApplication/", studentViews.deleteApplication, name="Delete Application"), ] diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index 0fbadd0..45993a5 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -204,3 +204,30 @@ def submitApplication(request, id, email, user_type): return Response({'action': "Submit Application", 'message': "Something Went Wrong"}, status=status.HTTP_400_BAD_REQUEST) + + +@api_view(['POST']) +@isAuthorized(allowed_users=[STUDENT]) +@precheck(required_data=[APPLICATION_ID]) +def deleteApplication(request, id, email, user_type): + try: + data = request.data + application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID], + student_id=id) + if application.placement.deadline_datetime < timezone.now(): + raise PermissionError("Deadline Passed") + + application.delete() + return Response({'action': "Delete Application", 'message': "Application Deleted"}, + status=status.HTTP_200_OK) + except Http404 as e: + return Response({'action': "Delete Application", 'message': str(e)}, + status=status.HTTP_404_NOT_FOUND) + except PermissionError as e: + return Response({'action': "Delete Application", 'message': str(e)}, + status=status.HTTP_403_FORBIDDEN) + except: + logger.warning("Delete Application: " + str(sys.exc_info())) + + return Response({'action': "Delete Application", 'message': "Something Went Wrong"}, + status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file