Skip to content

Commit

Permalink
feat: implement use case "Get Page"
Browse files Browse the repository at this point in the history
  • Loading branch information
fbraem committed Sep 21, 2023
1 parent 1a37751 commit 30713b9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions backend/src/kwai/modules/page/get_page.py
Original file line number Diff line number Diff line change
@@ -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))
12 changes: 12 additions & 0 deletions backend/src/tests/modules/page/test_get_page.py
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 30713b9

Please sign in to comment.