movie.api.js 2.08 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
}
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

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
}

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
const getListfromDB = async () => {
    const { data } = await axios.get(`${baseUrl}/api/movie`)
    return data
}
42
43
44
45
const getListByCategoryfromDB = async (category) => {
    const { data } = await axios.get(`${baseUrl}/api/movie/movielist/${category}`)
    return data
}
46
47
const submit = async (movieId) => {
    const { data } = await axios.post(`${baseUrl}/api/movie/${movieId}`)
48
    return data
49
50
}

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

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

const movieApi = {
Kim, Subin's avatar
Kim, Subin committed
67
    getAllfromTM,
68
    getListByCategoryfromDB,
Jiwon Yoon's avatar
Jiwon Yoon committed
69
    getMovieInfofromTM,
Jiwon Yoon's avatar
Jiwon Yoon committed
70
71
72
    getImagesfromTM,
    getCreditsfromTM,
    getVideosfromTM,
73
    getListfromDB,
Kim, Subin's avatar
Kim, Subin committed
74
75
    submit,
    remove,
Jiwon Yoon's avatar
Jiwon Yoon committed
76
    search,
77
78
79
}

export default movieApi