const favouriteFunction = require("../function/favourite");

const addToFavourite = async (req, res) => {
    try {
        const favourite = await favouriteFunction.addToFavourite(req);
        if(!favourite){
            return res.status(200).json({
            success: true,
            msg: "Removed From Favourite!", 
        })  
        } else {
            return res.status(200).json({
            success: true,
            msg: "Added to Favourite!",
            data: favourite 
        })  
        }
    } catch (error) {
        console.log("Having Errors :", error);
        return res.status(400).json({
            success: false,
            msg: "Having Errors!",
            error: error.message
        })
    }
};

const getAllFavourites = async (req, res) => {
    try {
        const result = await favouriteFunction.getAllFavourites(req);
        return res.status(200).json({
            success: true,
            msg: "All Favourites!",
            data: result
        })  
    } catch (error) {
        console.log("Having Errors :", error);
        return res.status(400).json({
            success: false,
            msg: "Having Errors!",
            error: error.message
        })
    }
};

module.exports = {
    addToFavourite,
    getAllFavourites
};