feat(chalice): handle wrong startTimestamp endTimestamp values
This commit is contained in:
parent
1e2b6d1178
commit
302119c3f5
3 changed files with 20 additions and 6 deletions
|
|
@ -92,7 +92,19 @@ class CreateNotificationSchema(BaseModel):
|
|||
notifications: List = Field(...)
|
||||
|
||||
|
||||
class NotificationsViewSchema(BaseModel):
|
||||
class _TimedSchema(BaseModel):
|
||||
startTimestamp: int = Field(default=None)
|
||||
endTimestamp: int = Field(default=None)
|
||||
|
||||
@root_validator
|
||||
def time_validator(cls, values):
|
||||
if values.get("startTimestamp") is not None and values.get("endTimestamp") is not None:
|
||||
assert values.get("startTimestamp") < values.get("endTimestamp"), \
|
||||
"endTimestamp must be greater than startTimestamp"
|
||||
return values
|
||||
|
||||
|
||||
class NotificationsViewSchema(_TimedSchema):
|
||||
ids: Optional[List] = Field(default=[])
|
||||
startTimestamp: Optional[int] = Field(default=None)
|
||||
endTimestamp: Optional[int] = Field(default=None)
|
||||
|
|
@ -816,7 +828,7 @@ class SearchErrorsSchema(FlatSessionsSearchPayloadSchema):
|
|||
query: Optional[str] = Field(default=None)
|
||||
|
||||
|
||||
class MetricPayloadSchema(BaseModel):
|
||||
class MetricPayloadSchema(_TimedSchema):
|
||||
startTimestamp: int = Field(TimeUTC.now(delta_days=-1))
|
||||
endTimestamp: int = Field(TimeUTC.now())
|
||||
density: int = Field(7)
|
||||
|
|
@ -967,7 +979,7 @@ class MetricOfClickMap(str, Enum):
|
|||
click_map_url = "clickMapUrl"
|
||||
|
||||
|
||||
class CardSessionsSchema(FlatSessionsSearch, _PaginatedSchema):
|
||||
class CardSessionsSchema(FlatSessionsSearch, _PaginatedSchema,_TimedSchema):
|
||||
startTimestamp: int = Field(TimeUTC.now(-7))
|
||||
endTimestamp: int = Field(TimeUTC.now())
|
||||
series: List[CardCreateSeriesSchema] = Field(default=[])
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import schemas, schemas_ee
|
||||
from typing import List, Optional
|
||||
from typing import Optional
|
||||
|
||||
import schemas
|
||||
import schemas_ee
|
||||
from chalicelib.core import metrics
|
||||
from chalicelib.utils import ch_client
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class InsightCategories(str, Enum):
|
|||
resources = "resources"
|
||||
|
||||
|
||||
class GetInsightsSchema(BaseModel):
|
||||
class GetInsightsSchema(schemas._TimedSchema):
|
||||
startTimestamp: int = Field(default=TimeUTC.now(-7))
|
||||
endTimestamp: int = Field(default=TimeUTC.now())
|
||||
metricValue: List[InsightCategories] = Field(default=[])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue