o
    CnPfF                     @   sx   d dl mZ d dlmZ d dlmZ d dlmZ d dlZd dl	m
Z
 ddlmZ dd	lmZ ed
d Zedd ZdS )    )render)status)JsonResponse)csrf_exemptN)verify_token   )Notifications)NotificationSerializerc                 C   s   t | }|d krtdtjddtjdS | jdkrCt| j}t }|d |_	|d |_t
|d |_|  td	tjddtjdS tj }t|d
d}t|jtjddtjdS )NzUser not logged in.messager   Fsafer   POSTtitlebodysend_tozNotification Send succesfully.T)many)notificationsr   )r   r   r   HTTP_401_UNAUTHORIZEDmethodjsonloadsr   r   r   intr   saveHTTP_200_OKobjectsallr	   data)requestuser_idrequest_datanotificationr   
serializer r#   V/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_ADMIN_APIS/notifications/views.pyr      s   



r   c                 C   s   t | }|d krtdtjddtjdS zt| j}tjj	|d d
  tdtjddtjdW S  tjyH   tdtjddtjd Y S w )	NzUser not login.r
   Fr   id)r%   z!Notification deleted Successfullyz4Notification doesn't exists. Invalid Notification id)r   r   r   r   r   r   r   r   r   getdeleter   DoesNotExistHTTP_400_BAD_REQUEST)r   r   r    r#   r#   r$   deleteNotification    s   r*   )django.shortcutsr   rest_frameworkr   django.httpr   django.views.decorators.csrfr   r   authentication.authr   modelsr   r"   r	   r   r*   r#   r#   r#   r$   <module>   s    
