diff --git a/backend/src/kwai/modules/page/get_page.py b/backend/src/kwai/modules/page/get_page.py new file mode 100644 index 000000000..8257d8735 --- /dev/null +++ b/backend/src/kwai/modules/page/get_page.py @@ -0,0 +1,28 @@ +"""Module for the use case "Get Page".""" +from dataclasses import dataclass + +from kwai.modules.page.pages.page import PageEntity, PageIdentifier +from kwai.modules.page.pages.page_repository import PageRepository + + +@dataclass(kw_only=True, frozen=True, slots=True) +class GetPageCommand: + """Input for the use case "Get Page".""" + + id: int + + +class GetPage: + """Use case "Get Page".""" + + def __init__(self, repo: PageRepository): + """Initialize the use case. + + Args: + repo: A repository to get the page. + """ + self._repo = repo + + async def execute(self, command: GetPageCommand) -> PageEntity: + """Execute the use case.""" + return await self._repo.get_by_id(PageIdentifier(command.id)) diff --git a/backend/src/tests/modules/page/test_get_page.py b/backend/src/tests/modules/page/test_get_page.py new file mode 100644 index 000000000..c5a119068 --- /dev/null +++ b/backend/src/tests/modules/page/test_get_page.py @@ -0,0 +1,12 @@ +"""Module for testing the use case "Get Page".""" +from kwai.modules.page.get_page import GetPage, GetPageCommand +from kwai.modules.page.pages.page import PageEntity +from kwai.modules.page.pages.page_repository import PageRepository + + +async def test_get_page(repo: PageRepository, saved_page: PageEntity): + """Test the "Get Page" use case.""" + command = GetPageCommand(id=saved_page.id.value) + page = await GetPage(repo).execute(command) + assert page is not None, "There should be a page." + assert page.id == saved_page.id, "The id of the pages should be the same."