Last active
February 4, 2016 19:44
-
-
Save brunoksato/762c705925c1834811bd to your computer and use it in GitHub Desktop.
factory.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular | |
.module('pub.posts.service', []) | |
.factory('PostsService', PostsService); | |
/** @ngInject */ | |
function PostsService($http, $q, API) { | |
function list(parentId){ | |
var defered = $q.defer(); | |
$http.get(API.API_URL + 'publisher/channels/' + parentId + '/channel_posts') | |
.success(defered.resolve) | |
.error(defered.reject); | |
return defered.promise; | |
} | |
function get(parentId, id){ | |
var defered = $q.defer(); | |
$http.get(API.API_URL + 'publisher/channel_posts/' + id) | |
.success(defered.resolve) | |
.error(defered.reject); | |
return defered.promise; | |
} | |
function save(parentId, model){ | |
var defered = $q.defer(); | |
$http.post(API.API_URL + 'publisher/channels/' + parentId + '/channel_posts', model) | |
.success(defered.resolve) | |
.error(defered.reject); | |
return defered.promise; | |
} | |
function update(parentId, id, model){ | |
var defered = $q.defer(); | |
$http.put(API.API_URL + 'publisher/channels/' + parentId + '/channel_posts/' + id, model) | |
.success(defered.resolve) | |
.error(defered.reject); | |
return defered.promise; | |
} | |
function remove(parentId, id){ | |
var defered = $q.defer(); | |
$http.delete(API.API_URL + 'publisher/channels/' + parentId + '/channel_posts/' + id) | |
.success(defered.resolve) | |
.error(defered.reject); | |
return defered.promise; | |
} | |
return{ | |
list: list, | |
get: get, | |
save: save, | |
update: update, | |
remove: remove | |
}; | |
} | |
})(); | |
(function() { | |
'use strict'; | |
angular | |
.module('pub.post', [ | |
'pub.posts.service' | |
]) | |
.controller('PostsCtrl', PostsCtrl); | |
/** @ngInject */ | |
function PostsCtrl($stateParams, PostsService) { | |
var vm = this; | |
vm.items = []; | |
PostsService.list($stateParams.parentId).then(function(result){ | |
vm.items = result; | |
}, function(err) { | |
console.log(err); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment