2020
2121import logging
2222from datetime import datetime
23+ from typing import Optional
2324
2425from PyMatcha .utils import create_notifications_table
2526from PyMatcha .utils .orm import Field
@@ -30,6 +31,7 @@ class Notification(Model):
3031 table_name = "notifications"
3132
3233 id = Field (int , modifiable = False )
34+ user_id = Field (int )
3335 dt_received = Field (datetime , fmt = "%Y-%m-%d %H:%M:%S" )
3436 content = Field (str )
3537 type = Field (str )
@@ -38,9 +40,20 @@ class Notification(Model):
3840
3941 @staticmethod
4042 def create (
41- content : str , type : str , link_to : str , is_seen : bool = False , dt_received : datetime = datetime .utcnow ()
43+ user_id : int ,
44+ content : str ,
45+ type : str ,
46+ link_to : Optional [str ],
47+ is_seen : bool = False ,
48+ dt_received : datetime = datetime .utcnow (),
4249 ) -> Notification :
43- new_notif = Notification (content = content , type = type , link_to = link_to , is_seen = is_seen , dt_received = dt_received )
50+ if type not in ["match" , "like" , "superlike" , "unlike" , "view" , "message" , "message_like" ]:
51+ raise ValueError (
52+ "type must be one of ['match', 'like', 'superlike', 'unlike', 'view', 'message', 'message_like']"
53+ )
54+ new_notif = Notification (
55+ user_id = user_id , content = content , type = type , link_to = link_to , is_seen = is_seen , dt_received = dt_received
56+ )
4457 new_notif .save ()
4558 logging .debug ("Creating new notification" )
4659 return new_notif
0 commit comments