31
31
@frozen
32
32
class UserNotificationSettings :
33
33
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
37
38
38
39
39
40
class UserNotificationSettingsEntity (CreatedUpdatedMixin , Base ):
@@ -43,13 +44,15 @@ class UserNotificationSettingsEntity(CreatedUpdatedMixin, Base):
43
44
weekly_report : Mapped [bool ] = mapped_column (Boolean , nullable = False , default = True )
44
45
inactivity_reminder : Mapped [bool ] = mapped_column (Boolean , nullable = False , default = True )
45
46
tutorial : Mapped [bool ] = mapped_column (Boolean , nullable = False , default = True )
47
+ marketing : Mapped [bool ] = mapped_column (Boolean , nullable = False , default = True )
46
48
47
49
def to_model (self ) -> UserNotificationSettings :
48
50
return UserNotificationSettings (
49
51
user_id = self .user_id ,
50
52
weekly_report = self .weekly_report ,
51
53
inactivity_reminder = self .inactivity_reminder ,
52
54
tutorial = self .tutorial ,
55
+ marketing = self .marketing ,
53
56
)
54
57
55
58
@staticmethod
@@ -59,6 +62,7 @@ def from_model(settings: UserNotificationSettings) -> "UserNotificationSettingsE
59
62
weekly_report = settings .weekly_report ,
60
63
inactivity_reminder = settings .inactivity_reminder ,
61
64
tutorial = settings .tutorial ,
65
+ marketing = settings .marketing ,
62
66
)
63
67
64
68
@@ -72,9 +76,7 @@ async def get_notification_settings(self, user_id: UserId) -> UserNotificationSe
72
76
if result := await session .get (UserNotificationSettingsEntity , user_id ):
73
77
return result .to_model ()
74
78
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 )
78
80
79
81
async def update_notification_settings (
80
82
self ,
@@ -83,6 +85,7 @@ async def update_notification_settings(
83
85
weekly_report : Optional [bool ] = None ,
84
86
inactivity_reminder : Optional [bool ] = None ,
85
87
tutorial : Optional [bool ] = None ,
88
+ marketing : Optional [bool ] = None ,
86
89
) -> UserNotificationSettings :
87
90
async with self .session_maker () as session :
88
91
if isinstance (user_id_or_email , str ):
@@ -108,6 +111,8 @@ async def update_notification_settings(
108
111
value .inactivity_reminder = inactivity_reminder
109
112
if tutorial is not None :
110
113
value .tutorial = tutorial
114
+ if marketing is not None :
115
+ value .marketing = marketing
111
116
settings = value .to_model ()
112
117
await session .commit ()
113
118
return settings
0 commit comments