From b08950ba96f7894a394468be4269f51cd0b6d6bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sabine=20Schr=C3=B6der?= <s.schroeder@fz-juelich.de>
Date: Wed, 18 Nov 2020 12:13:29 +0100
Subject: [PATCH] #17: after re-adding coordinate_validation_status to table
 stationmeta_core, it has also to be readded to the model/schema/docu

---
 docs/toardb_fastapi.md            |  4 ++++
 toardb/stationmeta/models_core.py |  2 ++
 toardb/stationmeta/schemas.py     | 18 ++++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/docs/toardb_fastapi.md b/docs/toardb_fastapi.md
index 9d2e0bf..2f58fb1 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 92262f5..e4099fc 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 193053e..9b818f0 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)):
-- 
GitLab