From 7f5131c192a9c210c072f3e2854998b6107eedc6 Mon Sep 17 00:00:00 2001 From: AlexMachin1997 Date: Sun, 16 Jun 2024 11:23:30 +0100 Subject: [PATCH] feat: Added the single tv show lookup query and enhanced the entertainment service to take into account the entertainment type e.g. movie or tv --- src/app.module.ts | 6 +- src/entertainment/entertainment.service.ts | 51 ++++++-- src/graphql.schema.ts | 6 +- src/models/Query.graphql | 1 + src/models/Show.graphql | 6 +- src/movie/movie.resolver.ts | 28 ++--- src/movie/movie.service.ts | 48 +++++--- src/show/show.module.ts | 14 +++ src/show/show.resolver.ts | 52 ++++++++ src/show/show.service.ts | 137 +++++++++++++++++++++ src/show/show.ts | 82 ++++++++++++ 11 files changed, 380 insertions(+), 51 deletions(-) create mode 100644 src/show/show.module.ts create mode 100644 src/show/show.resolver.ts create mode 100644 src/show/show.service.ts create mode 100644 src/show/show.ts diff --git a/src/app.module.ts b/src/app.module.ts index 4237983..7f319ed 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -4,11 +4,10 @@ import { GraphQLModule } from '@nestjs/graphql'; import { EntertainmentModule } from './entertainment/entertainment.module'; import { MovieModule } from './movie/movie.module'; +import { ShowModule } from './show/show.module'; import { UtilsModule } from './utils/utils.module'; @Module({ - controllers: [], - providers: [], imports: [ GraphQLModule.forRoot({ driver: ApolloDriver, @@ -41,7 +40,8 @@ import { UtilsModule } from './utils/utils.module'; }), MovieModule, UtilsModule, - EntertainmentModule + EntertainmentModule, + ShowModule ] }) export class AppModule {} diff --git a/src/entertainment/entertainment.service.ts b/src/entertainment/entertainment.service.ts index c11b4aa..5e8494e 100644 --- a/src/entertainment/entertainment.service.ts +++ b/src/entertainment/entertainment.service.ts @@ -6,6 +6,7 @@ import { BelongsToCollection, Cast, Crew, + ENTERTAINMENT_TYPES, GENDER, Keyword, Review, @@ -25,6 +26,12 @@ import { IVdoesQueryResponse } from './entertainment'; +// eslint-disable-next-line @typescript-eslint/naming-convention +interface IEntertainmentCommonArguments { + entertainmentType: ENTERTAINMENT_TYPES; + entertainmentId: number; +} + @Injectable() export class EntertainmentService { constructor( @@ -32,10 +39,13 @@ export class EntertainmentService { private readonly utilService: UtilsService ) {} - async getReview(): Promise { + async getReview({ + entertainmentType, + entertainmentId + }: IEntertainmentCommonArguments): Promise { const { data } = await firstValueFrom( this.httpService.get( - 'https://api.themoviedb.org/3/movie/19995/reviews?language=en-U', + `https://api.themoviedb.org/3/${entertainmentType.toLowerCase()}/${entertainmentId}/reviews?language=en-U`, { headers: { Accept: 'application/json', @@ -71,10 +81,13 @@ export class EntertainmentService { }; } - async getTopBilledCast(): Promise { + async getTopBilledCast({ + entertainmentType, + entertainmentId + }: IEntertainmentCommonArguments): Promise { const { data } = await firstValueFrom( this.httpService.get( - 'https://api.themoviedb.org/3/movie/19995/credits?language=en-U', + `https://api.themoviedb.org/3/${entertainmentType.toLocaleLowerCase()}/${entertainmentId}/credits?language=en-U`, { headers: { Accept: 'application/json', @@ -98,10 +111,13 @@ export class EntertainmentService { })); } - async getFeaturedCrewMembers(): Promise { + async getFeaturedCrewMembers({ + entertainmentType, + entertainmentId + }: IEntertainmentCommonArguments): Promise { const { data } = await firstValueFrom( this.httpService.get( - 'https://api.themoviedb.org/3/movie/19995/credits?language=en-U', + `https://api.themoviedb.org/3/${entertainmentType.toLowerCase()}/${entertainmentId}/credits?language=en-U`, { headers: { Accept: 'application/json', @@ -156,10 +172,13 @@ export class EntertainmentService { return featuredCrewMembers; } - async getKeywords(): Promise { + async getKeywords({ + entertainmentType, + entertainmentId + }: IEntertainmentCommonArguments): Promise { const { data } = await firstValueFrom( this.httpService.get( - 'https://api.themoviedb.org/3/movie/19995/keywords?language=en-U', + `https://api.themoviedb.org/3/${entertainmentType.toLocaleLowerCase()}/${entertainmentId}/keywords?language=en-U`, { headers: { Accept: 'application/json', @@ -174,10 +193,13 @@ export class EntertainmentService { return data.keywords; } - async getSocials(): Promise { + async getSocials({ + entertainmentType, + entertainmentId + }: IEntertainmentCommonArguments): Promise { const { data } = await firstValueFrom( this.httpService.get( - 'https://api.themoviedb.org/3/movie/19995/external_ids?language=en-U', + `https://api.themoviedb.org/3/${entertainmentType.toLowerCase()}/${entertainmentId}/external_ids?language=en-U`, { headers: { Accept: 'application/json', @@ -198,7 +220,7 @@ export class EntertainmentService { } getCollection = ( - collection: null | TheOpenMovieDatabaseBelongsToCollection + collection: undefined | null | TheOpenMovieDatabaseBelongsToCollection = null ): BelongsToCollection | null => { if (collection !== null) { return { @@ -234,10 +256,13 @@ export class EntertainmentService { return originalLanguage; }; - async getTrailerUrl(): Promise { + async getTrailerUrl({ + entertainmentType, + entertainmentId + }: IEntertainmentCommonArguments): Promise { const { data } = await firstValueFrom( this.httpService.get( - 'https://api.themoviedb.org/3/movie/19995/videos?language=en-U', + `https://api.themoviedb.org/3/${entertainmentType.toLowerCase()}/${entertainmentId}/videos?language=en-U`, { headers: { Accept: 'application/json', diff --git a/src/graphql.schema.ts b/src/graphql.schema.ts index bdacc84..e68a514 100644 --- a/src/graphql.schema.ts +++ b/src/graphql.schema.ts @@ -131,13 +131,13 @@ export interface Show { releaseDate?: Nullable; voteAverage?: Nullable; status?: Nullable; - reviews?: Nullable[]>; + review?: Nullable; recommendations?: Nullable[]>; keywords?: Nullable[]>; social?: Nullable; - featuredCast?: Nullable[]>; + topBilledCast?: Nullable[]>; featuredCrew?: Nullable[]>; - featuredVideo?: Nullable