refactor: cleanup duplicate code (#36173)

This commit is contained in:
chariri
2026-05-14 19:34:31 +09:00
committed by GitHub
parent 1a4288c811
commit a35b28dbef
33 changed files with 163 additions and 314 deletions

View File

@@ -7,6 +7,7 @@ from pydantic import computed_field, field_validator
from fields.base import ResponseModel
from graphon.file import helpers as file_helpers
from libs.helper import to_timestamp
simple_account_fields = {
"id": fields.String,
@@ -15,12 +16,6 @@ simple_account_fields = {
}
def _to_timestamp(value: datetime | int | None) -> int | None:
if isinstance(value, datetime):
return int(value.timestamp())
return value
def _build_avatar_url(avatar: str | None) -> str | None:
if avatar is None:
return None
@@ -59,7 +54,7 @@ class Account(_AccountAvatar):
@field_validator("last_login_at", "created_at", mode="before")
@classmethod
def _normalize_timestamp(cls, value: datetime | int | None) -> int | None:
return _to_timestamp(value)
return to_timestamp(value)
class AccountWithRole(_AccountAvatar):
@@ -75,7 +70,7 @@ class AccountWithRole(_AccountAvatar):
@field_validator("last_login_at", "last_active_at", "created_at", mode="before")
@classmethod
def _normalize_timestamp(cls, value: datetime | int | None) -> int | None:
return _to_timestamp(value)
return to_timestamp(value)
class AccountWithRoleList(ResponseModel):