const asyncHandler = require("express-async-handler");
const { save, getAll } = require("../services/favorites");

exports.save = asyncHandler(async (req, res, next) => {

    try{
        let result = await save(req.body);
        console.log(result);
        res.status(204).send({message: "Favorite created"});
    }catch(err){
        console.log(err);
        return res.status(500).send({error: err});
    }
    
});

exports.getAll = asyncHandler(async (req, res, next) => {
    console.log("controller getAll");
    try{
        let result = await getAll();
        console.log(result);
        res.status(200).send(result);
    }catch(err){
        console.log(err);
        return res.status(500).send({error: err});
    }
});