import Car from "../models/Car.js";
 
export const createCar = async (req, res) => {
    try {
        const car = await Car.create(req.body);
        res.status(201).json(car);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};
 
export const getCar = async (req, res) => {
    try {
        const cars = await Car.find();
        res.status(200).json(cars);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};
 
export const updateCar = async (req, res) => {
    try {
        const car = await Car.findByIdAndUpdate(req.params.id, req.body, { new: true });
        res.status(200).json(car);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};
 
export const deleteCar = async (req, res) => {
    try {
        const car = await Car.findByIdAndDelete(req.params.id);
        res.status(200).json(car);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};