parent
48d62c3178
commit
b1761484cb
@ -0,0 +1,82 @@
|
||||
import { TmdbMovieDetails } from '../api/themoviedb';
|
||||
import { MediaRequest } from '../entity/MediaRequest';
|
||||
|
||||
interface ProductionCompany {
|
||||
id: number;
|
||||
logoPath?: string;
|
||||
originCountry: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface MovieDetails {
|
||||
id: number;
|
||||
imdbId?: string;
|
||||
adult: boolean;
|
||||
backdropPath?: string;
|
||||
budget: number;
|
||||
genres: {
|
||||
id: number;
|
||||
name: string;
|
||||
}[];
|
||||
homepage?: string;
|
||||
originalLanguage: string;
|
||||
originalTitle: string;
|
||||
overview?: string;
|
||||
popularity: number;
|
||||
posterPath?: string;
|
||||
productionCompanies: ProductionCompany[];
|
||||
productionCountries: {
|
||||
iso_3166_1: string;
|
||||
name: string;
|
||||
}[];
|
||||
releaseDate: string;
|
||||
revenue: number;
|
||||
runtime?: number;
|
||||
spokenLanguages: {
|
||||
iso_639_1: string;
|
||||
name: string;
|
||||
}[];
|
||||
status: string;
|
||||
tagline?: string;
|
||||
title: string;
|
||||
video: boolean;
|
||||
voteAverage: number;
|
||||
voteCount: number;
|
||||
request?: MediaRequest;
|
||||
}
|
||||
|
||||
export const mapMovieDetails = (
|
||||
movie: TmdbMovieDetails,
|
||||
request?: MediaRequest
|
||||
): MovieDetails => ({
|
||||
id: movie.id,
|
||||
adult: movie.adult,
|
||||
budget: movie.budget,
|
||||
genres: movie.genres,
|
||||
originalLanguage: movie.original_language,
|
||||
originalTitle: movie.original_title,
|
||||
popularity: movie.popularity,
|
||||
productionCompanies: movie.production_companies.map((company) => ({
|
||||
id: company.id,
|
||||
logoPath: company.logo_path,
|
||||
originCountry: company.origin_country,
|
||||
name: company.name,
|
||||
})),
|
||||
productionCountries: movie.production_countries,
|
||||
releaseDate: movie.release_date,
|
||||
revenue: movie.revenue,
|
||||
spokenLanguages: movie.spoken_languages,
|
||||
status: movie.status,
|
||||
title: movie.title,
|
||||
video: movie.video,
|
||||
voteAverage: movie.vote_average,
|
||||
voteCount: movie.vote_count,
|
||||
backdropPath: movie.backdrop_path,
|
||||
homepage: movie.homepage,
|
||||
imdbId: movie.imdb_id,
|
||||
overview: movie.overview,
|
||||
posterPath: movie.poster_path,
|
||||
runtime: movie.runtime,
|
||||
tagline: movie.tagline,
|
||||
request,
|
||||
});
|
@ -0,0 +1,18 @@
|
||||
import { Router } from 'express';
|
||||
import TheMovieDb from '../api/themoviedb';
|
||||
import { mapMovieDetails } from '../models/Movie';
|
||||
import { MediaRequest } from '../entity/MediaRequest';
|
||||
|
||||
const movieRoutes = Router();
|
||||
|
||||
movieRoutes.get('/:id', async (req, res) => {
|
||||
const tmdb = new TheMovieDb();
|
||||
|
||||
const movie = await tmdb.getMovie({ movieId: Number(req.params.id) });
|
||||
|
||||
const request = await MediaRequest.getRequest(movie.id);
|
||||
|
||||
return res.status(200).json(mapMovieDetails(movie, request));
|
||||
});
|
||||
|
||||
export default movieRoutes;
|
Loading…
Reference in new issue