add more mapdata endpoints, completing the mapdata API tag
This commit is contained in:
parent
846101ea37
commit
141ab7489e
3 changed files with 76 additions and 16 deletions
|
@ -9,13 +9,14 @@ from c3nav.api.exceptions import API404
|
||||||
from c3nav.mapdata.api import optimize_query
|
from c3nav.mapdata.api import optimize_query
|
||||||
from c3nav.mapdata.models import (Area, Building, Door, Hole, Level, LocationGroup, LocationGroupCategory, Source,
|
from c3nav.mapdata.models import (Area, Building, Door, Hole, Level, LocationGroup, LocationGroupCategory, Source,
|
||||||
Space, Stair)
|
Space, Stair)
|
||||||
from c3nav.mapdata.models.access import AccessPermission
|
from c3nav.mapdata.models.access import AccessPermission, AccessRestriction, AccessRestrictionGroup
|
||||||
from c3nav.mapdata.models.geometry.space import (POI, Column, CrossDescription, LeaveDescription, LineObstacle,
|
from c3nav.mapdata.models.geometry.space import (POI, Column, CrossDescription, LeaveDescription, LineObstacle,
|
||||||
Obstacle, Ramp)
|
Obstacle, Ramp)
|
||||||
from c3nav.mapdata.schemas.filters import (ByCategoryFilter, ByGroupFilter, ByLevelFilter, ByOnTopOfFilter,
|
from c3nav.mapdata.schemas.filters import (ByCategoryFilter, ByGroupFilter, ByLevelFilter, ByOnTopOfFilter,
|
||||||
BySpaceFilter, FilterSchema)
|
BySpaceFilter, FilterSchema)
|
||||||
from c3nav.mapdata.schemas.models import (AreaSchema, BuildingSchema, ColumnSchema, CrossDescriptionSchema, DoorSchema,
|
from c3nav.mapdata.schemas.models import (AccessRestrictionGroupSchema, AccessRestrictionSchema, AreaSchema,
|
||||||
HoleSchema, LeaveDescriptionSchema, LevelSchema, LineObstacleSchema,
|
BuildingSchema, ColumnSchema, CrossDescriptionSchema, DoorSchema, HoleSchema,
|
||||||
|
LeaveDescriptionSchema, LevelSchema, LineObstacleSchema,
|
||||||
LocationGroupCategorySchema, LocationGroupSchema, ObstacleSchema, POISchema,
|
LocationGroupCategorySchema, LocationGroupSchema, ObstacleSchema, POISchema,
|
||||||
RampSchema, SourceSchema, SpaceSchema, StairSchema)
|
RampSchema, SourceSchema, SpaceSchema, StairSchema)
|
||||||
|
|
||||||
|
@ -420,3 +421,43 @@ def source_list(request):
|
||||||
def source_detail(request, source_id: int):
|
def source_detail(request, source_id: int):
|
||||||
# todo: access, caching, filtering, etc
|
# todo: access, caching, filtering, etc
|
||||||
return mapdata_retrieve_endpoint(request, Source, pk=source_id)
|
return mapdata_retrieve_endpoint(request, Source, pk=source_id)
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
AccessRestrictions
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@mapdata_api_router.get('/accessrestrictions/', response=list[AccessRestrictionSchema],
|
||||||
|
summary="Get access restriction list")
|
||||||
|
@paginate
|
||||||
|
def accessrestriction_list(request):
|
||||||
|
# todo cache?
|
||||||
|
return mapdata_list_endpoint(request, model=AccessRestriction)
|
||||||
|
|
||||||
|
|
||||||
|
@mapdata_api_router.get('/accessrestrictions/{accessrestriction_id}/', response=AccessRestrictionSchema,
|
||||||
|
summary="Get access restriction by ID")
|
||||||
|
def accessrestriction_detail(request, accessrestriction_id: int):
|
||||||
|
# todo: access, caching, filtering, etc
|
||||||
|
return mapdata_retrieve_endpoint(request, AccessRestriction, pk=accessrestriction_id)
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
AccessRestrictionGroups
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@mapdata_api_router.get('/accessrestrictiongroups/', response=list[AccessRestrictionGroupSchema],
|
||||||
|
summary="Get access restriction group list")
|
||||||
|
@paginate
|
||||||
|
def accessrestrictiongroup_list(request):
|
||||||
|
# todo cache?
|
||||||
|
return mapdata_list_endpoint(request, model=AccessRestrictionGroup)
|
||||||
|
|
||||||
|
|
||||||
|
@mapdata_api_router.get('/accessrestrictiongroups/{group_id}/', response=AccessRestrictionGroupSchema,
|
||||||
|
summary="Get access restriction group by ID")
|
||||||
|
def accessrestrictiongroups_detail(request, group_id: int):
|
||||||
|
# todo: access, caching, filtering, etc
|
||||||
|
return mapdata_retrieve_endpoint(request, AccessRestrictionGroup, pk=group_id)
|
||||||
|
|
|
@ -10,12 +10,6 @@ from c3nav.api.schema import LineStringSchema, PointSchema, PolygonSchema
|
||||||
from c3nav.api.utils import NonEmptyStr
|
from c3nav.api.utils import NonEmptyStr
|
||||||
|
|
||||||
|
|
||||||
class DjangoModelSchema(Schema):
|
|
||||||
id: PositiveInt = APIField(
|
|
||||||
title="ID",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SerializableSchema(Schema):
|
class SerializableSchema(Schema):
|
||||||
@model_validator(mode="wrap") # noqa
|
@model_validator(mode="wrap") # noqa
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -25,6 +19,12 @@ class SerializableSchema(Schema):
|
||||||
return handler(values)
|
return handler(values)
|
||||||
|
|
||||||
|
|
||||||
|
class DjangoModelSchema(SerializableSchema):
|
||||||
|
id: PositiveInt = APIField(
|
||||||
|
title="ID",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LocationSlugSchema(Schema):
|
class LocationSlugSchema(Schema):
|
||||||
slug: NonEmptyStr = APIField(
|
slug: NonEmptyStr = APIField(
|
||||||
title="location slug",
|
title="location slug",
|
||||||
|
@ -36,7 +36,7 @@ class LocationSlugSchema(Schema):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AccessRestrictionSchema(Schema):
|
class WithAccessRestrictionSchema(Schema):
|
||||||
access_restriction: Optional[PositiveInt] = APIField(
|
access_restriction: Optional[PositiveInt] = APIField(
|
||||||
default=None,
|
default=None,
|
||||||
title="access restriction ID",
|
title="access restriction ID",
|
||||||
|
@ -58,7 +58,7 @@ class TitledSchema(Schema):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LocationSchema(AccessRestrictionSchema, TitledSchema, LocationSlugSchema, SerializableSchema):
|
class LocationSchema(WithAccessRestrictionSchema, TitledSchema, LocationSlugSchema):
|
||||||
subtitle: NonEmptyStr = APIField(
|
subtitle: NonEmptyStr = APIField(
|
||||||
title="subtitle (preferred language)",
|
title="subtitle (preferred language)",
|
||||||
description="an automatically generated short description for this location. "
|
description="an automatically generated short description for this location. "
|
||||||
|
|
|
@ -4,8 +4,8 @@ from pydantic import Field as APIField
|
||||||
from pydantic import NonNegativeFloat, PositiveFloat, PositiveInt
|
from pydantic import NonNegativeFloat, PositiveFloat, PositiveInt
|
||||||
|
|
||||||
from c3nav.api.utils import NonEmptyStr
|
from c3nav.api.utils import NonEmptyStr
|
||||||
from c3nav.mapdata.schemas.model_base import (AccessRestrictionSchema, DjangoModelSchema, LabelSettingsSchema,
|
from c3nav.mapdata.schemas.model_base import (DjangoModelSchema, LabelSettingsSchema, LocationSchema,
|
||||||
LocationSchema, SerializableSchema, SpecificLocationSchema, TitledSchema,
|
SpecificLocationSchema, TitledSchema, WithAccessRestrictionSchema,
|
||||||
WithLevelSchema, WithLineStringGeometrySchema, WithPointGeometrySchema,
|
WithLevelSchema, WithLineStringGeometrySchema, WithPointGeometrySchema,
|
||||||
WithPolygonGeometrySchema, WithSpaceSchema)
|
WithPolygonGeometrySchema, WithSpaceSchema)
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class SpaceSchema(WithPolygonGeometrySchema, SpecificLocationSchema, WithLevelSc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DoorSchema(WithPolygonGeometrySchema, AccessRestrictionSchema, WithLevelSchema, DjangoModelSchema):
|
class DoorSchema(WithPolygonGeometrySchema, WithAccessRestrictionSchema, WithLevelSchema, DjangoModelSchema):
|
||||||
"""
|
"""
|
||||||
A link between two spaces
|
A link between two spaces
|
||||||
"""
|
"""
|
||||||
|
@ -221,7 +221,7 @@ class LocationGroupSchema(LocationSchema, DjangoModelSchema):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LocationGroupCategorySchema(TitledSchema, SerializableSchema, DjangoModelSchema):
|
class LocationGroupCategorySchema(TitledSchema, DjangoModelSchema):
|
||||||
"""
|
"""
|
||||||
A location group category can hold either one or multiple location groups.
|
A location group category can hold either one or multiple location groups.
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ class LocationGroupCategorySchema(TitledSchema, SerializableSchema, DjangoModelS
|
||||||
priority: int = APIField() # todo: ???
|
priority: int = APIField() # todo: ???
|
||||||
|
|
||||||
|
|
||||||
class SourceSchema(AccessRestrictionSchema, DjangoModelSchema):
|
class SourceSchema(WithAccessRestrictionSchema, DjangoModelSchema):
|
||||||
"""
|
"""
|
||||||
A source image that can be traced in the editor.
|
A source image that can be traced in the editor.
|
||||||
"""
|
"""
|
||||||
|
@ -289,3 +289,22 @@ class SourceSchema(AccessRestrictionSchema, DjangoModelSchema):
|
||||||
left: float
|
left: float
|
||||||
top: float
|
top: float
|
||||||
right: float
|
right: float
|
||||||
|
|
||||||
|
|
||||||
|
class AccessRestrictionSchema(TitledSchema, DjangoModelSchema):
|
||||||
|
"""
|
||||||
|
A category that some objects can belong to.
|
||||||
|
|
||||||
|
If they do, you can only see them if you have a permission to see objects with this access retriction.
|
||||||
|
"""
|
||||||
|
open: bool
|
||||||
|
groups: list[PositiveInt] = APIField(
|
||||||
|
title="access restriction groups"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AccessRestrictionGroupSchema(WithAccessRestrictionSchema, DjangoModelSchema):
|
||||||
|
"""
|
||||||
|
For simplicity's sake, access restrictions can belong to groups, and you can grant permissions for the entire group.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue