Coverage for app/backend/src/couchers/servicers/screens.py: 100%
14 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-10 18:39 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-10 18:39 +0000
1from google.protobuf import empty_pb2
2from sqlalchemy.orm import Session
4from couchers.context import CouchersContext
5from couchers.proto import (
6 discussions_pb2,
7 events_pb2,
8 messages_pb2,
9 requests_pb2,
10 screens_pb2,
11 screens_pb2_grpc,
12)
13from couchers.servicers.account import Account
14from couchers.servicers.discussions import Discussions
15from couchers.servicers.events import Events
16from couchers.servicers.requests import Requests
19class Screens(screens_pb2_grpc.ScreensServicer):
20 def GetDashboard(
21 self, request: screens_pb2.GetDashboardReq, context: CouchersContext, session: Session
22 ) -> screens_pb2.GetDashboardRes:
23 # the dashboard shows a small preview of each section
24 page_size = 3
26 def upcoming_host_requests_req(*, surfing: bool) -> requests_pb2.ListHostRequestsReq:
27 return requests_pb2.ListHostRequestsReq(
28 only_sent=surfing,
29 only_received=not surfing,
30 only_active=True,
31 status_in=[
32 messages_pb2.HOST_REQUEST_STATUS_ACCEPTED,
33 messages_pb2.HOST_REQUEST_STATUS_CONFIRMED,
34 ],
35 sort_by=requests_pb2.HOST_REQUEST_SORT_BY_FROM_DATE,
36 )
38 return screens_pb2.GetDashboardRes(
39 reminders=Account().GetReminders(empty_pb2.Empty(), context, session),
40 surfing=Requests().ListHostRequests(upcoming_host_requests_req(surfing=True), context, session),
41 hosting=Requests().ListHostRequests(upcoming_host_requests_req(surfing=False), context, session),
42 my_events=Events().ListMyEvents(
43 events_pb2.ListMyEventsReq(page_size=page_size),
44 context,
45 session,
46 ),
47 community_events=Events().ListMyEvents(
48 events_pb2.ListMyEventsReq(
49 page_size=page_size,
50 my_communities=True,
51 my_communities_exclude_global=True,
52 exclude_attending=True,
53 ),
54 context,
55 session,
56 ),
57 discussions=Discussions().ListMyCommunitiesDiscussions(
58 discussions_pb2.ListMyCommunitiesDiscussionsReq(page_size=page_size),
59 context,
60 session,
61 ),
62 )