-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
100 lines (86 loc) · 2.58 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const API_KEY = "a721dd910292becd0d78ed436463db21";
const BASE_URL = "https://api.themoviedb.org/3";
export interface Movie {
adult: boolean;
backdrop_path: string | null;
genre_ids: Array<number>;
id: number;
original_language: string;
original_title: string;
overview: string;
popularity: number;
poster_path: string | null;
release_date: string;
title: string;
video: boolean;
vote_average: number;
vote_count: number;
}
interface BaseResponse {
page: number;
total_results: number;
total_pages: number;
}
export interface MovieResponse extends BaseResponse {
results: Movie[];
}
// movieApi
const nowPlaying = () =>
fetch(
`${BASE_URL}/movie/now_playing?api_key=${API_KEY}&language=ko&page=1`
).then((res) => res.json());
const upcoming = ({ pageParam }: any) =>
fetch(
`${BASE_URL}/movie/upcoming?api_key=${API_KEY}&language=ko&page=${pageParam}`
).then((res) => res.json());
const trendingMovie = () =>
fetch(`${BASE_URL}/trending/movie/week?api_key=${API_KEY}&language=ko`).then(
(res) => res.json()
);
// tvApi
const airingToday = () =>
fetch(
`${BASE_URL}/tv/airing_today?api_key=${API_KEY}&language=ko&page=1`
).then((res) => res.json());
const topRated = () =>
fetch(`${BASE_URL}/tv/top_rated?api_key=${API_KEY}&language=ko&page=1`).then(
(res) => res.json()
);
const trendingTv = () =>
fetch(
`${BASE_URL}/trending/tv/week?api_key=${API_KEY}&language=ko&page=1`
).then((res) => res.json());
// searchApi
const movies = ({ queryKey }) => {
const query = queryKey[1];
return fetch(
`${BASE_URL}/search/movie?api_key=${API_KEY}&language=ko&query=${query}&include_adult=false`
).then((res) => res.json());
};
const tvs = ({ queryKey }) => {
const query = queryKey[1];
return fetch(
`${BASE_URL}/search/tv?api_key=${API_KEY}&language=ko&query=${query}&include_adult=false`
).then((res) => res.json());
};
// detailApi
const movieDetail = ({ queryKey }) => {
const id = queryKey[1];
return fetch(
`${BASE_URL}/movie/${id}?api_key=${API_KEY}&language=ko&include_adult=false&append_to_response=videos,images`
).then((res) => res.json());
};
const tvDetail = ({ queryKey }) => {
const id = queryKey[1];
return fetch(
`${BASE_URL}/tv/${id}?api_key=${API_KEY}&language=ko&include_adult=false&append_to_response=videos,images`
).then((res) => res.json());
};
export const moivesApi = { nowPlaying, upcoming, trending: trendingMovie };
export const tvApi = {
airingToday,
topRated,
trending: trendingTv,
};
export const searchApi = { movies, tvs };
export const detailApi = { movieDetail, tvDetail };