Skip to content

Commit

Permalink
feat(api): tv details endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sct committed Sep 16, 2020
1 parent b176148 commit a3beeed
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 24 deletions.
22 changes: 12 additions & 10 deletions server/api/themoviedb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export interface TmdbMovieDetails {
vote_count: number;
}

interface TmdbTvEpisodeDetails {
export interface TmdbTvEpisodeDetails {
id: number;
air_date: string;
episode_number: number;
Expand All @@ -154,6 +154,16 @@ interface TmdbTvEpisodeDetails {
vote_cuont: number;
}

export interface TmdbTvSeasonDetails {
id: number;
air_date: string;
episode_count: number;
name: string;
overview: string;
poster_path: string;
season_number: number;
}

export interface TmdbTvDetails {
id: number;
backdrop_path?: string;
Expand Down Expand Up @@ -197,15 +207,7 @@ export interface TmdbTvDetails {
name: string;
origin_country: string;
}[];
seasons: {
id: number;
air_date: string;
episode_count: number;
name: string;
overview: string;
poster_path: string;
season_number: number;
}[];
seasons: TmdbTvSeasonDetails[];
status: string;
type: string;
vote_average: number;
Expand Down
6 changes: 4 additions & 2 deletions server/entity/MediaRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class MediaRequest {
finalIds = mediaIds;
}

const requests = await requestRepository.find({ mediaId: In(finalIds) });
const requests = await requestRepository.find({
mediaId: In(finalIds),
});

return requests;
} catch (e) {
Expand All @@ -54,7 +56,7 @@ export class MediaRequest {

try {
const request = await requestRepository.findOneOrFail({
where: { tmdbId: id },
where: { mediaId: id },
});

return request;
Expand Down
13 changes: 2 additions & 11 deletions server/models/Movie.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import { TmdbMovieDetails } from '../api/themoviedb';
import { MediaRequest } from '../entity/MediaRequest';

interface ProductionCompany {
id: number;
logoPath?: string;
originCountry: string;
name: string;
}
import { ProductionCompany, Genre } from './common';

export interface MovieDetails {
id: number;
imdbId?: string;
adult: boolean;
backdropPath?: string;
budget: number;
genres: {
id: number;
name: string;
}[];
genres: Genre[];
homepage?: string;
originalLanguage: string;
originalTitle: string;
Expand Down
144 changes: 144 additions & 0 deletions server/models/Tv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { Genre, ProductionCompany } from './common';
import { MediaRequest } from '../entity/MediaRequest';
import {
TmdbTvEpisodeDetails,
TmdbTvSeasonDetails,
TmdbTvDetails,
} from '../api/themoviedb';

interface Episode {
id: number;
name: string;
airDate: string;
episodeNumber: number;
overview: string;
productionCode: string;
seasonNumber: number;
showId: number;
stillPath?: string;
voteAverage: number;
voteCount: number;
}

interface Season {
airDate: string;
id: number;
episodeCount: number;
name: string;
overview: string;
posterPath?: string;
seasonNumber: number;
}

export interface TvDetails {
id: number;
backdropPath?: string;
posterPath?: string;
createdBy: {
id: number;
name: string;
gender: number;
profilePath?: string;
}[];
episodeRunTime: number[];
firstAirDate: string;
genres: Genre[];
homepage: string;
inProduction: boolean;
languages: string[];
lastAirDate: string;
lastEpisodeToAir?: Episode;
name: string;
nextEpisodeToAir?: Episode;
networks: ProductionCompany[];
numberOfEpisodes: number;
numberOfSeasons: number;
originCountry: string[];
originalLanguage: string;
originalName: string;
overview: string;
popularity: number;
productionCompanies: ProductionCompany[];
seasons: Season[];
status: string;
type: string;
voteAverage: number;
voteCount: number;
request?: MediaRequest;
}

const mapEpisodeDetails = (episode: TmdbTvEpisodeDetails): Episode => ({
id: episode.id,
airDate: episode.air_date,
episodeNumber: episode.episode_number,
name: episode.name,
overview: episode.overview,
productionCode: episode.production_code,
seasonNumber: episode.season_number,
showId: episode.show_id,
voteAverage: episode.vote_average,
voteCount: episode.vote_cuont,
stillPath: episode.still_path,
});

const mapSeasonDetails = (season: TmdbTvSeasonDetails): Season => ({
airDate: season.air_date,
episodeCount: season.episode_count,
id: season.id,
name: season.name,
overview: season.overview,
seasonNumber: season.season_number,
posterPath: season.poster_path,
});

export const mapTvDetails = (
show: TmdbTvDetails,
request?: MediaRequest
): TvDetails => ({
createdBy: show.created_by,
episodeRunTime: show.episode_run_time,
firstAirDate: show.first_air_date,
genres: show.genres.map((genre) => ({
id: genre.id,
name: genre.name,
})),
homepage: show.homepage,
id: show.id,
inProduction: show.in_production,
languages: show.languages,
lastAirDate: show.last_air_date,
name: show.name,
networks: show.networks.map((network) => ({
id: network.id,
name: network.name,
originCountry: network.origin_country,
logoPath: network.logo_path,
})),
numberOfEpisodes: show.number_of_episodes,
numberOfSeasons: show.number_of_seasons,
originCountry: show.origin_country,
originalLanguage: show.original_language,
originalName: show.original_name,
overview: show.overview,
popularity: show.popularity,
productionCompanies: show.production_companies.map((company) => ({
id: company.id,
name: company.name,
originCountry: company.origin_country,
logoPath: company.logo_path,
})),
seasons: show.seasons.map(mapSeasonDetails),
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)
: undefined,
nextEpisodeToAir: show.next_episode_to_air
? mapEpisodeDetails(show.next_episode_to_air)
: undefined,
posterPath: show.poster_path,
request,
});
11 changes: 11 additions & 0 deletions server/models/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface ProductionCompany {
id: number;
logoPath?: string;
originCountry: string;
name: string;
}

export interface Genre {
id: number;
name: string;
}

0 comments on commit a3beeed

Please sign in to comment.