Coverage for bc/kwai-bc-portal/src/kwai_bc_portal/get_application.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module that defines the use case: get application for a portal.""" 

2 

3from dataclasses import dataclass 

4 

5from kwai_core.domain.presenter import Presenter 

6from kwai_core.domain.value_objects.identifier import IntIdentifier 

7 

8from kwai_bc_portal.applications.application_repository import ( 

9 ApplicationRepository, 

10) 

11from kwai_bc_portal.domain.application import ApplicationEntity 

12 

13 

14@dataclass(kw_only=True, frozen=True, slots=True) 

15class GetApplicationCommand: 

16 """Input for the use case [GetApplication][kwai_bc_portal.get_application.GetApplication]. 

17 

18 Attributes: 

19 id: The id of the application 

20 """ 

21 

22 id: int 

23 

24 

25class GetApplication: 

26 """Implements the use case 'get application'.""" 

27 

28 def __init__( 

29 self, 

30 application_repo: ApplicationRepository, 

31 presenter: Presenter[ApplicationEntity], 

32 ): 

33 """Initialize the use case. 

34 

35 Args: 

36 application_repo: A repository for getting applications. 

37 presenter: A presenter for an application. 

38 """ 

39 self._application_repo = application_repo 

40 self._presenter = presenter 

41 

42 async def execute(self, command: GetApplicationCommand): 

43 """Execute the use case. 

44 

45 Args: 

46 command: The input for this use case. 

47 """ 

48 self._presenter.present( 

49 await self._application_repo.get_by_id(IntIdentifier(command.id)) 

50 )