add dynamiclocation to API
This commit is contained in:
parent
ecca514118
commit
93883355b0
2 changed files with 55 additions and 5 deletions
|
@ -13,13 +13,14 @@ from c3nav.mapdata.models import (Area, Building, Door, Hole, Level, LocationGro
|
|||
from c3nav.mapdata.models.access import AccessPermission, AccessRestriction, AccessRestrictionGroup
|
||||
from c3nav.mapdata.models.geometry.space import (POI, Column, CrossDescription, LeaveDescription, LineObstacle,
|
||||
Obstacle, Ramp)
|
||||
from c3nav.mapdata.models.locations import DynamicLocation
|
||||
from c3nav.mapdata.schemas.filters import (ByCategoryFilter, ByGroupFilter, ByOnTopOfFilter, FilterSchema,
|
||||
LevelGeometryFilter, SpaceGeometryFilter)
|
||||
from c3nav.mapdata.schemas.models import (AccessRestrictionGroupSchema, AccessRestrictionSchema, AreaSchema,
|
||||
BuildingSchema, ColumnSchema, CrossDescriptionSchema, DoorSchema, HoleSchema,
|
||||
LeaveDescriptionSchema, LevelSchema, LineObstacleSchema,
|
||||
LocationGroupCategorySchema, LocationGroupSchema, ObstacleSchema, POISchema,
|
||||
RampSchema, SourceSchema, SpaceSchema, StairSchema)
|
||||
BuildingSchema, ColumnSchema, CrossDescriptionSchema, DoorSchema,
|
||||
DynamicLocationSchema, HoleSchema, LeaveDescriptionSchema, LevelSchema,
|
||||
LineObstacleSchema, LocationGroupCategorySchema, LocationGroupSchema,
|
||||
ObstacleSchema, POISchema, RampSchema, SourceSchema, SpaceSchema, StairSchema)
|
||||
|
||||
mapdata_api_router = APIRouter(tags=["mapdata"])
|
||||
|
||||
|
@ -500,3 +501,25 @@ def accessrestrictiongroup_list(request):
|
|||
def accessrestrictiongroups_retrieve(request, group_id: int):
|
||||
# todo: access, caching, filtering, etc
|
||||
return mapdata_retrieve_endpoint(request, AccessRestrictionGroup, pk=group_id)
|
||||
|
||||
|
||||
"""
|
||||
DynamicLocations
|
||||
"""
|
||||
|
||||
|
||||
@mapdata_api_router.get('/dynamiclocations/',
|
||||
response={200: list[DynamicLocationSchema], **auth_responses},
|
||||
summary="Get dynamic location list")
|
||||
@paginate
|
||||
def dynamiclocation_list(request):
|
||||
# todo cache?
|
||||
return mapdata_list_endpoint(request, model=DynamicLocation)
|
||||
|
||||
|
||||
@mapdata_api_router.get('/dynamiclocations/{dynamiclocation_id}/',
|
||||
response={200: DynamicLocationSchema, **API404.dict(), **auth_responses},
|
||||
summary="Get dynamic location by ID")
|
||||
def dynamiclocation_retrieve(request, dynamiclocation_id: int):
|
||||
# todo: access, caching, filtering, etc
|
||||
return mapdata_retrieve_endpoint(request, DynamicLocation, pk=dynamiclocation_id)
|
||||
|
|
|
@ -285,6 +285,16 @@ class LocationGroupCategorySchema(TitledSchema, DjangoModelSchema):
|
|||
priority: int = APIField() # todo: ???
|
||||
|
||||
|
||||
class DynamicLocationSchema(SpecificLocationSchema, DjangoModelSchema):
|
||||
"""
|
||||
A dynamic location represents a moving object. Its position has to be separately queries through the position API.
|
||||
|
||||
A dynamic location is a specific location, and can therefore be routed to and from,
|
||||
as well as belong to location groups.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class SourceSchema(WithAccessRestrictionSchema, DjangoModelSchema):
|
||||
"""
|
||||
A source image that can be traced in the editor.
|
||||
|
@ -358,6 +368,14 @@ class FullLocationGroupLocationSchema(SimpleGeometryLocationsSchema, LocationGro
|
|||
locationtype: Literal["locationgroup"]
|
||||
|
||||
|
||||
class FullDynamicLocationLocationSchema(SimpleGeometryLocationsSchema, DynamicLocationSchema):
|
||||
"""
|
||||
A dynamic location for the location API.
|
||||
See DynamicLocation schema for details.
|
||||
"""
|
||||
locationtype: Literal["dynamiclocation"]
|
||||
|
||||
|
||||
class SlimLocationMixin(Schema):
|
||||
level: ClassVar[None]
|
||||
space: ClassVar[None]
|
||||
|
@ -407,7 +425,7 @@ class SlimPOILocationSchema(SlimLocationMixin, FullPOILocationSchema):
|
|||
|
||||
class SlimLocationGroupLocationSchema(SlimLocationMixin, FullLocationGroupLocationSchema):
|
||||
"""
|
||||
A locagroun group with some rarely needed fields removed and some additional information for the location API.
|
||||
A location group with some rarely needed fields removed and some additional information for the location API.
|
||||
See LocationGroup schema for details.
|
||||
"""
|
||||
category: ClassVar[None]
|
||||
|
@ -417,6 +435,13 @@ class SlimLocationGroupLocationSchema(SlimLocationMixin, FullLocationGroupLocati
|
|||
can_report_missing: ClassVar[None]
|
||||
|
||||
|
||||
class SlimDynamicLocationLocationSchema(SlimLocationMixin, FullDynamicLocationLocationSchema):
|
||||
"""
|
||||
A dynamic location with some rarely needed fields removed for the location API.
|
||||
See DynamicLocation schema for details.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
FullLocationSchema = Annotated[
|
||||
Union[
|
||||
|
@ -425,6 +450,7 @@ FullLocationSchema = Annotated[
|
|||
FullAreaLocationSchema,
|
||||
FullPOILocationSchema,
|
||||
FullLocationGroupLocationSchema,
|
||||
FullDynamicLocationLocationSchema,
|
||||
],
|
||||
Discriminator("locationtype"),
|
||||
]
|
||||
|
@ -436,6 +462,7 @@ SlimLocationSchema = Annotated[
|
|||
SlimAreaLocationSchema,
|
||||
SlimPOILocationSchema,
|
||||
SlimLocationGroupLocationSchema,
|
||||
SlimDynamicLocationLocationSchema,
|
||||
],
|
||||
Discriminator("locationtype"),
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue