Skip to content

Commit 9af6018

Browse files
committed
Added for who the message is and another message type
1 parent a93b5d4 commit 9af6018

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

backend/PyMatcha/models/notification.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import logging
2222
from datetime import datetime
23+
from typing import Optional
2324

2425
from PyMatcha.utils import create_notifications_table
2526
from 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

backend/PyMatcha/utils/tables.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,10 @@ def _create_notifications_table(db):
228228
CREATE TABLE IF NOT EXISTS notifications
229229
(
230230
id INT auto_increment PRIMARY KEY,
231+
user_id INT NOT NULL,
231232
dt_received DATETIME DEFAULT NOW(),
232233
content LONGTEXT NOT NULL,
233-
type ENUM('match', 'like', 'superlike', 'unlike', 'view', 'message'),
234+
type ENUM('match', 'like', 'superlike', 'unlike', 'view', 'message', 'message_like'),
234235
is_seen BOOLEAN DEFAULT FALSE,
235236
link_to VARCHAR(256)
236237
) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci ;

0 commit comments

Comments
 (0)