39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from core.database import fake_users_db
|
|
from typing import Optional
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/endpoint")
|
|
async def distance_handler(
|
|
start_point: str,
|
|
end_point: str,
|
|
unit: Optional[str] = "km"
|
|
):
|
|
"""Calculate distance between two points"""
|
|
if not start_point or not end_point:
|
|
raise HTTPException(status_code=400, detail="Both start and end points are required")
|
|
|
|
if unit not in ["km", "miles", "meters"]:
|
|
raise HTTPException(status_code=400, detail="Invalid unit. Must be km, miles, or meters")
|
|
|
|
# Demo calculation - would be replaced with actual distance calculation
|
|
demo_distances = {
|
|
"km": 100,
|
|
"miles": 62.1371,
|
|
"meters": 100000
|
|
}
|
|
|
|
return {
|
|
"message": "Distance calculated successfully",
|
|
"data": {
|
|
"start_point": start_point,
|
|
"end_point": end_point,
|
|
"distance": demo_distances[unit],
|
|
"unit": unit
|
|
},
|
|
"metadata": {
|
|
"calculation_method": "demo",
|
|
"accuracy": "approximate"
|
|
}
|
|
} |