Skip to content

Commit 7afc01a

Browse files
committed
[feat] user notification settings: add marketing column
1 parent 009ae30 commit 7afc01a

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

fixbackend/notification/user_notification_repo.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
@frozen
3232
class UserNotificationSettings:
3333
user_id: UserId
34-
weekly_report: bool
35-
inactivity_reminder: bool
36-
tutorial: bool
34+
weekly_report: bool = True
35+
inactivity_reminder: bool = True
36+
tutorial: bool = True
37+
marketing: bool = True
3738

3839

3940
class UserNotificationSettingsEntity(CreatedUpdatedMixin, Base):
@@ -43,13 +44,15 @@ class UserNotificationSettingsEntity(CreatedUpdatedMixin, Base):
4344
weekly_report: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
4445
inactivity_reminder: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
4546
tutorial: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
47+
marketing: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
4648

4749
def to_model(self) -> UserNotificationSettings:
4850
return UserNotificationSettings(
4951
user_id=self.user_id,
5052
weekly_report=self.weekly_report,
5153
inactivity_reminder=self.inactivity_reminder,
5254
tutorial=self.tutorial,
55+
marketing=self.marketing,
5356
)
5457

5558
@staticmethod
@@ -59,6 +62,7 @@ def from_model(settings: UserNotificationSettings) -> "UserNotificationSettingsE
5962
weekly_report=settings.weekly_report,
6063
inactivity_reminder=settings.inactivity_reminder,
6164
tutorial=settings.tutorial,
65+
marketing=settings.marketing,
6266
)
6367

6468

@@ -72,9 +76,7 @@ async def get_notification_settings(self, user_id: UserId) -> UserNotificationSe
7276
if result := await session.get(UserNotificationSettingsEntity, user_id):
7377
return result.to_model()
7478
else:
75-
return UserNotificationSettings(
76-
user_id=user_id, weekly_report=True, inactivity_reminder=True, tutorial=True
77-
)
79+
return UserNotificationSettings(user_id=user_id)
7880

7981
async def update_notification_settings(
8082
self,
@@ -83,6 +85,7 @@ async def update_notification_settings(
8385
weekly_report: Optional[bool] = None,
8486
inactivity_reminder: Optional[bool] = None,
8587
tutorial: Optional[bool] = None,
88+
marketing: Optional[bool] = None,
8689
) -> UserNotificationSettings:
8790
async with self.session_maker() as session:
8891
if isinstance(user_id_or_email, str):
@@ -108,6 +111,8 @@ async def update_notification_settings(
108111
value.inactivity_reminder = inactivity_reminder
109112
if tutorial is not None:
110113
value.tutorial = tutorial
114+
if marketing is not None:
115+
value.marketing = marketing
111116
settings = value.to_model()
112117
await session.commit()
113118
return settings
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
user_notification_settings: add marketing column
3+
"""
4+
5+
from typing import Union
6+
7+
import sqlalchemy as sa
8+
from alembic import op
9+
10+
revision: str = "2c3086217445"
11+
down_revision: Union[str, None] = "1e4ccaf4e087"
12+
13+
14+
def upgrade() -> None:
15+
op.add_column(
16+
"user_notification_settings",
17+
sa.Column(
18+
"marketing",
19+
sa.Boolean(),
20+
nullable=False,
21+
server_default="true",
22+
),
23+
)

0 commit comments

Comments
 (0)