
    i              
       h   d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
mZmZmZ  e       ZdeddfdZej#                  d	       ee      fd
edeeef   fd       Zej-                  d       ee      fded
edeeef   fd       Zej1                  d       ee      fde
d
edeeef   fd       Zy)    )	APIRouterDependsHTTPExceptionstatus)require_session)get_push_public_key)PushSubscriptionDeletePayloadPushSubscriptionPayloadSessionIdentityget_tenant_storeexcreturnNc                     t        |       }d|j                         v rt        j                  nt        j                  }t        ||      | )Nzsolo l'admin)status_codedetail)strlowerr   HTTP_403_FORBIDDENHTTP_400_BAD_REQUESTr   )r   r   r   s      'apps/backend-hub/app/api/routes/push.py_raise_push_errorr      s;    XF/=/O&++U[UpUpK
K
?SH    z/public-keysessionc                 6    | }t               }t        |      |dS )N)	supported
public_key)r   bool)r   _r   s      r   get_public_keyr      s$    A$&J*%  r   z/subscriptionspayloadc                 z    	 t               j                  ||       S # t        $ r}t        |       Y d }~y d }~ww xY wN)r   upsert_push_subscription
ValueErrorr   r    r   r   s      r   register_subscriptionr&       s8    
!::7GLL #s    	:5:c                     	 t               j                  || j                        S # t        $ r}t	        |       Y d }~y d }~ww xY wr"   )r   delete_push_subscriptionendpointr$   r   r%   s      r   delete_subscriptionr*   +   s>    
!::7GDTDTUU #s   #& 	A?A)fastapir   r   r   r   app.api.depsr   &app.services.push_notification_servicer   app.services.tenant_storer	   r
   r   r   routerr$   r   getdictr   objectr   postr&   deleter*    r   r   <module>r6      s   = = ( F  
I: I$ I M.5o.F O 4PSU[P[K\     '7$ 
#v+     '7* 
#v+ !r   