movie.api.js 2.23 KB
Newer Older
1
import axios from "axios";
Jiwon Yoon's avatar
Jiwon Yoon committed
2
import { baseUrl, TMDBUrl } from "../utils/baseUrl.js";
3

Kim, Subin's avatar
Kim, Subin committed
4
5
6
7
8
9
10
11
const getAllfromTM = async () => {
    const payload = {
        params: {
            pageNum: 1
        }
    }
    const { data } = await axios.get(`${baseUrl}/api/movie/all`, payload)
    return data
12
}
한규민's avatar
한규민 committed
13
14
15
16
const getMovieIdfromTM = async (movieId) => {
    const { data } = await axios.get(`${baseUrl}/api/movie/${movieId}`)
    return data
}
Jiwon Yoon's avatar
Jiwon Yoon committed
17
18
const getMovieInfofromTM = async (id) => {
    const movieId = id
Jiwon Yoon's avatar
Jiwon Yoon committed
19
20
    const response = await axios.get(`${TMDBUrl}/${movieId}?api_key=${process.env.REACT_APP_TMDB_API_KEY}&language=ko-KR`)
    return response.data
Jiwon Yoon's avatar
Jiwon Yoon committed
21
}
22

Jiwon Yoon's avatar
Jiwon Yoon committed
23
24
25
26
27
const getImagesfromTM = async (id) => {
    const movieId = id
    const response = await axios.get(`${TMDBUrl}/${movieId}/images?api_key=${process.env.REACT_APP_TMDB_API_KEY}`)
    return response.data
}
28

29
const getCreditsfromTM = async (id) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
30
31
32
33
34
    const movieId = id
    const response = await axios.get(`${TMDBUrl}/${movieId}/credits?api_key=${process.env.REACT_APP_TMDB_API_KEY}`)
    return response.data
}

35
const getVideosfromTM = async (id) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
36
37
38
39
40
    const movieId = id
    const response = await axios.get(`${TMDBUrl}/${movieId}/videos?api_key=${process.env.REACT_APP_TMDB_API_KEY}`)
    return response.data.results
}

41
42
43
44
const getListfromDB = async () => {
    const { data } = await axios.get(`${baseUrl}/api/movie`)
    return data
}
45
46
47
48
const getListByCategoryfromDB = async (category) => {
    const { data } = await axios.get(`${baseUrl}/api/movie/movielist/${category}`)
    return data
}
49
50
const submit = async (movieId) => {
    const { data } = await axios.post(`${baseUrl}/api/movie/${movieId}`)
51
    return data
52
53
}

Kim, Subin's avatar
Kim, Subin committed
54
55
56
57
58
const remove = async (movieId) => {
    const { data } = await axios.delete(`${baseUrl}/api/movie/${movieId}`)
    return data
}

Kim, Subin's avatar
Kim, Subin committed
59
const search = async ({ type, keyword }) => {
Kim, Subin's avatar
Kim, Subin committed
60
61
    const payload = {
        params: {
Kim, Subin's avatar
Kim, Subin committed
62
            keyword
Kim, Subin's avatar
Kim, Subin committed
63
64
        }
    }
Kim, Subin's avatar
Kim, Subin committed
65
    const { data } = await axios.get(`${baseUrl}/api/movie/search/${type}`, payload)
Kim, Subin's avatar
Kim, Subin committed
66
    return data
67
68
69
}

const movieApi = {
Kim, Subin's avatar
Kim, Subin committed
70
    getAllfromTM,
71
    getListByCategoryfromDB,
Jiwon Yoon's avatar
Jiwon Yoon committed
72
    getMovieInfofromTM,
Jiwon Yoon's avatar
Jiwon Yoon committed
73
74
75
    getImagesfromTM,
    getCreditsfromTM,
    getVideosfromTM,
76
    getListfromDB,
한규민's avatar
한규민 committed
77
    getMovieIdfromTM,
Kim, Subin's avatar
Kim, Subin committed
78
79
    submit,
    remove,
Jiwon Yoon's avatar
Jiwon Yoon committed
80
    search,
81
82
83
}

export default movieApi