Coverage for src/kwai/modules/training/get_training_definitions.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module that defines the use case "Get Training Definitions"."""
3from dataclasses import dataclass
5from kwai.core.domain.use_case import UseCaseBrowseResult
6from kwai.modules.training.trainings.training_definition_repository import (
7 TrainingDefinitionRepository,
8)
11@dataclass(kw_only=True, frozen=True, slots=True)
12class GetTrainingDefinitionsCommand:
13 """Input for the use case "Get Training Definitions"."""
15 limit: int | None = None
16 offset: int | None = None
19class GetTrainingDefinitions:
20 """Use case "Get Training Definitions"."""
22 def __init__(self, repo: TrainingDefinitionRepository):
23 """Initialize the use case.
25 Args:
26 repo: A repository for retrieving training definitions.
27 """
28 self._repo = repo
30 async def execute(
31 self, command: GetTrainingDefinitionsCommand
32 ) -> UseCaseBrowseResult:
33 """Execute the use case."""
34 query = self._repo.create_query()
36 return UseCaseBrowseResult(
37 count=await query.count(),
38 iterator=self._repo.get_all(query, command.limit, command.offset),
39 )