Coverage for polar/customer_portal/repository/wallet.py: 52%

19 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 15:52 +0000

1from uuid import UUID 1a

2 

3from sqlalchemy import Select 1a

4from sqlalchemy.orm import joinedload 1a

5 

6from polar.auth.models import AuthSubject 1a

7from polar.kit.repository import ( 1a

8 Options, 

9 RepositoryBase, 

10 RepositorySoftDeletionIDMixin, 

11 RepositorySoftDeletionMixin, 

12 RepositorySortingMixin, 

13 SortingClause, 

14) 

15from polar.models import Customer, Wallet 1a

16 

17from ..sorting.wallet import CustomerWalletSortProperty 1a

18 

19 

20class CustomerWalletRepository( 1a

21 RepositorySortingMixin[Wallet, CustomerWalletSortProperty], 

22 RepositorySoftDeletionIDMixin[Wallet, UUID], 

23 RepositorySoftDeletionMixin[Wallet], 

24 RepositoryBase[Wallet], 

25): 

26 model = Wallet 1a

27 

28 def get_readable_statement( 1a

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 ) 

34 

35 def get_eager_options(self) -> Options: 1a

36 return (joinedload(Wallet.customer).joinedload(Customer.organization),) 

37 

38 def get_sorting_clause(self, property: CustomerWalletSortProperty) -> SortingClause: 1a

39 match property: 

40 case CustomerWalletSortProperty.created_at: 

41 return Wallet.created_at 

42 case CustomerWalletSortProperty.balance: 

43 return Wallet.balance