books.factory.js 877 B

123456789101112131415161718192021222324252627282930313233343536
  1. (function() {
  2. 'use strict';
  3. app.factory('books.repository', ['webApi', '$http', function(webApi, $http) {
  4. return {
  5. getBooks: _getBooks,
  6. getBookById: _getBookById,
  7. getAuthors: _getAuthors,
  8. updateBookById: _updateBookById,
  9. addBook: _addBook,
  10. deleteBook: _deleteBook
  11. };
  12. function _getBooks() {
  13. return $http.get(webApi.DOMAIN + '/api/v2/books');
  14. };
  15. function _getBookById(id) {
  16. return $http.get(webApi.DOMAIN + '/api/v2/books/' + id);
  17. };
  18. function _getAuthors() {
  19. return $http.get(webApi.DOMAIN + '/api/v2/authors');
  20. };
  21. function _updateBookById(id, book) {
  22. return $http.put(webApi.DOMAIN + '/api/v2/books/' + id, book);
  23. };
  24. function _addBook(data){
  25. return $http.post(webApi.DOMAIN + '/api/v2/books', data);
  26. }
  27. function _deleteBook(id){
  28. return $http.delete(webApi.DOMAIN + '/api/v2/books/' + id);
  29. }
  30. }]);
  31. })();