Coverage for src/kwai/modules/teams/delete_team.py: 100%

12 statements  

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

1"""Module that defines the use case "Delete Team".""" 

2 

3from dataclasses import dataclass 

4 

5from kwai.modules.teams.domain.team import TeamIdentifier 

6from kwai.modules.teams.repositories.team_repository import TeamRepository 

7 

8 

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

10class DeleteTeamCommand: 

11 """Input for the use case DeleteTeam.""" 

12 

13 id: int 

14 

15 

16class DeleteTeam: 

17 """Use case for deleting a team.""" 

18 

19 def __init__(self, repo: TeamRepository): 

20 """Initialize the use case. 

21 

22 Args: 

23 repo: A repository for deleting a team. 

24 """ 

25 self._repo = repo 

26 

27 async def execute(self, command: DeleteTeamCommand) -> None: 

28 """Execute the use case. 

29 

30 Args: 

31 command: The input for the use case. 

32 

33 Raises: 

34 TeamNotFoundException: If the team does not exist. 

35 """ 

36 team = await self._repo.get( 

37 self._repo.create_query().filter_by_id(TeamIdentifier(command.id)) 

38 ) 

39 # TODO: check if the team is not attached to one or more trainings... 

40 await self._repo.delete(team)