Skip to content

Commit

Permalink
Update validation function in the schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
essaaam committed Oct 27, 2024
1 parent 3873338 commit c99cbee
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/weather/schemas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, Field, validator
from pydantic import BaseModel, Field, field_validator, ValidationInfo, ValidationError
from typing import List
from src.constants import AggregationMethod, LocationName, TemporalResolution, Unit
from src.validation.utils import (
Expand All @@ -15,13 +15,13 @@ class TemperatureDataRequest(BaseModel):
aggregation: AggregationMethod = Field(..., description="Aggregation method")

# Custom validator to check if timestamps are valid and in the correct order
@validator("startDate", "endDate")
@field_validator("startDate")
def validate_timestamp_in_range(cls, v):
return validate_timestamp_in_range(v)

@validator("endDate")
def end_date_must_be_after_start_date(cls, v, values):
return validate_timestamp_startdate_before_enddate(values.get("startDate"), v)
@field_validator("endDate")
def end_date_must_be_after_start_date(cls, v, info: ValidationInfo):
return validate_timestamp_startdate_before_enddate(info.data.get("startDate"), v)

class TemperatureDataMeta(BaseModel):
startDate: int
Expand Down

0 comments on commit c99cbee

Please sign in to comment.