movie.api.js 2.04 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
}
Jiwon Yoon's avatar
Jiwon Yoon committed
13
const getMoviesfromTM = async (category) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
14
    console.log(category)
Jiwon Yoon's avatar
Jiwon Yoon committed
15
    const response = await axios.get(`${baseUrl}/api/movie/showmovies/${category}`)
Jiwon Yoon's avatar
Jiwon Yoon committed
16
    console.log(response.data)
Jiwon Yoon's avatar
Jiwon Yoon committed
17
    return response.data
Jiwon Yoon's avatar
Jiwon Yoon committed
18
19
20
}
const getMovieInfofromTM = async (id) => {
    const movieId = id
Jiwon Yoon's avatar
Jiwon Yoon committed
21
22
23
    const response = await axios.get(`${TMDBUrl}/${movieId}?api_key=${process.env.REACT_APP_TMDB_API_KEY}&language=ko-KR`)
    console.log(response.data)
    return response.data
Jiwon Yoon's avatar
Jiwon Yoon committed
24
}
Jiwon Yoon's avatar
Jiwon Yoon committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
}
const getCreditsfromTM = async (id) =>{
    const movieId = id
    const response = await axios.get(`${TMDBUrl}/${movieId}/credits?api_key=${process.env.REACT_APP_TMDB_API_KEY}`)
    return response.data
}

const getVideosfromTM = async (id) =>{
    const movieId = id
    const response = await axios.get(`${TMDBUrl}/${movieId}/videos?api_key=${process.env.REACT_APP_TMDB_API_KEY}`)
    return response.data.results
}

42
43
const submit = async (movieId) => {
    const { data } = await axios.post(`${baseUrl}/api/movie/${movieId}`)
Jiwon Yoon's avatar
Jiwon Yoon committed
44
    console.log("data==", data)
45
46
}

Kim, Subin's avatar
Kim, Subin committed
47
48
49
50
51
const remove = async (movieId) => {
    const { data } = await axios.delete(`${baseUrl}/api/movie/${movieId}`)
    return data
}

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

const movieApi = {
Kim, Subin's avatar
Kim, Subin committed
63
    getAllfromTM,
Jiwon Yoon's avatar
Jiwon Yoon committed
64
65
    getMoviesfromTM,
    getMovieInfofromTM,
Jiwon Yoon's avatar
Jiwon Yoon committed
66
67
68
    getImagesfromTM,
    getCreditsfromTM,
    getVideosfromTM,
Kim, Subin's avatar
Kim, Subin committed
69
70
    submit,
    remove,
Jiwon Yoon's avatar
Jiwon Yoon committed
71
    search,
72
73
74
}

export default movieApi