movie.api.js 2.11 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
const getAllfromTM = async (pageNum) => {
Kim, Subin's avatar
Kim, Subin committed
5
6
    const payload = {
        params: {
Kim, Subin's avatar
Kim, Subin committed
7
            pageNum
Kim, Subin's avatar
Kim, Subin committed
8
9
10
11
        }
    }
    const { data } = await axios.get(`${baseUrl}/api/movie/all`, payload)
    return data
12
}
13

Jiwon Yoon's avatar
Jiwon Yoon committed
14
15
const getMovieInfofromTM = async (id) => {
    const movieId = id
Jiwon Yoon's avatar
Jiwon Yoon committed
16
17
    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
18
}
19

Jiwon Yoon's avatar
Jiwon Yoon committed
20
21
22
23
24
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
}
25

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

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

38
39
40
41
42
const getListfromDB = async () => {
    const { data } = await axios.get(`${baseUrl}/api/movie`)
    return data
}

Kim, Subin's avatar
Kim, Subin committed
43
44
45
46
47
const getListByCategoryfromDB = async (category) => {
    const { data } = await axios.get(`${baseUrl}/api/movie/movielist/${category}`)
    return data
}

48
49
const submit = async (movieId) => {
    const { data } = await axios.post(`${baseUrl}/api/movie/${movieId}`)
50
    return data
51
52
}

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

Kim, Subin's avatar
Kim, Subin committed
58
const search = async ({ type, keyword }, pageNum) => {
Kim, Subin's avatar
Kim, Subin committed
59
60
    const payload = {
        params: {
Kim, Subin's avatar
Kim, Subin committed
61
62
            keyword,
            pageNum
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,
Kim, Subin's avatar
Kim, Subin committed
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,
Kim, Subin's avatar
Kim, Subin committed
77
78
    submit,
    remove,
Jiwon Yoon's avatar
Jiwon Yoon committed
79
    search,
80
81
82
}

export default movieApi