Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/smartphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Smartphone(SQLModel, table=True):
msrp_usd: int | None = None

# Memory
ram_gb: int
ram_gb: float # sub-GB on 2006-2012 phones (original iPhone 0.125)
storage_options_gb: list[int] = Field(default_factory=list, sa_column=Column(JSON))
variant: dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON))

Expand Down
7 changes: 6 additions & 1 deletion app/schemas/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
PREFIX = settings.api_version_prefix


def _whole_as_int(value: float) -> int | float:
"""8.0 → 8 so whole-GB phones keep their integer JSON; 0.125 stays a float."""
return int(value) if float(value).is_integer() else value


def url_for(resource: str, slug: str) -> str:
"""Build a versioned resource URL, e.g. ``/v1/smartphones/galaxy-s25``."""
return f"{PREFIX}/{resource}/{slug}"
Expand Down Expand Up @@ -250,7 +255,7 @@ def smartphone_read(
soc=soc_summary(soc, soc_manufacturer),
release_date=phone.release_date,
msrp_usd=phone.msrp_usd,
ram_gb=phone.ram_gb,
ram_gb=_whole_as_int(phone.ram_gb),
storage_options_gb=phone.storage_options_gb,
variant=phone.variant,
display=phone.display,
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/smartphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SmartphoneRead(BaseModel):
soc: SoCSummary
release_date: date
msrp_usd: int | None = None
ram_gb: int
ram_gb: int | float
storage_options_gb: list[int]
variant: dict[str, Any]
display: dict[str, Any]
Expand Down
Loading