Merge pull request #179 from uttamthummala/Internship-Update
Updated Backend to accomodate notifications
This commit is contained in:
commit
e702f70627
|
@ -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")
|
||||
|
|
|
@ -511,3 +511,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))
|
||||
|
||||
|
|
Loading…
Reference in New Issue