-
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.
WJ-18 - New: Popular movie api and parse;
WJ-18 - New: Format date and tmdb images;
- Loading branch information
Lucas Teixeira
committed
Aug 24, 2020
1 parent
7d5ae8e
commit 7440f98
Showing
8 changed files
with
121 additions
and
0 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
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,45 @@ | ||
import tmdb from 'services/api/tmdb'; | ||
|
||
import RawResponse from 'domains/Movie/api/Popular/RawResponse'; | ||
import Response from 'domains/Movie/api/Popular/Response'; | ||
import formatDate from 'shared/utils/formatDate'; | ||
import formatTmdbImage from 'shared/utils/formatTmdbImage'; | ||
|
||
const Popular = async (): Promise<Response[]> => { | ||
const response = await rawPopular(); | ||
|
||
return parseResponse(response); | ||
}; | ||
|
||
export const rawPopular = async (): Promise<RawResponse[]> => { | ||
const response = await tmdb.get('/movie/popular'); | ||
|
||
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default interface FormatDate { | ||
value?: string; | ||
} |
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,6 @@ | ||
import TmdbImageSize from 'shared/utils/enums/TmdbImageSize'; | ||
|
||
export default interface FormatTmdbImage { | ||
value?: string; | ||
size?: TmdbImageSize; | ||
} |
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,8 @@ | ||
enum TmdbImageSize { | ||
SMALL = 'w300', | ||
MEDIUM = 'w780', | ||
LARGE = 'w1280', | ||
ORIGINAL = 'original', | ||
} | ||
|
||
export default TmdbImageSize; |
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,16 @@ | ||
import FormatDate from 'shared/utils/dtos/FormatDate'; | ||
|
||
const formatDate = ({ value }: FormatDate): string => { | ||
if (!value) { | ||
return '-'; | ||
} | ||
|
||
const date = new Date(value); | ||
date.setDate(date.getDate() + 1); | ||
|
||
const formattedDate = Intl.DateTimeFormat('pt-BR').format(date); | ||
|
||
return formattedDate; | ||
}; | ||
|
||
export default formatDate; |
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 @@ | ||
import FormatTmdbImage from 'shared/utils/dtos/FormatTmdbImage'; | ||
import TmdbImageSize from 'shared/utils/enums/TmdbImageSize'; | ||
|
||
const formatTmdbImage = ({ | ||
value, | ||
size = TmdbImageSize.MEDIUM, | ||
}: FormatTmdbImage): string | null => { | ||
if (!value) { | ||
return null; | ||
} | ||
|
||
return `${process.env.REACT_APP_TMDB_IMAGE_URL}/${size}${value}`; | ||
}; | ||
|
||
export default formatTmdbImage; |