Coverage for src/couchers/servicers/notifications.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

14 statements  

1from couchers.db import session_scope 

2from couchers.models import User 

3from couchers.sql import couchers_select as select 

4from proto import notifications_pb2, notifications_pb2_grpc 

5 

6 

7class Notifications(notifications_pb2_grpc.NotificationsServicer): 

8 def GetNotificationSettings(self, request, context): 

9 with session_scope() as session: 

10 user = session.execute(select(User).where(User.id == context.user_id)).scalar_one() 

11 return notifications_pb2.GetNotificationSettingsRes( 

12 new_notifications_enabled=user.new_notifications_enabled 

13 ) 

14 

15 def SetNotificationSettings(self, request, context): 

16 with session_scope() as session: 

17 user = session.execute(select(User).where(User.id == context.user_id)).scalar_one() 

18 user.new_notifications_enabled = request.enable_new_notifications 

19 return notifications_pb2.SetNotificationSettingsRes()