diff --git a/src/main/webapp/js/dao/pets.js b/src/main/webapp/js/dao/pets.js new file mode 100644 index 0000000000000000000000000000000000000000..72c3d2b72e55e67dc60aa77eab674c96b602466f --- /dev/null +++ b/src/main/webapp/js/dao/pets.js @@ -0,0 +1,54 @@ +var PetsDAO = (function() { + var resourcePath = "rest/pets/"; + var requestByAjax = function(data, done, fail, always) { + done = typeof done !== 'undefined' ? done : function() {}; + fail = typeof fail !== 'undefined' ? fail : function() {}; + always = typeof always !== 'undefined' ? always : function() {}; + + $.ajax(data) + .done(done) + .fail(fail) + .always(always); + }; + + function PetsDAO() { + this.listPets = function(done, fail, always) { + requestByAjax({ + url: resourcePath, + type: 'GET' + }, done, fail, always); + }; + + this.listPeoplePets = function(id, done, fail, always) { + requestByAjax({ + url: "rest/people/" + id + "/pets/", + type: 'GET' + }, done, fail, always) + }; + + this.addPet = function(pet, done, fail, always) { + requestByAjax({ + url: resourcePath, + type: 'POST', + data: pet + }, done, fail, always); + }; + + this.modifyPet = function(pet, done, fail, always) { + requestByAjax({ + url: resourcePath + pet.id, + type: 'PUT', + data: pet + }, done, fail, always); + }; + + this.deletePet = function(id, done, fail, always) { + requestByAjax({ + url: resourcePath + id, + type: 'DELETE', + }, done, fail, always); + }; + } + + return PetDAO; +})(); \ No newline at end of file