
    ,:j                          d dl mZ d dlmZ d dlmZ ddlmZ ddlm	Z	 d dl
mZ  G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Zy)    )APIView)Responsestatus   )Notification)NotificationSerializer)verify_tokenc                       e Zd Zd Zy)NotificationsViewc                 `   t        |      }|st        ddit        j                        S t        j
                  j                  |      j                  d      }t        |d      }|j                  d	      j                         }t        d
|j                         ||j                  dd      S )NmessageUnauthorizedr   )user_idz-idT)manyFis_readz"Notifications fetched successfully   )r   countunread_countnotificationsr   )r
   r   r   HTTP_401_UNAUTHORIZEDr   objectsfilterorder_byr	   r   data)selfrequestr   r   
serializerr   s         1/var/www/html/HOMYLIO_ADMIN/notifications/apis.pygetzNotificationsView.get   s    w'~ 33	  %,,33 4 

(5/ 	 ,


 %++ , 

%' 	 ?&,,. ,!+
 	
    N__name__
__module____qualname__r!    r"   r    r   r      s    !
r"   r   c                       e Zd Zd Zy)MarkNotificationReadViewc                    t        |      }|st        ddit        j                        S |j                  j                  d      }|st        ddit        j                        S 	 t        j                  j                  ||      }d|_	        |j                          t        dd	d
      S # t        j                  $ r  t        ddit        j                        cY S w xY w)Nr   r   r   notification_idnotification_id is requiredidr   TzNotification marked as readr   r   r   Notification not found)r
   r   r   r   r   r!   HTTP_400_BAD_REQUESTr   r   r   saveDoesNotExistHTTP_404_NOT_FOUNDr   r   r   r+   notifications        r    postzMarkNotificationReadView.post4   s    w'~ 33	  ",,**
 < 22	 	'//33" 4 L
 $(L <!  (( 	7 00	 	s   &AB, ,0CCNr$   r%   r&   r7   r'   r"   r    r)   r)   2   s    0r"   r)   c                       e Zd Zd Zy)MarkAllNotificationsReadViewc                     t        |      }|st        ddit        j                        S t        j
                  j                  |d      j                  d       t        dd	d
      S )Nr   r   r   Fr   r   Tr   z All notifications marked as readr   r/   )r
   r   r   r   r   r   r   update)r   r   r   s      r    r7   z!MarkAllNotificationsReadView.postj   s    w'~ 33	  	## 	$ 	
 &  
 =
 	
r"   Nr8   r'   r"   r    r:   r:   h   s    
r"   r:   c                       e Zd Zd Zy)DeleteNotificationViewc                    t        |      }|st        ddit        j                        S |j                  j                  d      }|st        ddit        j                        S 	 t        j                  j                  ||      }|j                          t        ddd	      S # t        j                  $ r  t        dd
it        j                        cY S w xY w)Nr   r   r   r+   r,   r-   z!Notification deleted successfullyr   r/   r0   )r
   r   r   r   r   r!   r1   r   r   deleter3   r4   r5   s        r    r7   zDeleteNotificationView.post   s    w'~ 33	  ",,**
 < 22	 	'//33" 4 L
 !B!  (( 	7 00	 	s   &>B% %0CCNr8   r'   r"   r    r?   r?      s    /r"   r?   c                       e Zd Zd Zy)NotificationCountViewc                     t        |      }|st        ddit        j                        S t        j
                  j                  |d      j                         }t        |dd      S )Nr   r   r   Fr<   r   )r   r   )r
   r   r   r   r   r   r   r   )r   r   r   r   s       r    r!   zNotificationCountView.get   sz    w'~ 33	  $++22 3 
 %' 	
  ,
 	
r"   Nr#   r'   r"   r    rC   rC      s    
r"   rC   N)rest_framework.viewsr   rest_framework.responser   rest_frameworkr   modelsr   serializersr	   utils.helpersr
   r   r)   r:   r?   rC   r'   r"   r    <module>rK      sV    ( , !   / &#
 #
N2w 2l
7 
>1W 1j
G 
r"   