diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index db7f79f..d04a980 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -124,6 +124,8 @@ def updateDeadline(request, id, email, user_type): opening.deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z') opening.changed_by = get_object_or_404(User, id=id) opening.save() + deadline=opening.deadline_datetime.strftime('%Y-%m-%d %H:%M:%S') + send_opening_to_notifications_service(id=opening.id,name=opening.company_name,deadline=deadline,role=opening.designation) return Response({'action': "Update Deadline", 'message': "Deadline Updated"}, status=status.HTTP_200_OK) except Http404: @@ -160,6 +162,8 @@ def updateOfferAccepted(request, id, email, user_type): opening.changed_by = get_object_or_404(User, id=id) opening.save() if opening.offer_accepted: + deadline=deadline_datetime.strftime('%Y-%m-%d %H:%M:%S') + send_opening_to_notifications_service(id=opening.id,name=opening.company_name,deadline=deadline,role=opening.designation) send_opening_notifications(opening.id,opening_type) else: raise ValueError("Offer Status already updated") diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index 1827df0..a439233 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -562,3 +562,22 @@ def send_email_for_opening(opening): print("An error occurred while sending the email:", e) +@background_task.background(schedule=2) +def send_opening_to_notifications_service(id,name,deadline,role): + data={ + "id":id, + "company":name, + "deadline":deadline, + "role":role + } + encoded=jwt.encode(data,os.environ.get("JWT_SECRET_KEY"),algorithm="HS256") + data_={ + "token":encoded, + } + resp=rq.post(url=os.environ.get("PUSH_API_URL")+"addopening/",data=data_) + if resp.status_code==200: + print("Notification Sent") + else: + print("Notification Failed") + logger.warning("Utils - send_opening_to_notifications_service: " + str(resp) + "data sent:"+str(data)) +