const express = require('express');
const asyncHandler = require('express-async-handler');
const animeCtrl = require('../controllers/anime.controller');

const router = express.Router();
module.exports = router;

//router.use(passport.authenticate('jwt', { session: false }))

router.route('/add').post(asyncHandler(insert));
router.route('/get/:sid(\d+)').get(asyncHandler(get));
router.route('/all').get(asyncHandler(getAll));
router.route('/search').get(asyncHandler(search));


async function insert(req, res) {
  let anime = await animeCtrl.insert(req.body);
  res.json(anime);
}

async function get(req, res) {
  let all_animes = await animeCtrl.get(req.params['sid']);
  res.json(all_animes);
}

async function getAll(req, res) {
  let all_animes = await animeCtrl.getAll();
  res.json(all_animes);
}

async function search(req, res) {
  let result = await animeCtrl.search(req.params['key'], req.params['value']);
  res.json(result);
}
