File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed
Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -26,3 +26,17 @@ def validate_timestamp_start_date_before_end_date(startDate, endDate):
2626 raise HTTPException (
2727 status_code = 400 , detail = "endDate must be after startDate" )
2828 return endDate
29+
30+
31+ def validate_temperature_timestamp_in_range (start , end ):
32+ min_timestamp = - 946771200 # 01/01/1940
33+ max_timestamp = int (time .time ()) # now
34+ print (end )
35+ print (max_timestamp )
36+ if (start < min_timestamp or end > max_timestamp ):
37+ raise HTTPException (
38+ status_code = 400 , detail = f"Timestamp must be between { min_timestamp } and { max_timestamp } " )
39+ elif end <= start :
40+ raise HTTPException (
41+ status_code = 400 , detail = "endDate must be after startDate" )
42+ return end
Original file line number Diff line number Diff line change 44
55from src .constants import AggregationMethod , LocationName , TemporalResolution , Unit
66from src .validation .utils import (
7- validate_timestamp_in_range ,
7+ validate_temperature_timestamp_in_range ,
88 validate_timestamp_start_date_before_end_date ,
99)
1010
@@ -33,14 +33,9 @@ class WeatherDataRequest(BaseModel):
3333 )
3434 aggregation : AggregationMethod = Field (..., description = "Aggregation method" )
3535
36- # Custom validator to check if timestamps are valid and in the correct order
37- @field_validator ("startDate" )
38- def validate_timestamp_in_range (cls , v ):
39- return validate_timestamp_in_range (v )
40-
4136 @field_validator ("endDate" )
42- def end_date_must_be_after_start_date (cls , v , info : ValidationInfo ):
43- return validate_timestamp_start_date_before_end_date (
37+ def validate_temperature_timestamp_in_range (cls , v , info : ValidationInfo ):
38+ return validate_temperature_timestamp_in_range (
4439 info .data .get ("startDate" ), v
4540 )
4641
You can’t perform that action at this time.
0 commit comments