more schema for positioning API
This commit is contained in:
parent
210d079bb7
commit
67e5b0f8a1
1 changed files with 28 additions and 13 deletions
|
@ -1,36 +1,51 @@
|
||||||
from typing import Annotated
|
from typing import Annotated, Optional
|
||||||
|
|
||||||
from ninja import Field as APIField
|
from ninja import Field as APIField
|
||||||
from ninja import Router as APIRouter
|
from ninja import Router as APIRouter, Schema
|
||||||
|
from pydantic import NegativeInt
|
||||||
|
|
||||||
from c3nav.api.newauth import auth_responses
|
from c3nav.api.newauth import auth_responses
|
||||||
|
from c3nav.api.utils import NonEmptyStr
|
||||||
from c3nav.mapdata.models import Source
|
from c3nav.mapdata.models import Source
|
||||||
|
from c3nav.mapdata.schemas.models import CustomLocationSchema
|
||||||
from c3nav.mapdata.schemas.responses import BoundsSchema
|
from c3nav.mapdata.schemas.responses import BoundsSchema
|
||||||
from c3nav.routing.rangelocator import RangeLocator
|
from c3nav.routing.rangelocator import RangeLocator
|
||||||
|
|
||||||
|
BSSIDSchema = Annotated[str, APIField(pattern=r"^[a-z0-9]{2}(:[a-z0-9]{2}){5}$", title="BSSID")]
|
||||||
|
|
||||||
positioning_api_router = APIRouter(tags=["positioning"])
|
positioning_api_router = APIRouter(tags=["positioning"])
|
||||||
|
|
||||||
|
|
||||||
|
class LocateRequestItemSchema(Schema):
|
||||||
|
ssid: NonEmptyStr
|
||||||
|
bssid: BSSIDSchema
|
||||||
|
rssi: NegativeInt
|
||||||
|
distance: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
|
class LocateRequestSchema(Schema):
|
||||||
|
items: list[LocateRequestItemSchema]
|
||||||
|
|
||||||
|
|
||||||
|
class PositioningResult(Schema):
|
||||||
|
location: Optional[CustomLocationSchema]
|
||||||
|
|
||||||
|
|
||||||
@positioning_api_router.post('/locate/', summary="locate based on wifi scans",
|
@positioning_api_router.post('/locate/', summary="locate based on wifi scans",
|
||||||
response={200: BoundsSchema, **auth_responses})
|
response={200: PositioningResult, **auth_responses})
|
||||||
def locate():
|
def locate(locate_data: LocateRequestSchema):
|
||||||
# todo: implement
|
# todo: implement
|
||||||
return {
|
raise NotImplementedError
|
||||||
"bounds": Source.max_bounds(),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@positioning_api_router.get('/locate-test/', summary="get dummy location for debugging",
|
@positioning_api_router.get('/locate-test/', summary="get dummy location for debugging",
|
||||||
response={200: BoundsSchema, **auth_responses})
|
response={200: PositioningResult, **auth_responses})
|
||||||
def locate_test():
|
def locate_test():
|
||||||
# todo: implement
|
raise NotImplementedError
|
||||||
return {
|
|
||||||
"bounds": Source.max_bounds(),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BeaconsXYZ = dict[
|
BeaconsXYZ = dict[
|
||||||
Annotated[str, APIField(pattern=r"^[a-z0-9]{2}(:[a-z0-9]{2}){5}$", title="BSSID")],
|
BSSIDSchema,
|
||||||
Annotated[
|
Annotated[
|
||||||
tuple[
|
tuple[
|
||||||
Annotated[int, APIField(title="X (in cm)")],
|
Annotated[int, APIField(title="X (in cm)")],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue