Skip to content

Instantly share code, notes, and snippets.

@cristoferdomingues
Created January 24, 2017 23:53
Show Gist options
  • Save cristoferdomingues/b6c24df39fd8eee499e871c364b5b18e to your computer and use it in GitHub Desktop.
Save cristoferdomingues/b6c24df39fd8eee499e871c364b5b18e to your computer and use it in GitHub Desktop.
Angular Generic Crud
'use strict';
var crudService = angular.module('crud.service', ['app.config', 'ngResource']);
crudService.factory('CrudService', function(ENV, $resource, $schemaFormWrapper) {
return $resource(
ENV.apiEndpoint + '/senha/:crud/:entity/:param', {
crud: '@crud',
entity: '@entity',
param: '@param'
},
{
'get': { method: 'GET' },
'save': { method: 'POST' },
'update': { method: 'PUT' },
'query': {
method: 'GET',
isArray: true,
params: { crud: this.crud || 'genericcrud' },
transformResponse: function(data,header) {
var json = JSON.parse(data);
var array = json.listData;
return array;
},
transformRequest : function(data,header) {
debugger;
}
},
'remove': { method: 'DELETE' },
'loadJson': { method: 'GET',
transformResponse: function(data,header) {
return $schemaFormWrapper.translater(data);
}
}
}
);
}).config(function($httpProvider) {
$httpProvider.defaults.headers.post['Content-Type'] = 'application/json; charset=UTF-8';
});
@cristoferdomingues
Copy link
Author

Usage

CrudService.query({entity:'cadsenhacategoria'}, function (cadSenhaCategoriaRetorno) {}); -------------------------------- default
CrudService.query({crud: 'crud', entity:'cadsenhacategoria'}, function (cadSenhaCategoriaRetorno) {}); -------------------------------- especifico

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment