diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Pets/PetRequestDTO.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Pets/PetRequestDTO.java index 3e2df1e18e..4705b91f05 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Pets/PetRequestDTO.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Pets/PetRequestDTO.java @@ -20,5 +20,5 @@ public class PetRequestDTO { private String petTypeId; //private String photoId; private String isActive; - + private String weight; } diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Pets/PetResponseDTO.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Pets/PetResponseDTO.java index 847825f2eb..e3aad3c8b4 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Pets/PetResponseDTO.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Pets/PetResponseDTO.java @@ -24,7 +24,7 @@ public class PetResponseDTO { private String petTypeId; //private String photoId; private String isActive; - + private String weight; //private final List visits = new ArrayList<>(); diff --git a/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.controller.js b/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.controller.js index 8032b818ba..65fe669044 100755 --- a/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.controller.js +++ b/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.controller.js @@ -12,6 +12,24 @@ function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $ vm.pets = []; // Function to get pet type name based on petTypeId + /* vm.getPetTypeName = function (petTypeId) { + switch (petTypeId) { + case '1': + return 'Cat'; + case '2': + return 'Dog'; + case '3': + return 'Lizard'; + case '4': + return 'Snake'; + case '5': + return 'Bird'; + case '6': + return 'Hamster'; + default: + return 'Unknown'; + } + };*/ vm.getBirthday = function(birthday) { @@ -32,6 +50,11 @@ function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $ .then(function (resp) { vm.owner = resp.data; console.log(vm.owner); + + vm.owner.pets.forEach(function (pet) { + pet.isActive = pet.isActive === "true"; + }); + }) .catch(function (error) { console.error('Error fetching owner data:', error); @@ -88,5 +111,76 @@ function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $ console.error('Error fetching pet data:', error); }); -} + + // Toggle pet's active status + vm.toggleActiveStatus = function (petId) { + return $http.get('api/gateway/pets/' + petId + '?_=' + new Date().getTime(), {headers: {'Cache-Control': 'no-cache'}}) + .then(function (resp) { + console.log("Pet id is " + petId); + console.log(resp.data); + vm.pet = resp.data; + console.log("Pet id is " + vm.pet.petId); + console.log(vm.pet); + console.log("====================================="); + console.log(resp.data); + console.log("Active status before is:" + vm.pet.isActive); + vm.pet.isActive = vm.pet.isActive === "true" ? "false" : "true"; + console.log("Active status after is:" + vm.pet.isActive); + + return $http.patch('api/gateway/pet/' + petId, { + isActive: vm.pet.isActive + }, {headers: {'Cache-Control': 'no-cache'}}); + }) + .then(function (resp) { + console.log("Pet active status updated successfully"); + vm.pet = resp.data; + // Schedule a function to be executed during the next digest cycle + $scope.$evalAsync(); + }) + .catch(function (error) { + console.error("Error updating pet active status:", error); + // Handle the error appropriately + }); + }; + + + // Watch the pet.isActive property + $scope.$watch('pet.isActive', function (newVal, oldVal) { + if (newVal !== oldVal) { + // The pet.isActive property has changed, update the UI + $scope.$apply(); + } + }); + + + vm.deletePet = function (petId) { + var config = { + headers: { + 'Content-Type': 'application/json' + } + }; + + $http.delete('api/gateway/pets/' + petId, config) + .then(function (resp) { + console.log("Pet deleted successfully"); + + /* $http.get('api/gateway/owners/' + $stateParams.ownerId).then(function (resp) { + self.owner = resp.data; + }); + */ + + vm.owner.pets = vm.owner.pets.filter(function (pet) { + return pet.petId !== petId; + }); + + $scope.$applyAsync(); + // Handle the success appropriately + }).catch(function (error) { + console.error("Error deleting pet:", error); + // Handle the error appropriately + }); + }; +}; + + diff --git a/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.template.html b/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.template.html index 4da0135119..fac26c3128 100644 --- a/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.template.html +++ b/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.template.html @@ -80,6 +80,7 @@

Pets

+

({{$ctrl.getPetTypeName(pet.petTypeId)}}) - {{pet.name}}
diff --git a/api-gateway/src/main/resources/static/scripts/pet-details/pet-details.template.html b/api-gateway/src/main/resources/static/scripts/pet-details/pet-details.template.html index 6a90246f42..6fc1692c8d 100644 --- a/api-gateway/src/main/resources/static/scripts/pet-details/pet-details.template.html +++ b/api-gateway/src/main/resources/static/scripts/pet-details/pet-details.template.html @@ -40,6 +40,10 @@

No pet found

+
+ + +
diff --git a/api-gateway/src/main/resources/static/scripts/pet-form/pet-form.controller.js b/api-gateway/src/main/resources/static/scripts/pet-form/pet-form.controller.js index e7d70be31d..713fc04ba2 100755 --- a/api-gateway/src/main/resources/static/scripts/pet-form/pet-form.controller.js +++ b/api-gateway/src/main/resources/static/scripts/pet-form/pet-form.controller.js @@ -24,8 +24,7 @@ angular.module('petForm') return 'Unknown'; } }; - - // Clear the form fields + // Clear the form fields self.pet = {}; // Changed $ctrl.pet to self.pet $http.get('api/gateway/owners/petTypes').then(function (resp) { @@ -68,13 +67,16 @@ angular.module('petForm') if (confirm("Are you sure you want to submit this form with the following details?\n\n" + "Pet Name: " + self.pet.name + "\n" + "Pet Birth Date: " + formattedBirthDate + "\n" + + "Weight: " + self.pet.weight + " KG" + "\n" + "Pet Type: " + petTypeName)) { var data = { petId: self.pet.petId, name: self.pet.name, birthDate: new Date(self.pet.birthDate).toISOString(), ownerId: self.pet.ownerId, - petTypeId: self.pet.petTypeId + petTypeId: self.pet.petTypeId, + weight: self.pet.weight, + isActive: self.pet.isActive }; var req; diff --git a/api-gateway/src/main/resources/static/scripts/pet-form/pet-form.template.html b/api-gateway/src/main/resources/static/scripts/pet-form/pet-form.template.html index 3715534d44..f039455c82 100755 --- a/api-gateway/src/main/resources/static/scripts/pet-form/pet-form.template.html +++ b/api-gateway/src/main/resources/static/scripts/pet-form/pet-form.template.html @@ -17,7 +17,7 @@
- +
birth date is required. @@ -25,6 +25,14 @@
+
+ +
+ + Weight is required. +
+
+