Coverage for polar/customer_portal/repository/wallet.py: 96%
19 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
1from uuid import UUID
3from sqlalchemy import Select
4from sqlalchemy.orm import joinedload
6from polar.auth.models import AuthSubject
7from polar.kit.repository import (
8 Options,
9 RepositoryBase,
10 RepositorySoftDeletionIDMixin,
11 RepositorySoftDeletionMixin,
12 RepositorySortingMixin,
13 SortingClause,
14)
15from polar.models import Customer, Wallet
17from ..sorting.wallet import CustomerWalletSortProperty
20class CustomerWalletRepository(
21 RepositorySortingMixin[Wallet, CustomerWalletSortProperty],
22 RepositorySoftDeletionIDMixin[Wallet, UUID],
23 RepositorySoftDeletionMixin[Wallet],
24 RepositoryBase[Wallet],
25):
26 model = Wallet
28 def get_readable_statement(
29 self, auth_subject: AuthSubject[Customer]
30 ) -> Select[tuple[Wallet]]:
31 return self.get_base_statement().where(
32 Wallet.customer_id == auth_subject.subject.id
33 )
35 def get_eager_options(self) -> Options:
36 return (joinedload(Wallet.customer).joinedload(Customer.organization),)
38 def get_sorting_clause(self, property: CustomerWalletSortProperty) -> SortingClause:
39 match property:
40 case CustomerWalletSortProperty.created_at:
41 return Wallet.created_at
42 case CustomerWalletSortProperty.balance: 42 ↛ exitline 42 didn't return from function 'get_sorting_clause' because the pattern on line 42 always matched
43 return Wallet.balance