37 lines
1 KiB
Python
37 lines
1 KiB
Python
from __future__ import annotations
|
|
|
|
from pydantic import BaseModel, ConfigDict, field_validator
|
|
|
|
|
|
class HomepageConfigOut(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
hero_headline: str
|
|
hero_subheadline: str | None
|
|
hero_cta_label: str
|
|
hero_cta_url: str
|
|
featured_properties_limit: int
|
|
hero_image_url: str | None = None
|
|
|
|
|
|
class HomepageConfigIn(BaseModel):
|
|
hero_headline: str
|
|
hero_subheadline: str | None = None
|
|
hero_cta_label: str = "Ver Imóveis"
|
|
hero_cta_url: str = "/imoveis"
|
|
featured_properties_limit: int = 6
|
|
hero_image_url: str | None = None
|
|
|
|
@field_validator("hero_headline")
|
|
@classmethod
|
|
def headline_not_empty(cls, v: str) -> str:
|
|
if not v.strip():
|
|
raise ValueError("hero_headline não pode ser vazio")
|
|
return v
|
|
|
|
@field_validator("featured_properties_limit")
|
|
@classmethod
|
|
def limit_in_range(cls, v: int) -> int:
|
|
if not (1 <= v <= 12):
|
|
raise ValueError("featured_properties_limit deve estar entre 1 e 12")
|
|
return v
|