Skip to content

Commit

Permalink
refactor: rename ContentRow into TextRow
Browse files Browse the repository at this point in the history
  • Loading branch information
fbraem committed Sep 22, 2023
1 parent 9b55e25 commit 3aed78d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 32 deletions.
14 changes: 7 additions & 7 deletions backend/src/kwai/core/db/rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def create_owner(self) -> Owner:


@dataclass(kw_only=True, frozen=True, slots=True)
class ContentRow:
class TextRow:
"""Represent a row for a content table.
Attributes:
locale: The code of the locale of the text
format: The format of the text (md = markdown, html, ...)
title: The title of the news items
content: The long content of the news item
summary: A summary of the content
title: The title of the text
content: The long content of the text
summary: A summary of the text
user_id: The id of the author
created_at: the timestamp of creation
updated_at: the timestamp of the last modification
Expand All @@ -57,11 +57,11 @@ class ContentRow:
created_at: datetime
updated_at: datetime | None

def create_content(self, author: Owner) -> LocaleText:
"""Create a Content value object from a row.
def create_text(self, author: Owner) -> LocaleText:
"""Create a LocaleText value object from a row.
Args:
author: The author of the content.
author: The author of the text.
"""
return LocaleText(
locale=Locale(self.locale),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def _create_entity(rows: list[dict[str, Any]]) -> NewsItemEntity:
return NewsItemsTable(rows[0]).create_entity(
ApplicationsTable(rows[0]).create_entity(),
[
NewsItemTextsTable(row).create_content(
author=OwnersTable(row).create_owner()
)
NewsItemTextsTable(row).create_text(author=OwnersTable(row).create_owner())
for row in rows
],
)
Expand Down
4 changes: 2 additions & 2 deletions backend/src/kwai/modules/portal/news/news_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass
from datetime import datetime

from kwai.core.db.rows import ContentRow
from kwai.core.db.rows import TextRow
from kwai.core.db.table import Table
from kwai.core.domain.value_objects.local_timestamp import LocalTimestamp
from kwai.core.domain.value_objects.period import Period
Expand All @@ -17,7 +17,7 @@


@dataclass(kw_only=True, frozen=True, slots=True)
class NewsItemTextRow(ContentRow):
class NewsItemTextRow(TextRow):
"""Represent a row in the news_contents table.
Attributes:
Expand Down
12 changes: 4 additions & 8 deletions backend/src/kwai/modules/portal/pages/page_db_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
PageRepository,
)
from kwai.modules.portal.pages.page_tables import (
PageContentRow,
PageContentsTable,
PageRow,
PagesTable,
PageTextRow,
)


Expand All @@ -28,9 +28,7 @@ def _create_entity(rows: list[dict[str, Any]]) -> PageEntity:
return PagesTable(rows[0]).create_entity(
ApplicationsTable(rows[0]).create_entity(),
[
PageContentsTable(row).create_content(
author=OwnersTable(row).create_owner()
)
PageContentsTable(row).create_text(author=OwnersTable(row).create_owner())
for row in rows
],
)
Expand All @@ -48,9 +46,7 @@ async def create(self, page: PageEntity) -> PageEntity:
)
result = Entity.replace(page, id_=PageIdentifier(new_id))

content_rows = [
PageContentRow.persist(result, content) for content in page.texts
]
content_rows = [PageTextRow.persist(result, content) for content in page.texts]
await self._database.insert(PageContentsTable.table_name, *content_rows)

await self._database.commit()
Expand All @@ -68,7 +64,7 @@ async def update(self, page: PageEntity):
)
await self._database.execute(delete_contents_query)

content_rows = [PageContentRow.persist(page, content) for content in page.texts]
content_rows = [PageTextRow.persist(page, content) for content in page.texts]
await self._database.insert(PageContentsTable.table_name, *content_rows)
await self._database.commit()

Expand Down
8 changes: 4 additions & 4 deletions backend/src/kwai/modules/portal/pages/page_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass
from datetime import datetime

from kwai.core.db.rows import ContentRow
from kwai.core.db.rows import TextRow
from kwai.core.db.table import Table
from kwai.core.domain.value_objects.local_timestamp import LocalTimestamp
from kwai.core.domain.value_objects.text import LocaleText
Expand All @@ -12,7 +12,7 @@


@dataclass(kw_only=True, frozen=True, slots=True)
class PageContentRow(ContentRow):
class PageTextRow(TextRow):
"""Represent a row in the page_contents table.
Attributes:
Expand All @@ -29,7 +29,7 @@ def persist(cls, page: PageEntity, content: LocaleText):
page: The page that contains the content.
content: The content of a page.
"""
return PageContentRow(
return PageTextRow(
page_id=page.id.value,
locale=content.locale.value,
format=content.format.value,
Expand All @@ -42,7 +42,7 @@ def persist(cls, page: PageEntity, content: LocaleText):
)


PageContentsTable = Table("page_contents", PageContentRow)
PageContentsTable = Table("page_contents", PageTextRow)


@dataclass(kw_only=True, frozen=True, slots=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
from kwai.modules.training.trainings.training_tables import (
TrainingCoachesTable,
TrainingCoachRow,
TrainingContentRow,
TrainingContentsTable,
TrainingDefinitionsTable,
TrainingRow,
TrainingsTable,
TrainingTeamRow,
TrainingTeamsTable,
TrainingTextRow,
)
from kwai.modules.training.trainings.training_team_db_query import TrainingTeamDbQuery
from kwai.modules.training.trainings.value_objects import TrainingCoach
Expand All @@ -41,7 +41,7 @@ def _create_entity(rows: list[Record]) -> TrainingEntity:
)
return TrainingsTable(rows[0]).create_entity(
[
TrainingContentsTable(row).create_content(OwnersTable(row).create_owner())
TrainingContentsTable(row).create_text(OwnersTable(row).create_owner())
for row in rows
],
definition=definition,
Expand Down Expand Up @@ -144,7 +144,7 @@ async def create(self, training: TrainingEntity) -> TrainingEntity:
result = Entity.replace(training, id_=TrainingIdentifier(new_id))

content_rows = [
TrainingContentRow.persist(result, content) for content in training.texts
TrainingTextRow.persist(result, content) for content in training.texts
]

await self._database.insert(TrainingContentsTable.table_name, *content_rows)
Expand All @@ -166,7 +166,7 @@ async def update(self, training: TrainingEntity) -> None:
# Update the text, first delete, then insert again.
await self._delete_contents(training)
content_rows = [
TrainingContentRow.persist(training, content) for content in training.texts
TrainingTextRow.persist(training, content) for content in training.texts
]
await self._database.insert(TrainingContentsTable.table_name, *content_rows)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from datetime import datetime, time

from kwai.core.db.rows import ContentRow
from kwai.core.db.rows import TextRow
from kwai.core.db.table import Table
from kwai.core.domain.value_objects.local_timestamp import LocalTimestamp
from kwai.core.domain.value_objects.owner import Owner
Expand All @@ -26,7 +26,7 @@


@dataclass(kw_only=True, frozen=True, slots=True)
class TrainingContentRow(ContentRow):
class TrainingTextRow(TextRow):
"""Represent a row in the training_contents table.
Attributes:
Expand All @@ -43,7 +43,7 @@ def persist(cls, training: TrainingEntity, content: LocaleText):
training: The training that contains the text content.
content: The text content of the training.
"""
return TrainingContentRow(
return TrainingTextRow(
training_id=training.id.value,
locale=content.locale.value,
format=content.format.value,
Expand All @@ -56,7 +56,7 @@ def persist(cls, training: TrainingEntity, content: LocaleText):
)


TrainingContentsTable = Table("training_contents", TrainingContentRow)
TrainingContentsTable = Table("training_contents", TrainingTextRow)


@dataclass(kw_only=True, frozen=True, slots=True)
Expand Down

0 comments on commit 3aed78d

Please sign in to comment.