Commit 0fec1cc5 authored by Iago Gómez Salgado's avatar Iago Gómez Salgado

Added frontend PetDAO

parent 9b577e37
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment