diff --git a/docs/toardb_fastapi.md b/docs/toardb_fastapi.md index 9d2e0bfa26e534c8ed87c78ad33d483addcd9f85..2f58fb1bf3b7914b58c1ad2c49ac61002421aa51 100644 --- a/docs/toardb_fastapi.md +++ b/docs/toardb_fastapi.md @@ -79,6 +79,7 @@ | codes | [ string ] | list of station's codes | Yes | | name | string | | Yes | | coordinates | [Coordinates](#coordinates) | | Yes | +| coordinate_validation_status | string | | Yes | | country | string | | Yes | | state | string | | Yes | | type_of_environment | string | | Yes | @@ -195,6 +196,7 @@ | codes | [ string ] | list of station's codes | Yes | | name | string | | Yes | | coordinates | [Coordinates](#coordinates) | | Yes | +| coordinate_validation_status | string | | Yes | | country | string | | Yes | | state | string | | Yes | | type_of_environment | string | | Yes | @@ -210,6 +212,7 @@ | codes | [ string ] | list of station's codes | Yes | | name | string | | Yes | | coordinates | [Coordinates](#coordinates) | | Yes | +| coordinate_validation_status | string | | Yes | | country | string | | Yes | | state | string | | Yes | | type_of_environment | string | | Yes | @@ -269,6 +272,7 @@ | codes | [ string ] | | No | | name | string | | No | | coordinates | [Coordinates](#coordinates) | | No | +| coordinate_validation_status | string | | No | | country | string | | No | | state | string | | No | | type_of_environment | string | | No | diff --git a/toardb/stationmeta/models_core.py b/toardb/stationmeta/models_core.py index 92262f5af3f41bd8caca2ff645c18cbe77eab832..e4099fc74370b831c6d5eb1e21ff88818655751d 100644 --- a/toardb/stationmeta/models_core.py +++ b/toardb/stationmeta/models_core.py @@ -31,6 +31,8 @@ class StationmetaCore_WithoutCoords(Base): +------------------------------+--------------------------+-----------+----------+----------------------------------------------+ | coordinates | geometry(PointZ,4326) | | not null | | +------------------------------+--------------------------+-----------+----------+----------------------------------------------+ + | coordinate_validation_status | integer | | not null | 0 | + +------------------------------+--------------------------+-----------+----------+----------------------------------------------+ | country | character varying(128) | | not null | | +------------------------------+--------------------------+-----------+----------+----------------------------------------------+ | state | character varying(128) | | not null | | diff --git a/toardb/stationmeta/schemas.py b/toardb/stationmeta/schemas.py index 193053e43ede39e0415f6dc1e69bfb2024d3dbb2..9b818f0afe48ca92c4132d0fd9e35b6b88914427 100644 --- a/toardb/stationmeta/schemas.py +++ b/toardb/stationmeta/schemas.py @@ -29,6 +29,7 @@ class StationmetaCoreBase(BaseModel): codes: List[str] = Field(..., description="list of station's codes") name: str coordinates: Coordinates + coordinate_validation_status: str country: str state: str type_of_environment: str @@ -39,6 +40,10 @@ class StationmetaCoreBase(BaseModel): class Config(BaseConfig): orm_mode = True + @validator('coordinate_validation_status') + def check_coordinate_validation_status(cls, v): + return tuple(filter(lambda x: x.value == int(v), CV_enum))[0].string + @validator('type_of_environment') def check_type_of_environment(cls, v): return tuple(filter(lambda x: x.value == int(v), ST_enum))[0].string @@ -52,6 +57,7 @@ class StationmetaCorePatch(BaseModel): codes: List[str] = None name: str = None coordinates: Coordinates = None + coordinate_validation_status: str = None country: str = None state: str = None type_of_environment: str = None @@ -62,6 +68,11 @@ class StationmetaCorePatch(BaseModel): class Config(BaseConfig): orm_mode = True + @validator('coordinate_validation_status') + def check_coordinate_validation_status(cls, v): + if v: + return tuple(filter(lambda x: x.value == int(v), CV_enum))[0].string + @validator('type_of_environment') def check_type_of_environment(cls, v): if v: @@ -76,6 +87,13 @@ class StationmetaCorePatch(BaseModel): class StationmetaCoreCreate(StationmetaCoreBase): pass + @validator('coordinate_validation_status') + def check_coordinate_validation_status(cls, v): + if tuple(filter(lambda x: x.string == v, CV_enum)): + return v + else: + raise ValueError(f"coordinate validation status not known: {v}") + @validator('type_of_environment') def check_type_of_environment(cls, v): if tuple(filter(lambda x: x.string == v, ST_enum)):