make editor geometries schema a bit more generic

This commit is contained in:
Laura Klünder 2023-12-03 18:11:53 +01:00
parent 12220823c3
commit 02e3fd60e6
2 changed files with 9 additions and 28 deletions

View file

@ -53,7 +53,7 @@ def geometrystyles(request):
@editor_api_router.get('/geometries/space/{space_id}/', summary="get the geometries to display for a space",
response={200: list[EditorSpaceGeometriesElemSchema], **API404.dict(),
response={200: list[EditorGeometriesElemSchema], **API404.dict(),
**auth_permission_responses},
openapi_extra={"security": [{"APITokenAuth": ["editor_access"]}]})
@newapi_etag_with_update_cache_key(etag_func=editor_etag_func)
@ -75,7 +75,7 @@ def space_geometries(request, space_id: EditorID, update_cache_key: UpdateCacheK
@editor_api_router.get('/geometries/level/{level_id}/', summary="get the geometries to display for a level",
response={200: list[EditorLevelGeometriesElemSchema], **API404.dict(),
response={200: list[EditorGeometriesElemSchema], **API404.dict(),
**auth_permission_responses},
openapi_extra={"security": [{"APITokenAuth": ["editor_access"]}]})
@newapi_etag_with_update_cache_key(etag_func=editor_etag_func)

View file

@ -40,9 +40,11 @@ EditorGeometriesCacheReferenceElem = Annotated[
]
class BaseEditorGeometriesPropertiesSchema(Schema):
class EditorGeometriesPropertiesSchema(Schema):
id: EditorID
type: NonEmptyStr
space: Optional[EditorID] = None
level: Optional[EditorID] = None
bounds: bool = False
color: Optional[str] = None
opacity: Optional[float] = None # todo: range
@ -55,46 +57,25 @@ class EditorGeometriesGraphEdgePropertiesSchema(Schema):
to_node: EditorID
class EditorSpaceGeometriesPropertiesSchema(BaseEditorGeometriesPropertiesSchema):
space: EditorID
class EditorLevelGeometriesPropertiesSchema(BaseEditorGeometriesPropertiesSchema):
level: EditorID
class EditorGeometriesGraphEdgeElemSchema(Schema):
type: Literal["Feature"]
properties: EditorGeometriesGraphEdgePropertiesSchema
geometry: LineSchema
class BaseEditorGeometriesGeometryElemSchema(Schema):
class EditorGeometriesGeometryElemSchema(Schema):
type: Literal["Feature"]
geometry: AnyGeometrySchema = APIField(description="geometry, potentially modified for displaying")
original_geometry: Optional[GeometrySchema] = APIField(
default=None,
description="original unchanged geometry, not modified, original(??)", # todo: more precise
)
properties: EditorGeometriesPropertiesSchema
class EditorSpaceGeometriesGeometryElemSchema(BaseEditorGeometriesGeometryElemSchema):
properties: EditorSpaceGeometriesPropertiesSchema
class EditorLevelGeometriesGeometryElemSchema(BaseEditorGeometriesGeometryElemSchema):
properties: EditorLevelGeometriesPropertiesSchema
EditorSpaceGeometriesElemSchema = Union[
EditorGeometriesElemSchema = Union[
EditorGeometriesUpdateCacheKeyElem,
Annotated[EditorSpaceGeometriesGeometryElemSchema, APIField(title="a geometry object")],
Annotated[EditorGeometriesGraphEdgeElemSchema, APIField(title="a graph edge")],
EditorGeometriesCacheReferenceElem,
]
EditorLevelGeometriesElemSchema = Union[
EditorGeometriesUpdateCacheKeyElem,
Annotated[EditorLevelGeometriesGeometryElemSchema, APIField(title="a geometry object")],
Annotated[EditorGeometriesGeometryElemSchema, APIField(title="a geometry object")],
Annotated[EditorGeometriesGraphEdgeElemSchema, APIField(title="a graph edge")],
EditorGeometriesCacheReferenceElem,
]