feat(frontend/api): beginning of new request modal
also includes new api endpoints for seasons
This commit is contained in:
@@ -183,7 +183,7 @@ export interface TmdbMovieDetails {
|
||||
external_ids: TmdbExternalIds;
|
||||
}
|
||||
|
||||
export interface TmdbTvEpisodeDetails {
|
||||
export interface TmdbTvEpisodeResult {
|
||||
id: number;
|
||||
air_date: string;
|
||||
episode_number: number;
|
||||
@@ -197,13 +197,13 @@ export interface TmdbTvEpisodeDetails {
|
||||
vote_cuont: number;
|
||||
}
|
||||
|
||||
export interface TmdbTvSeasonDetails {
|
||||
export interface TmdbTvSeasonResult {
|
||||
id: number;
|
||||
air_date: string;
|
||||
episode_count: number;
|
||||
name: string;
|
||||
overview: string;
|
||||
poster_path: string;
|
||||
poster_path?: string;
|
||||
season_number: number;
|
||||
}
|
||||
|
||||
@@ -227,9 +227,9 @@ export interface TmdbTvDetails {
|
||||
in_production: boolean;
|
||||
languages: string[];
|
||||
last_air_date: string;
|
||||
last_episode_to_air?: TmdbTvEpisodeDetails;
|
||||
last_episode_to_air?: TmdbTvEpisodeResult;
|
||||
name: string;
|
||||
next_episode_to_air?: TmdbTvEpisodeDetails;
|
||||
next_episode_to_air?: TmdbTvEpisodeResult;
|
||||
networks: {
|
||||
id: number;
|
||||
name: string;
|
||||
@@ -250,7 +250,7 @@ export interface TmdbTvDetails {
|
||||
name: string;
|
||||
origin_country: string;
|
||||
}[];
|
||||
seasons: TmdbTvSeasonDetails[];
|
||||
seasons: TmdbTvSeasonResult[];
|
||||
status: string;
|
||||
type: string;
|
||||
vote_average: number;
|
||||
@@ -262,6 +262,11 @@ export interface TmdbTvDetails {
|
||||
external_ids: TmdbExternalIds;
|
||||
}
|
||||
|
||||
export interface TmdbSeasonWithEpisodes extends TmdbTvSeasonResult {
|
||||
episodes: TmdbTvEpisodeResult[];
|
||||
external_ids: TmdbExternalIds;
|
||||
}
|
||||
|
||||
class TheMovieDb {
|
||||
private apiKey = 'db55323b8d3e4154498498a75642b381';
|
||||
private axios: AxiosInstance;
|
||||
@@ -335,6 +340,32 @@ class TheMovieDb {
|
||||
}
|
||||
};
|
||||
|
||||
public getTvSeason = async ({
|
||||
tvId,
|
||||
seasonNumber,
|
||||
language,
|
||||
}: {
|
||||
tvId: number;
|
||||
seasonNumber: number;
|
||||
language?: string;
|
||||
}): Promise<TmdbSeasonWithEpisodes> => {
|
||||
try {
|
||||
const response = await this.axios.get<TmdbSeasonWithEpisodes>(
|
||||
`/tv/${tvId}/season/${seasonNumber}`,
|
||||
{
|
||||
params: {
|
||||
language,
|
||||
append_to_response: 'external_ids',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return response.data;
|
||||
} catch (e) {
|
||||
throw new Error(`[TMDB] Failed to fetch tv show details: ${e.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
public async getMovieRecommendations({
|
||||
movieId,
|
||||
page = 1,
|
||||
|
||||
@@ -43,13 +43,13 @@ class Media {
|
||||
const mediaRepository = getRepository(Media);
|
||||
|
||||
try {
|
||||
const media = await mediaRepository.findOneOrFail({
|
||||
const media = await mediaRepository.findOne({
|
||||
where: { tmdbId: id },
|
||||
});
|
||||
|
||||
return media;
|
||||
} catch (e) {
|
||||
logger.error(e.messaage);
|
||||
logger.error(e.message);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ class Media {
|
||||
public status: MediaStatus;
|
||||
|
||||
@OneToMany(() => MediaRequest, (request) => request.media)
|
||||
public requests: MediaRequest;
|
||||
public requests: MediaRequest[];
|
||||
|
||||
@CreateDateColumn()
|
||||
public createdAt: Date;
|
||||
|
||||
@@ -6,7 +6,6 @@ import Media from '../entity/Media';
|
||||
import { MediaStatus, MediaType } from '../constants/media';
|
||||
import logger from '../logger';
|
||||
import { getSettings, Library } from '../lib/settings';
|
||||
import { resolve } from 'dns';
|
||||
|
||||
const BUNDLE_SIZE = 10;
|
||||
|
||||
|
||||
@@ -9,9 +9,10 @@ import {
|
||||
mapExternalIds,
|
||||
} from './common';
|
||||
import {
|
||||
TmdbTvEpisodeDetails,
|
||||
TmdbTvSeasonDetails,
|
||||
TmdbTvEpisodeResult,
|
||||
TmdbTvSeasonResult,
|
||||
TmdbTvDetails,
|
||||
TmdbSeasonWithEpisodes,
|
||||
} from '../api/themoviedb';
|
||||
import type Media from '../entity/Media';
|
||||
|
||||
@@ -39,6 +40,11 @@ interface Season {
|
||||
seasonNumber: number;
|
||||
}
|
||||
|
||||
interface SeasonWithEpisodes extends Season {
|
||||
episodes: Episode[];
|
||||
externalIds: ExternalIds;
|
||||
}
|
||||
|
||||
export interface TvDetails {
|
||||
id: number;
|
||||
backdropPath?: string;
|
||||
@@ -81,7 +87,7 @@ export interface TvDetails {
|
||||
mediaInfo?: Media;
|
||||
}
|
||||
|
||||
const mapEpisodeDetails = (episode: TmdbTvEpisodeDetails): Episode => ({
|
||||
const mapEpisodeResult = (episode: TmdbTvEpisodeResult): Episode => ({
|
||||
id: episode.id,
|
||||
airDate: episode.air_date,
|
||||
episodeNumber: episode.episode_number,
|
||||
@@ -95,7 +101,7 @@ const mapEpisodeDetails = (episode: TmdbTvEpisodeDetails): Episode => ({
|
||||
stillPath: episode.still_path,
|
||||
});
|
||||
|
||||
const mapSeasonDetails = (season: TmdbTvSeasonDetails): Season => ({
|
||||
const mapSeasonResult = (season: TmdbTvSeasonResult): Season => ({
|
||||
airDate: season.air_date,
|
||||
episodeCount: season.episode_count,
|
||||
id: season.id,
|
||||
@@ -105,6 +111,20 @@ const mapSeasonDetails = (season: TmdbTvSeasonDetails): Season => ({
|
||||
posterPath: season.poster_path,
|
||||
});
|
||||
|
||||
export const mapSeasonWithEpisodes = (
|
||||
season: TmdbSeasonWithEpisodes
|
||||
): SeasonWithEpisodes => ({
|
||||
airDate: season.air_date,
|
||||
episodeCount: season.episode_count,
|
||||
episodes: season.episodes.map(mapEpisodeResult),
|
||||
externalIds: mapExternalIds(season.external_ids),
|
||||
id: season.id,
|
||||
name: season.name,
|
||||
overview: season.overview,
|
||||
seasonNumber: season.season_number,
|
||||
posterPath: season.poster_path,
|
||||
});
|
||||
|
||||
export const mapTvDetails = (
|
||||
show: TmdbTvDetails,
|
||||
media?: Media
|
||||
@@ -141,17 +161,17 @@ export const mapTvDetails = (
|
||||
originCountry: company.origin_country,
|
||||
logoPath: company.logo_path,
|
||||
})),
|
||||
seasons: show.seasons.map(mapSeasonDetails),
|
||||
seasons: show.seasons.map(mapSeasonResult),
|
||||
status: show.status,
|
||||
type: show.type,
|
||||
voteAverage: show.vote_average,
|
||||
voteCount: show.vote_count,
|
||||
backdropPath: show.backdrop_path,
|
||||
lastEpisodeToAir: show.last_episode_to_air
|
||||
? mapEpisodeDetails(show.last_episode_to_air)
|
||||
? mapEpisodeResult(show.last_episode_to_air)
|
||||
: undefined,
|
||||
nextEpisodeToAir: show.next_episode_to_air
|
||||
? mapEpisodeDetails(show.next_episode_to_air)
|
||||
? mapEpisodeResult(show.next_episode_to_air)
|
||||
: undefined,
|
||||
posterPath: show.poster_path,
|
||||
credits: {
|
||||
|
||||
@@ -479,6 +479,10 @@ components:
|
||||
type: string
|
||||
seasonNumber:
|
||||
type: number
|
||||
episodes:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Episode'
|
||||
TvDetails:
|
||||
type: object
|
||||
properties:
|
||||
@@ -1554,6 +1558,37 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TvDetails'
|
||||
/tv/{tvId}/season/{seasonId}:
|
||||
get:
|
||||
summary: Return season details with episode list
|
||||
description: Returns back season details with a list of episodes
|
||||
tags:
|
||||
- tv
|
||||
parameters:
|
||||
- in: path
|
||||
name: tvId
|
||||
required: true
|
||||
schema:
|
||||
type: number
|
||||
example: 76479
|
||||
- in: path
|
||||
name: seasonId
|
||||
required: true
|
||||
schema:
|
||||
type: number
|
||||
example: 1
|
||||
- in: query
|
||||
name: language
|
||||
schema:
|
||||
type: string
|
||||
example: en-US
|
||||
responses:
|
||||
'200':
|
||||
description: TV details
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Season'
|
||||
/tv/{tvId}/recommendations:
|
||||
get:
|
||||
summary: Request recommended tv series
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Router } from 'express';
|
||||
import TheMovieDb from '../api/themoviedb';
|
||||
import { MediaRequest } from '../entity/MediaRequest';
|
||||
import { mapTvDetails } from '../models/Tv';
|
||||
import { mapTvDetails, mapSeasonWithEpisodes } from '../models/Tv';
|
||||
import { mapTvResult } from '../models/Search';
|
||||
import Media from '../entity/Media';
|
||||
|
||||
@@ -20,6 +20,18 @@ tvRoutes.get('/:id', async (req, res) => {
|
||||
return res.status(200).json(mapTvDetails(tv, media));
|
||||
});
|
||||
|
||||
tvRoutes.get('/:id/season/:seasonNumber', async (req, res) => {
|
||||
const tmdb = new TheMovieDb();
|
||||
|
||||
const season = await tmdb.getTvSeason({
|
||||
tvId: Number(req.params.id),
|
||||
seasonNumber: Number(req.params.seasonNumber),
|
||||
language: req.query.language as string,
|
||||
});
|
||||
|
||||
return res.status(200).json(mapSeasonWithEpisodes(season));
|
||||
});
|
||||
|
||||
tvRoutes.get('/:id/recommendations', async (req, res) => {
|
||||
const tmdb = new TheMovieDb();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user