15 lines
627 B
Python
15 lines
627 B
Python
from fastapi import APIRouter, HTTPException, status
|
|
from schemas.car import CarCreate, CarSchema
|
|
from helpers.car_helpers import create_car, normalize_car_data
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/create-car", response_model=CarSchema, status_code=status.HTTP_201_CREATED)
|
|
async def create_new_car(car: CarCreate):
|
|
"""Create a new car with the provided name and color"""
|
|
try:
|
|
normalized_data = normalize_car_data({"name": car.name, "color": car.color})
|
|
new_car = create_car(normalized_data)
|
|
return new_car
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e)) |