-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from 90lucasgabriel/feature/WJ-35
WJ-35 - Create Now Playing service
- Loading branch information
Showing
10 changed files
with
119 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default interface Params { | ||
page?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default interface RawResponse { | ||
poster_path?: string; | ||
overview: string; | ||
release_date: string; | ||
genre_ids: number[]; | ||
id: number; | ||
original_title: string; | ||
original_language: string; | ||
title: string; | ||
backdrop_path?: string; | ||
popularity: number; | ||
vote_count: number; | ||
video: boolean; | ||
vote_average: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default interface Response { | ||
poster?: string; | ||
backdrop?: string; | ||
overview: string; | ||
releaseDate: string; | ||
genreIds: number[]; | ||
id: number; | ||
originalTitle: string; | ||
title: string; | ||
popularity: number; | ||
voteCount: number; | ||
voteAverage: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import tmdb from 'services/api/tmdb'; | ||
|
||
import Params from 'domains/Movie/api/NowPlaying/Params'; | ||
import RawResponse from 'domains/Movie/api/NowPlaying/RawResponse'; | ||
import Response from 'domains/Movie/api/NowPlaying/Response'; | ||
import formatDate from 'shared/utils/formatDate'; | ||
import formatTmdbImage from 'shared/utils/formatTmdbImage'; | ||
|
||
const NowPlaying = async (params?: Params): Promise<Response[]> => { | ||
const response = await rawNowPlaying(params); | ||
|
||
return parseResponse(response); | ||
}; | ||
|
||
export const rawNowPlaying = async ( | ||
params?: Params, | ||
): Promise<RawResponse[]> => { | ||
const response = await tmdb.get('/movie/now_playing', { | ||
params: { page: params?.page }, | ||
}); | ||
|
||
return response.data.results; | ||
}; | ||
|
||
const parseResponse = (rawResponse: RawResponse[]): Response[] => { | ||
let response = [] as Response[]; | ||
|
||
rawResponse.forEach(movie => { | ||
const parsedMovie = { | ||
overview: movie.overview, | ||
genreIds: movie.genre_ids, | ||
id: movie.id, | ||
originalTitle: movie.original_title, | ||
title: movie.title, | ||
popularity: movie.popularity, | ||
voteCount: movie.vote_count, | ||
voteAverage: movie.vote_average, | ||
|
||
releaseDate: formatDate({ value: movie.release_date }), | ||
poster: formatTmdbImage({ value: movie.poster_path }), | ||
backdrop: formatTmdbImage({ value: movie.backdrop_path }), | ||
} as Response; | ||
|
||
response = [...response, parsedMovie]; | ||
}); | ||
|
||
return response; | ||
}; | ||
|
||
export default NowPlaying; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as NowPlaying } from './NowPlaying'; | ||
export { default as Popular } from './Popular'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters