Migrate location recorder and refine db config

This commit is contained in:
2026-04-19 21:39:23 +02:00
parent 31390882ef
commit 32cc6847fd
19 changed files with 507 additions and 31 deletions
+28
View File
@@ -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)