12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- (function() {
- 'use strict';
- app.factory('books.repository', ['webApi', '$http', function(webApi, $http) {
- return {
- getBooks: _getBooks,
- getBookById: _getBookById,
- getAuthors: _getAuthors,
- updateBookById: _updateBookById,
- addBook: _addBook,
- deleteBook: _deleteBook,
- searchBy: _searchBy,
- updateAuthorsById: _updateAuthorsById,
- addAuthor: _addAuthor,
- deleteAuthorById: _deleteAuthorById
- };
- function _getBooks() {
- return $http.get(webApi.DOMAIN + '/api/v2/books');
- };
- function _getBookById(id) {
- return $http.get(webApi.DOMAIN + '/api/v2/books/' + id);
- };
- function _getAuthors() {
- return $http.get(webApi.DOMAIN + '/api/v2/authors');
- };
- function _updateBookById(id, book) {
- return $http.put(webApi.DOMAIN + '/api/v2/books/' + id, book);
- };
- function _addBook(data){
- return $http.post(webApi.DOMAIN + '/api/v2/books', data);
- }
- function _deleteBook(id){
- return $http.delete(webApi.DOMAIN + '/api/v2/books/' + id);
- }
- function _searchBy(string){
- return $http.get(webApi.DOMAIN + '/api/v2/search?string=' + string);
- }
- function _updateAuthorsById(data, id){
- return $http.put(webApi.DOMAIN + '/api/v2/authors/' + id, data);
- }
- function _addAuthor(data){
- return $http.post(webApi.DOMAIN + '/api/v2/authors' , data);
- }
- function _deleteAuthorById(id){
- return $http.delete(webApi.DOMAIN + '/api/v2/authors/' + id);
- }
- }]);
- })();
|