-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug(CSTM-CPC-879): fix pet edit to edit all values (#538)
JIRA: [link to jira ticket](https://champlainsaintlambert.atlassian.net/browse/CPC-879) ## Context: Making It so the customer can edit the Name, Birthdate, and Pet Type. Previously you could only change the name. ## Changes - Fixed Bug where the pet info in the form would dissapear - Added birthdate and pet type to owner details - Made birthdate and pet type editable ## Before and After UI (Required for UI-impacting PRs) <img width="1440" alt="image" src="https://github.com/cgerard321/champlain_petclinic/assets/40618145/8bd0dae3-3f67-4342-8417-4937cda94c1c"> <img width="1440" alt="2" src="https://github.com/cgerard321/champlain_petclinic/assets/40618145/ab9498a5-8177-4096-b546-93b65c3ae690"> --------- Co-authored-by: Eduardo J.C <[email protected]>
- Loading branch information
1 parent
bc760ba
commit 2885fa5
Showing
4 changed files
with
96 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 30 additions & 44 deletions
74
api-gateway/src/main/resources/static/scripts/pet-form/pet-form.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,49 @@ | ||
'use strict'; | ||
|
||
angular.module('petForm') | ||
.controller('PetFormController', ['$http', '$state', '$stateParams', function ($http, $state, $stateParams) { | ||
.controller('PetFormController', ['$http', '$state', '$stateParams', '$filter', '$q', function ($http, $state, $stateParams, $filter, $q) { | ||
var self = this; | ||
var ownerId = $stateParams.ownerId || 0; | ||
var method = $stateParams.method; | ||
var petId = $stateParams.petId || 0; | ||
var owner = ""; | ||
var myDate = new Date(); | ||
|
||
$http.get('api/gateway/owners/petTypes').then(function (resp) { | ||
self.types = resp.data; | ||
}); | ||
|
||
$http.get('api/gateway/pets/' + petId).then(function (resp) { | ||
self.pet = resp.data; | ||
$http.get('api/gateway/owners/petTypes') | ||
.then(function (resp) { | ||
self.types = resp.data; | ||
}); | ||
|
||
}); | ||
$q.all([ | ||
$http.get('api/gateway/pets/' + petId), | ||
$http.get('api/gateway/owners/' + ownerId) | ||
]).then(function (responses) { | ||
var petData = responses[0].data; | ||
petData.birthDate = new Date(petData.birthDate); | ||
|
||
$http.get('api/gateway/owners/' + ownerId).then(function (resp) { | ||
var ownerData = resp.data; | ||
owner = ownerData.firstName + " " + ownerData.lastName; | ||
self.pet = { | ||
owner: owner | ||
} | ||
var ownerData = responses[1].data; | ||
petData.owner = ownerData.firstName + " " + ownerData.lastName; | ||
|
||
self.pet = petData; | ||
self.checked = false; | ||
}); | ||
|
||
|
||
// Function to submit the form | ||
self.submit = function () { | ||
var petType = { | ||
id: self.pet.type.id, | ||
name: self.pet.type.name | ||
} | ||
|
||
var data = { | ||
petId: self.pet.petId, | ||
name: self.pet.name, | ||
birthDate: self.pet.birthDate, | ||
birthDate: new Date(self.pet.birthDate).toISOString(), | ||
ownerId: self.pet.ownerId, | ||
type: petType | ||
} | ||
|
||
|
||
var req; | ||
|
||
|
||
req = $http.put("api/gateway/" + "pets/" + petId, data); | ||
|
||
req.then(function () { | ||
$state.go('ownerDetails', { ownerId: ownerId }); | ||
}, function (response) { | ||
var error = response.data; | ||
error.errors = error.errors || []; | ||
alert(error.error + "\r\n" + error.errors.map(function (e) { | ||
return e.field + ": " + e.defaultMessage; | ||
}).join("\r\n")); | ||
}); | ||
petTypeId: self.pet.petTypeId | ||
}; | ||
|
||
$http.put("api/gateway/pets/" + petId, data) | ||
.then(function () { | ||
$state.go('ownerDetails', { ownerId: ownerId }); | ||
}, function (response) { | ||
var error = response.data; | ||
error.errors = error.errors || []; | ||
alert(error.error + "\r\n" + error.errors.map(function (e) { | ||
return e.field + ": " + e.defaultMessage; | ||
}).join("\r\n")); | ||
}); | ||
}; | ||
}]); | ||
}]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters