-
Notifications
You must be signed in to change notification settings - Fork 3
/
MovieService.js
42 lines (36 loc) · 996 Bytes
/
MovieService.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import API from './config';
const MOVIES_ENDPOINTS = {
LIST_MOVIES: "list_movies.json", //URI para llamar a todas las peliculas
MOVIE_DETAIL: "movie_details.json?movie_id=" //URI para llamar a una pelicula en especifico.
}
const MovieService = { //Objeto Movie Service
getAll: () => new Promise(
(resolve,reject) => {
API.get(MOVIES_ENDPOINTS.LIST_MOVIES)
.then(
res => res.data.data.movies
)
.then(
data => resolve(data)
)
.catch(
err => reject(err)
)
}
), // Funcion que nos devolverá el valor de todas las peliculas
get: (id) => new Promise(
(resolve,reject) => {
API.get(MOVIES_ENDPOINTS.MOVIE_DETAIL+id)
.then(
res => res.data.data.movie
)
.then(
data => resolve(data)
)
.catch(
err => reject(err)
)
}
), //Funcion que nos devolverá el valor de una pelicula, la cual buscaremos via ID.
}
export default MovieService;