Files
service-finder/backend/app/api/v1/endpoints/constants.py

88 lines
3.0 KiB
Python

"""
Constants API Endpoint
======================
Serves static dictionaries (vehicle features, drive types, etc.)
to the frontend so it doesn't need to hardcode them.
"""
from fastapi import APIRouter, Query
from app.constants.vehicle_features import (
CAR_FEATURES,
CAR_DRIVE_TYPES,
CAR_TRANSMISSION_TYPES,
CAR_AC_TYPES,
CAR_BODY_TYPES,
AC_CONNECTOR_TYPES,
DC_CONNECTOR_TYPES,
MOTORCYCLE_STROKES,
MOTORCYCLE_COOLING,
MOTORCYCLE_MIXTURE,
MOTORCYCLE_FEATURES,
LCV_BODY_TYPES,
LCV_FEATURES,
HGV_TRANSMISSION_TYPES,
HGV_PTO_TYPES,
HGV_BODY_TYPES,
HGV_FEATURES,
)
router = APIRouter()
@router.get("/vehicle-features")
async def get_vehicle_features(
type: str = Query(None, description="Filter by vehicle type: 'car', 'motorcycle', 'lcv' or 'hgv'")
):
"""Return all vehicle feature dictionaries for frontend use.
If ?type=motorcycle is provided, returns motorcycle-specific data.
If ?type=lcv is provided, returns LCV-specific data.
If ?type=hgv is provided, returns HGV-specific data.
Otherwise returns car-specific data.
"""
if type == "motorcycle":
return {
**MOTORCYCLE_FEATURES, # Spread categories directly: technical, frame_body, luggage, multimedia, other
"drive_types": CAR_DRIVE_TYPES,
"transmission_types": CAR_TRANSMISSION_TYPES,
"ac_types": {}, # No AC types for motorcycles
"body_types": {}, # No body types for motorcycles
"ac_connector_types": AC_CONNECTOR_TYPES,
"dc_connector_types": DC_CONNECTOR_TYPES,
"motorcycle_strokes": MOTORCYCLE_STROKES,
"motorcycle_cooling": MOTORCYCLE_COOLING,
"motorcycle_mixture": MOTORCYCLE_MIXTURE,
}
if type == "lcv":
return {
**LCV_FEATURES, # Spread categories directly: technical, interior, exterior, multimedia
"drive_types": CAR_DRIVE_TYPES,
"transmission_types": CAR_TRANSMISSION_TYPES,
"ac_types": CAR_AC_TYPES,
"body_types": LCV_BODY_TYPES,
"ac_connector_types": AC_CONNECTOR_TYPES,
"dc_connector_types": DC_CONNECTOR_TYPES,
}
if type == "hgv":
return {
**HGV_FEATURES, # Spread categories directly: technical_work, cabin, multimedia
"drive_types": CAR_DRIVE_TYPES,
"transmission_types": HGV_TRANSMISSION_TYPES,
"pto_types": HGV_PTO_TYPES,
"ac_types": CAR_AC_TYPES,
"body_types": HGV_BODY_TYPES,
"ac_connector_types": AC_CONNECTOR_TYPES,
"dc_connector_types": DC_CONNECTOR_TYPES,
}
return {
**CAR_FEATURES, # Spread categories directly: technical, interior, exterior, multimedia, other
"drive_types": CAR_DRIVE_TYPES,
"transmission_types": CAR_TRANSMISSION_TYPES,
"ac_types": CAR_AC_TYPES,
"body_types": CAR_BODY_TYPES,
"ac_connector_types": AC_CONNECTOR_TYPES,
"dc_connector_types": DC_CONNECTOR_TYPES,
}