
    hB	                     z   d dl mZmZmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZmZ d dlmZ d dlmZmZ  e       Z e        ej/                  d	ee   
       ee      fdefd       Zej5                  d       ee      fdededefd       Zej;                  d       ee      fdedefd       Zy)    )	APIRouterDependsHTTPException)Pagepaginate)"disable_installed_extensions_check)desc)Notification)NotificationBaseNotificationUpdateSendNotification)check_token_validity)send_push_notification_by_tokensend_push_notification_by_topic )response_modeldependenciesc                    | \  }}|j                  t              j                  t        j                  |j                  k(        j                  t        t        j                              j                         }t        |      S )N)	queryr
   filteruser_ididorder_byr	   allr   )r   dbusernotificationss       P/Users/theessential/Documents/Github/Lekema-Backend/app/routers/notifications.pyget_notificationsr      s_    HBHH\*11,2F2F$''2QR[[\`amapap\qrvvxMM""    z/{notification_id}notification_idnotificationc                 j   |\  }}|j                  t              j                  t        j                  | k(        j	                         }|t        dd      |j                         j                         D ]  \  }}|	t        |||        |j                          |j                  |       dd|dS )Ni  zNotification not foundstatus_codedetailTu$   Notification modifiée avec succès!)statusmessager"   )r   r
   r   r   firstr   
model_dumpitemssetattrcommitrefresh)r!   r"   r   r   r   db_notificationkeyvalues           r   update_notificationr2      s    HBhh|,33LOO4VW]]_O4LMM"--/557 1
UOS%01 IIKJJ 9' r    z/send-notificationc                 (   |\  }}| j                   s| j                  st        dd      | j                  r,t        | j                  | j                  | j
                        }n+t        | j                   | j                  | j
                        }dd|dS )Ni  z-Either topic or device_token must be providedr$   Fu#   Notification envoyée avec succès!)r'   r(   result)topicdevice_tokenr   r   titlecontentr   )r"   r   r   r   r4   s        r   send_notificationr9   /   s    HBl&?&?4cdd  01J1JLL^L^`l`t`tu01C1C\EWEWYeYmYmn8 r    N)fastapir   r   r   fastapi_paginationr   r   fastapi_pagination.utilsr   
sqlalchemyr	   app.models.notificationr
   app.schemas.notificationr   r   r   app.utils.authentificationr   app.utils.helpersr   r   routergettupler   putintr2   postr9    r    r   <module>rI      s    5 5 - G  0 [ [ ; ^	 # $ Bt$456,34H,I #E # 7#  !fm  oC  gD  <N ^c  "( !"LSThLi $4 E  #r    