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
4


Kim, Subin's avatar
Kim, Subin committed
5
6
7
8
9
10
11
12
const getAllfromTM = async () => {
    const payload = {
        params: {
            pageNum: 1
        }
    }
    const { data } = await axios.get(`${baseUrl}/api/movie/all`, payload)
    return data
13
}
Jiwon Yoon's avatar
Jiwon Yoon committed
14
const getMoviesfromTM = async (category) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
15
    console.log(category)
Jiwon Yoon's avatar
Jiwon Yoon committed
16
    const response = await axios.get(`${baseUrl}/api/movie/showmovies/${category}`)
Jiwon Yoon's avatar
Jiwon Yoon committed
17
    console.log(response.data)
Jiwon Yoon's avatar
Jiwon Yoon committed
18
    return response.data
Jiwon Yoon's avatar
Jiwon Yoon committed
19
20
21
}
const getMovieInfofromTM = async (id) => {
    const movieId = id
Jiwon Yoon's avatar
Jiwon Yoon committed
22
23
24
    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
25
}
Jiwon Yoon's avatar
Jiwon Yoon committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
}

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

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

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

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

export default movieApi