Skip to content

Instantly share code, notes, and snippets.

@lazarofl
Created May 29, 2014 05:30
Show Gist options
  • Save lazarofl/22b644976c9d4d2ae28c to your computer and use it in GitHub Desktop.
Save lazarofl/22b644976c9d4d2ae28c to your computer and use it in GitHub Desktop.
angular.module('app').service('ComprasService', ['$http', function ($http) {
this.ObterListaDeCompras = function() {
return $http.get('/listadecompras').then(function(response) {
return response || null;
}, function(response) {
switch(response.status)
{
default:
throw 'nenhuma informação';
}
});
};
this.Adicionar = function(item) {
if(!!!item || !!!item.nome || !!!item.quantidade)
{
throw 'item não está definido';
}
return $http.post('/listadecompras', item).then(function(response) {
return response || null;
}, function(response) {
switch(response.status)
{
default:
throw 'nenhuma informação';
}
});
};
this.Atualizar = function(item) {
return $http.put('/listadecompras', item).then(function(response) {
return response || null;
}, function(response) {
switch(response.status)
{
default:
throw 'nenhuma informação';
}
});
};
this.Remover = function(item) {
return $http.delete('/listadecompras', item).then(function(response) {
return response || null;
}, function(response) {
switch(response.status)
{
default:
throw 'nenhuma informação';
}
});
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment