feat(api): discover endpoint for movie/tv (#73)

pull/74/head
sct 4 years ago committed by GitHub
parent ba34e54d77
commit 258bb93be2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -732,6 +732,12 @@ paths:
schema: schema:
type: string type: string
example: 'Mulan' example: 'Mulan'
- in: query
name: page
schema:
type: number
example: 1
default: 1
responses: responses:
'200': '200':
description: Results description: Results
@ -756,6 +762,74 @@ paths:
- $ref: '#/components/schemas/MovieResult' - $ref: '#/components/schemas/MovieResult'
- $ref: '#/components/schemas/TvResult' - $ref: '#/components/schemas/TvResult'
- $ref: '#/components/schemas/PersonResult' - $ref: '#/components/schemas/PersonResult'
/discover/movies:
get:
summary: Discover movies
description: Returns a list of movies in JSON format
tags:
- search
parameters:
- in: query
name: page
schema:
type: number
example: 1
default: 1
responses:
'200':
description: Results
content:
application/json:
schema:
type: object
properties:
page:
type: number
example: 1
totalPages:
type: number
example: 20
totalResults:
type: number
example: 200
results:
type: array
items:
$ref: '#/components/schemas/MovieResult'
/discover/tv:
get:
summary: Discover TV shows
description: Returns a list of tv shows in JSON format
tags:
- search
parameters:
- in: query
name: page
schema:
type: number
example: 1
default: 1
responses:
'200':
description: Results
content:
application/json:
schema:
type: object
properties:
page:
type: number
example: 1
totalPages:
type: number
example: 20
totalResults:
type: number
example: 200
results:
type: array
items:
$ref: '#/components/schemas/TvResult'
security: security:
- cookieAuth: [] - cookieAuth: []

@ -0,0 +1,33 @@
import { Router } from 'express';
import TheMovieDb from '../api/themoviedb';
import { mapMovieResult, mapTvResult } from '../models/Search';
const discoverRoutes = Router();
discoverRoutes.get('/movies', async (req, res) => {
const tmdb = new TheMovieDb();
const data = await tmdb.getDiscoverMovies({ page: Number(req.query.page) });
return res.status(200).json({
page: data.page,
totalPages: data.total_pages,
totalResults: data.total_results,
results: data.results.map(mapMovieResult),
});
});
discoverRoutes.get('/tv', async (req, res) => {
const tmdb = new TheMovieDb();
const data = await tmdb.getDiscoverTv({ page: Number(req.query.page) });
return res.status(200).json({
page: data.page,
totalPages: data.total_pages,
totalResults: data.total_results,
results: data.results.map(mapTvResult),
});
});
export default discoverRoutes;

@ -6,6 +6,7 @@ import settingsRoutes from './settings';
import { Permission } from '../lib/permissions'; import { Permission } from '../lib/permissions';
import { getSettings } from '../lib/settings'; import { getSettings } from '../lib/settings';
import searchRoutes from './search'; import searchRoutes from './search';
import discoverRoutes from './discover';
const router = Router(); const router = Router();
@ -17,6 +18,7 @@ router.use(
settingsRoutes settingsRoutes
); );
router.use('/search', isAuthenticated(), searchRoutes); router.use('/search', isAuthenticated(), searchRoutes);
router.use('/discover', isAuthenticated(), discoverRoutes);
router.use('/auth', authRoutes); router.use('/auth', authRoutes);
router.get('/settings/public', (_req, res) => { router.get('/settings/public', (_req, res) => {

@ -7,9 +7,11 @@ const searchRoutes = Router();
searchRoutes.get('/', async (req, res) => { searchRoutes.get('/', async (req, res) => {
const tmdb = new TheMovieDb(); const tmdb = new TheMovieDb();
const results = await tmdb.searchMulti({ query: req.query.query as string }); const results = await tmdb.searchMulti({
const megaResults = mapSearchResults(results.results); query: req.query.query as string,
console.log(megaResults); page: Number(req.query.page),
});
return res.status(200).json({ return res.status(200).json({
page: results.page, page: results.page,
totalPages: results.total_pages, totalPages: results.total_pages,

Loading…
Cancel
Save