Migrate location recorder and refine db config
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import json
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import PlainTextResponse, Response
|
||||
from pydantic import ValidationError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.dependencies import get_db
|
||||
from app.schemas.location import LocationRecordRequest
|
||||
from app.services.location import record_location
|
||||
|
||||
router = APIRouter(tags=["location"])
|
||||
|
||||
|
||||
@router.post("/location/record")
|
||||
async def create_location_record(request: Request, db: Session = Depends(get_db)) -> Response:
|
||||
try:
|
||||
raw_payload = await request.body()
|
||||
data = json.loads(raw_payload)
|
||||
payload = LocationRecordRequest.model_validate(data)
|
||||
except json.JSONDecodeError as exc:
|
||||
return PlainTextResponse(str(exc), status_code=400)
|
||||
except ValidationError as exc:
|
||||
return PlainTextResponse(str(exc), status_code=400)
|
||||
|
||||
record_location(db, payload)
|
||||
return Response(status_code=200)
|
||||
|
||||
Reference in New Issue
Block a user