Skip to content

Commit

Permalink
feat: adding fieldName to time payload M2-8209 (#1659)
Browse files Browse the repository at this point in the history
* adding new field called fieldName to time payload

* chore/checking format with ruff

* removing fieldName from timePayload

---------

Co-authored-by: Felipe Imperio <[email protected]>
  • Loading branch information
felipeMetaLab and Felipe Imperio authored Nov 19, 2024
1 parent e7696d8 commit 544b42e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/apps/activities/domain/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class SliderConditionType(StrEnum):
OUTSIDE_OF = "OUTSIDE_OF"


class FieldNamePayloadType(StrEnum):
FROM = "from"
TO = "to"


class TimePayloadType(StrEnum):
START_TIME = "startTime"
END_TIME = "endTime"
Expand Down Expand Up @@ -136,6 +141,13 @@ def dict(self, *args, **kwargs):
class DateRangePayload(PublicModel):
minDate: datetime.date
maxDate: datetime.date
fieldName: FieldNamePayloadType | None = None

@validator("fieldName", pre=True, always=True)
def validate_field_name(cls, v):
if v is not None and v not in FieldNamePayloadType.__members__.values():
raise ValueError(f"{v} is not a valid FieldNamePayloadType value.")
return v

@root_validator(pre=True)
def validate_dates(cls, values):
Expand Down Expand Up @@ -166,6 +178,13 @@ class SingleTimePayload(PublicModel):
time: Optional[datetime.time] = None
max_value: Optional[datetime.time] = None
min_value: Optional[datetime.time] = None
fieldName: FieldNamePayloadType | None = None

@validator("fieldName", pre=True, always=True)
def validate_field_name(cls, v):
if v is not None and v not in FieldNamePayloadType.__members__.values():
raise ValueError(f"{v} is not a valid FieldNamePayloadType value.")
return v

@root_validator(pre=True)
def validate_time(cls, values: Dict[str, Any]) -> Dict[str, Any]:
Expand Down Expand Up @@ -227,6 +246,13 @@ def _time_to_dict(time: datetime.time) -> Dict[str, int]:
class MinMaxTimePayload(PublicModel):
minTime: Optional[datetime.time] = None
maxTime: Optional[datetime.time] = None
fieldName: FieldNamePayloadType | None = None

@validator("fieldName", pre=True, always=True)
def validate_field_name(cls, v):
if v is not None and v not in FieldNamePayloadType.__members__.values():
raise ValueError(f"{v} is not a valid FieldNamePayloadType value.")
return v

@root_validator(pre=True)
def validate_times(cls, values: Dict[str, Any]) -> Dict[str, Any]:
Expand Down

0 comments on commit 544b42e

Please sign in to comment.