-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.js
70 lines (55 loc) · 1.47 KB
/
service.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use strict";
function MovieService($http) {
let key = "32535e85345be91dd928261c4d1d2a0e";
let movieData = {};
let movieDetailData = {};
const getInfo = (title) => {
// console.log(title);
let movieTitle = title;
return $http ({
url: "https://api.themoviedb.org/3/search/movie?api_key=" + key +"&query=" + title,
method: "GET"
}).then((response) =>{
movieData = response;
return movieData;
})
} //end of getInfo
const getDetails = (movieid) =>{
return $http ({
url: "https://api.themoviedb.org/3/movie/"+movieid+"?api_key=" + key +"&append_to_response=releases",
method: "GET"
}).then((response) =>{
movieDetailData = response;
return movieDetailData;
})
}
//Declares watchlist, function to add title
let watchList = [];
const addTitle = (id, overview, runtime, certification, vote_average, genres) =>{
let newTitle = {};
watchList.push(id, overview, runtime, certification, vote_average, genres);
return watchList;
}
//Remove title from watchlist
const removeTitle = (id) => {
// watchList.splice(index, 1);
watchList.forEach((value, index)=>{
if (value === id){
watchList.splice(index, 1);
}
})
}
const getWatchList = () =>{
return watchList;
}
return {
getInfo,
getDetails,
addTitle,
removeTitle,
getWatchList
}
}
angular
.module("app")
.factory("MovieService", MovieService)