Coverage for apps/kwai-api/src/kwai_api/v1/presenters.py: 100%
9 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
1"""Module for defining presenters for common entities."""
3from typing import Self
5from kwai_bc_club.domain.country import CountryEntity
6from kwai_core.domain.presenter import Presenter
7from kwai_core.json_api import JsonApiPresenter
9from kwai_api.v1.schemas import CountryAttributes, CountryDocument, CountryResource
12class JsonApiCountryPresenter(
13 JsonApiPresenter[CountryDocument], Presenter[CountryEntity]
14):
15 """A presenter that transforms a country entity into a JSON:API document."""
17 def present(self, country: CountryEntity) -> Self:
18 self._document = CountryDocument(
19 data=CountryResource(
20 id=str(country.id),
21 attributes=CountryAttributes(
22 iso_2=country.iso_2, iso_3=country.iso_3, name=country.name
23 ),
24 )
25 )
26 return self