books.factory.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. searchBy: _searchBy,
  12. updateAuthorsById: _updateAuthorsById,
  13. addAuthor: _addAuthor,
  14. deleteAuthorById: _deleteAuthorById
  15. };
  16. function _getBooks() {
  17. return $http.get(webApi.DOMAIN + '/api/v2/books');
  18. };
  19. function _getBookById(id) {
  20. return $http.get(webApi.DOMAIN + '/api/v2/books/' + id);
  21. };
  22. function _getAuthors() {
  23. return $http.get(webApi.DOMAIN + '/api/v2/authors');
  24. };
  25. function _updateBookById(id, book) {
  26. return $http.put(webApi.DOMAIN + '/api/v2/books/' + id, book);
  27. };
  28. function _addBook(data){
  29. return $http.post(webApi.DOMAIN + '/api/v2/books', data);
  30. }
  31. function _deleteBook(id){
  32. return $http.delete(webApi.DOMAIN + '/api/v2/books/' + id);
  33. }
  34. function _searchBy(string){
  35. return $http.get(webApi.DOMAIN + '/api/v2/search?string=' + string);
  36. }
  37. function _updateAuthorsById(data, id){
  38. return $http.put(webApi.DOMAIN + '/api/v2/authors/' + id, data);
  39. }
  40. function _addAuthor(data){
  41. return $http.post(webApi.DOMAIN + '/api/v2/authors' , data);
  42. }
  43. function _deleteAuthorById(id){
  44. return $http.delete(webApi.DOMAIN + '/api/v2/authors/' + id);
  45. }
  46. }]);
  47. })();