
    \gw                     4    d dl mZmZ d dlmZ d Zd Zd ZdS )    )requestjsonify)get_db_connectionc                  N   	 t           j        } |                     d          }|                     d          }|                     d          }|r|r|st          ddi          dfS t	                      }|                                }|                    d|||f           |                                 |                                 |                                 t          dd	i          d
fS # t          $ r*}t          dt          |          i          dfcY d }~S d }~ww xY w)Nuser_idtitlemessageerrorz!Missing user_id, title or message  z|
            INSERT INTO notifications (user_id, title, message, created_at)
            VALUES (%s, %s, %s, NOW())
        statuszNotification sent     r   jsongetr   r   cursorexecutecommitclose	Exceptionstr)datar   r   r	   connr   es          :/var/www/wisegym.app/api/functions/notification_service.pysend_notificationr      s@   /|((9%%!!((9%% 	Pe 	P7 	PG%HIJJCOO ""  ug&	( 	( 	( 	

"5677<< / / /Q())3......./s%   A#C0 &B	C0 0
D$:DD$D$c                 ~   	 t                      }|                    d          }|                    d| f           |                                }|                                 |                                 t          |          S # t          $ r*}t          dt          |          i          dfcY d }~S d }~ww xY w)NT)
dictionaryz
            SELECT id, title, message, created_at
            FROM notifications
            WHERE user_id = %s
            ORDER BY created_at DESC
        r
   r   )r   r   r   fetchallr   r   r   r   )r   r   r   resultsr   s        r   get_notifications_for_userr!      s    / ""-- 
 Z	 	 	 //##

w / / /Q())3......./s   BB 
B<B71B<7B<c                     	 t           j        } |                     d          }|st          ddi          dfS t	                      }|                                }|                    d|f           |                                 |                                 |                                 t          ddi          dfS # t          $ r*}t          dt          |          i          d	fcY d }~S d }~ww xY w)
Nnotification_idr
   zMissing notification_idr   z'DELETE FROM notifications WHERE id = %sr   zNotification deleted   r   r   )r   notif_idr   r   r   s        r   delete_notificationr&   .   s    /|88-.. 	FG%>?@@#EE ""@8+NNN

"89::C?? / / /Q())3......./s#   5C  BC   
C4
C/)C4/C4N)flaskr   r   	db_configr   r   r!   r&        r   <module>r+      sf    " " " " " " " " ' ' ' ' ' '/ / /2/ / /"/ / / / /r*   