angular.module('bookstore.services', [])
.factory('Auth', function($http, $window) {
  var signup = function(data) {
    return $http({
      method: 'POST',
      url: '/api/users',
      data: JSON.stringify(data),
      ContentType: 'application/json'
    })
    .then(function(res) {
      return res.data.token;
    })
  };
  var signin = function(data) {
    return $http({
      method: 'POST',
      url: '/auth/signin' ,
      data: data,
      headers: $window.localStorage.getItem('access_token'),
      ContentType: 'application/json'
    })
    .then(function(res) {
      return res.data;
    });
  };
  var me = function(token) {
    return $http({
      method: 'GET',
      url: '/api/users/me',
      params: {access_token: token},
      ContentType: 'application/json'
    })
    .then(function(res) {
      return res.data;
    });
  };
  var removeBook = function(bookId) {
    return $http({
      method: 'DELETE',
      url: '/api/books/' + bookId,
      params: {access_token: $window.localStorage.getItem('access_token')},
      ContentType: 'application/json'
    })
    .then(function(res) {
      return res.data;
    });
  };
  return {
    signup: signup,
    signin: signin,
    me: me,
    removeBook: removeBook
  }
})
.factory('Landing', function($http, $window) {
  var getBooks = function(search, index) {
    return $http({
      method: 'GET',
      url: 'https://www.googleapis.com/books/v1/volumes?q=' + search + '&printType=books&orderBy=relevance&filter=ebooks&maxResults=40&startIndex=' + index
    })
    .then(function(res) {
      return res.data;
    });
  };
  var saveBook = function(book) {
    return $http({
      method: 'POST',
      url: 'api/books',
      data: JSON.stringify(book),
      ContentType: 'application/json',
      params: {access_token: $window.localStorage.getItem('access_token')}
    })
    .then(function(res) {
      return res.data;
    });
  };

  return {
    getBooks: getBooks,
    saveBook: saveBook
  }
})
.factory('Shelf', function($http, $window) {
  var getShelf = function(userId) {
    return $http({
      method: 'GET',
      url: 'api/books/',
      params: {userId: userId, access_token: $window.localStorage.getItem('access_token')},
      ContentType: 'application/json'
    })
    .then(function(res) {
      return res.data;
    });
  };
  var sendToken = function(data) {
    return $http({
      method: 'POST',
      url: '/payment',
      data: data,
      ContentType: 'application/json'
    })
    .then(function(res) {
      console.log(res.data);
      return res.data;
    });
  };

  return {
    getShelf: getShelf,
    sendToken: sendToken
  };
})
.factory('Details', function($http) {
  var bookInfo = function(id) {
    return $http({
      method: 'GET',
      url: 'api/books/' + id,
      ContentType: 'application/json'
    })
    .then(function(res) {
      return res.data;
    });
  }

  return {
    bookInfo: bookInfo
  }
});
@@ -882,18 +882,16 @@
 ion(book
-Id
 ) %7B%0A    
@@ -960,17 +960,19 @@
 ' + book
-I
+._i
 d,%0A     
@@ -2324,24 +2324,390 @@
    %7D);%0A  %7D;%0A
+  var updateBook = function(bookId, data) %7B%0A    return $http(%7B%0A      method: 'PUT',%0A      url: 'api/books/' + bookId,%0A      params: %7Baccess_token: $window.localStorage.getItem('access_token')%7D,%0A      ContentType: 'application/json',%0A      data: JSON.stringify(data)%0A    %7D)%0A    .then(function(res) %7B%0A      //console.log(res.data);%0A      return res.data;%0A    %7D);%0A  %7D;%0A
   var sendTo
@@ -3007,16 +3007,44 @@
 endToken
+,%0A    updateBook: updateBook
 %0A  %7D;%0A%7D)

add service for updating book with multiple copies in cart