 import Car from "../models/CarModels.js"

 export const carCreate = 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});
    }
 };

 //read

 export const getAllCars = async (req,res) => {
    try{
        const car = await Car.find();
        res.status(201).json(car);
    }catch(error){
        res.status(500).json({message:error.message});
    }
 };

 //update

 export const updateCar = async(req, res) => {
    try{
        const updateCar = await Car.findByIdAndUpdate(req.params.id, req.body, {new:true});
        res.status(201).json(updateCar);
    }catch(error){
res.status(500).json({message:error.message});
    }
 };

 //delete

 export const deleteCar = async (req,res) => {
try{
    await Car.findByIdAndDelete(req.params.id);
    res.status(201).json({message:"car deleted successfully"});
}catch(error){
    res.status(500).json({message:error.message});
}
 };