From bea1ef7a9feb5064b3f775a8f469ae08ef7201fc Mon Sep 17 00:00:00 2001 From: "osgonzalez@esei.uvigo.es" Date: Thu, 15 Mar 2018 19:50:50 +0100 Subject: [PATCH] Add dao/pet.js and view pet.js --- src/main/webapp/js/dao/pet.js | 47 +++++++++++++++++++ src/main/webapp/js/view/pet.js | 0 .../uvigo/esei/daa/rest/PetResourceTest.java | 1 - 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/webapp/js/dao/pet.js create mode 100644 src/main/webapp/js/view/pet.js diff --git a/src/main/webapp/js/dao/pet.js b/src/main/webapp/js/dao/pet.js new file mode 100644 index 0000000..6aa9dad --- /dev/null +++ b/src/main/webapp/js/dao/pet.js @@ -0,0 +1,47 @@ +var PetDAO = (function() { + var resourcePath = "rest/pet/"; + 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 PetDAO() { + this.listPet = function(done, fail, always) { + requestByAjax({ + url: resourcePath, + 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 diff --git a/src/main/webapp/js/view/pet.js b/src/main/webapp/js/view/pet.js new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/es/uvigo/esei/daa/rest/PetResourceTest.java b/src/test/java/es/uvigo/esei/daa/rest/PetResourceTest.java index 09349df..1ef6a2e 100644 --- a/src/test/java/es/uvigo/esei/daa/rest/PetResourceTest.java +++ b/src/test/java/es/uvigo/esei/daa/rest/PetResourceTest.java @@ -36,7 +36,6 @@ import com.github.springtestdbunit.annotation.ExpectedDatabase; import es.uvigo.esei.daa.DAAExampleApplication; import es.uvigo.esei.daa.entities.Pet; -import es.uvigo.esei.daa.entities.Pet; import es.uvigo.esei.daa.listeners.ApplicationContextBinding; import es.uvigo.esei.daa.listeners.ApplicationContextJndiBindingTestExecutionListener; import es.uvigo.esei.daa.listeners.DbManagement; -- 2.18.1