UNPKG

@meisens1/lotr-sdk

Version:
68 lines (59 loc) 2.34 kB
const express = require('express'); const router = express.Router(); const quoteController = require('../controllers/quoteController'); const movieController = require('../controllers/movieController'); const { accessToken } = require('../config'); //Movie Routes //Route: /Movie (paginated) router.get('/movie', async(req, res) => { const { page, limit } = req.query; try { const { movies, pagination } = await movieController.getMovies(accessToken, page, limit); res.json({ movies, pagination }); } catch (error) { res.status(500).json({ error: 'Failed to retrieve movies' }); } }); //Route: /movie/{id} Get Movie By Id router.get('/movie/:id', async(req, res) => { const { id } = req.params; try { const movie = await movieController.getMovieById(accessToken, id); res.json(movie); } catch (error) { res.status(500).json({ error: `Failed to retrieve movie with ID ${id}` }); } }); //Quote Routes //Route: /movie/{id}/quote -- Get Quotes by Movie Id Paginated (this goes into the quotes controller because it returns the quotes model) router.get('/movie/:id/quote', async(req, res) => { const { id, page, limit } = req.params; try { const quote = await quoteController.getQuoteByMovieId(accessToken, id, page, limit); res.json(quote); } catch (error) { res.status(500).json({ error: `Failed to retrieve quotes for movie with ID ${id}` }); } }); //Route: /quote (paginated) router.get('/quote', async(req, res) => { const { page, limit } = req.query; try { const { quotes, pagination } = await quoteController.getQuotes(accessToken, page, limit); res.json({ quotes, pagination }); } catch (error) { res.status(500).json({ error: 'Failed to retrieve quotes' }); } }); //Route: /quote/{id} Get Quote by Quote Id router.get('/quote/:id', async(req, res) => { const { id } = req.params; try { const quote = await quoteController.getQuoteById(accessToken, id); res.json(quote); } catch (error) { res.status(500).json({ error: `Failed to retrieve quote with ID ${id}` }); } }); //TODO: Additional routes for the api, book, character, etc. module.exports = router;