diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/CustomersServiceClient.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/CustomersServiceClient.java index 4cda73203f..d1f0b14c52 100755 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/CustomersServiceClient.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/CustomersServiceClient.java @@ -140,14 +140,14 @@ public Mono getPet(final String ownerId, final String petId) { public Flux getPetsByOwnerId(final String ownerId) { return webClientBuilder.build().get() - .uri(customersServiceUrl + "/pet/owner/" + ownerId + "/pets") + .uri(customersServiceUrl + "/pet/owner/" + ownerId) .retrieve() .bodyToFlux(PetResponseDTO.class); } public Mono createPet(PetResponseDTO model, final String ownerId) { return webClientBuilder.build().post() - .uri(customersServiceUrl + "{ownerId}/pets", ownerId) + .uri(customersServiceUrl + "/pet", ownerId) .body(just(model), PetResponseDTO.class) .accept(MediaType.APPLICATION_JSON) .retrieve().bodyToMono(PetResponseDTO.class); 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 f07d99ea48..3e2df1e18e 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 @@ -18,7 +18,7 @@ public class PetRequestDTO { private String name; private Date birthDate; private String petTypeId; - private String photoId; + //private String photoId; private String isActive; } 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 dcbc46ee2f..847825f2eb 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 @@ -22,7 +22,7 @@ public class PetResponseDTO { private String name; private Date birthDate; private String petTypeId; - private String photoId; + //private String photoId; private String isActive; diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java index b10ec36fe3..f9f1a8377c 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java @@ -147,7 +147,7 @@ public Mono> deleteBillsByCustomerId(final @PathVariable St @IsUserSpecific(idToMatch = {"customerId"}, bypassRoles = {Roles.ADMIN,Roles.VET}) - @PostMapping(value = "owners/{ownerId}/pets" , produces = "application/json", consumes = "application/json") + @PostMapping(value = "/owners/{ownerId}/pets" , produces = "application/json", consumes = "application/json") public Mono> createPet(@RequestBody PetResponseDTO pet, @PathVariable String ownerId){ return customersServiceClient.createPet(pet, ownerId).map(s -> ResponseEntity.status(HttpStatus.CREATED).body(s)) .defaultIfEmpty(ResponseEntity.badRequest().build()); diff --git a/api-gateway/src/main/resources/static/index.html b/api-gateway/src/main/resources/static/index.html index fad30e0d8e..34122ec4c2 100755 --- a/api-gateway/src/main/resources/static/index.html +++ b/api-gateway/src/main/resources/static/index.html @@ -166,6 +166,10 @@ + + + + diff --git a/api-gateway/src/main/resources/static/scripts/app.js b/api-gateway/src/main/resources/static/scripts/app.js index 7251ddeaac..e98be79bda 100644 --- a/api-gateway/src/main/resources/static/scripts/app.js +++ b/api-gateway/src/main/resources/static/scripts/app.js @@ -9,7 +9,7 @@ const whiteList = new Set([ /* App Module */ const petClinicApp = angular.module('petClinicApp', [ - 'ui.router', 'layoutNav', 'layoutFooter', 'layoutWelcome', 'ownerList', 'ownerDetails', 'ownerForm', 'ownerRegister', 'petForm' + 'ui.router', 'layoutNav', 'layoutFooter', 'layoutWelcome', 'ownerList', 'ownerDetails', 'ownerForm', 'ownerRegister', 'petRegister', 'petForm' , 'visits', 'vetList','vetForm','vetDetails', 'visitList', 'billForm', 'billUpdateForm', 'loginForm', 'rolesDetails', 'signupForm', 'billDetails', 'billsByOwnerId', 'billHistory','billsByVetId','inventoryList', 'inventoryForm', 'productForm','inventoryProductList', 'inventoryUpdateForm', 'productUpdateForm' , 'verification' , 'adminPanel','resetPwdForm','forgotPwdForm','petTypeList']); 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 d3d480b397..4f6a8789d1 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 @@ -1,81 +1,101 @@ angular.module('ownerDetails') - .controller('OwnerDetailsController', ['$http', '$state', '$stateParams', '$scope', '$timeout', '$q', function ($http, $state, $stateParams, $scope, $timeout, $q) { - var self = this; - self.owner = {}; - self.pet = {}; + .controller('OwnerDetailsController', OwnerDetailsController); - $http.get('api/gateway/owners/' + $stateParams.ownerId).then(function (resp) { - self.owner = resp.data; - console.log(self.owner); +OwnerDetailsController.$inject = ['$http', '$state', '$stateParams', '$scope', '$timeout', '$q']; - var petPromises = self.owner.pets.map(function (pet) { - return $http.get('api/gateway/pets/' + pet.petid, { cache: false }); - }); +function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $q) { + var vm = this; // Use 'vm' (short for ViewModel) instead of 'self' + // Initialize properties + vm.owner = {}; + vm.pet = {}; + vm.pets = []; - $q.all(petPromises).then(function (responses) { - self.owner.pets = responses.map(function (response) { - return response.data; - }); - }); + // Fetch owner data + $http.get('api/gateway/owners/' + $stateParams.ownerId) + .then(function (resp) { + vm.owner = resp.data; + console.log(vm.owner); + }) + .catch(function (error) { + console.error('Error fetching owner data:', error); }); - self.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"); + // Fetch associated pets and their details + $http.get(`api/gateway/owners/${$stateParams.ownerId}/pets`) + .then(function (response) { + // Split the response by newline characters to get individual pet objects + var petResponses = response.data.split('\n'); - /* $http.get('api/gateway/owners/' + $stateParams.ownerId).then(function (resp) { - self.owner = resp.data; - }); - */ +// Parse each pet response as JSON, remove the "data:" prefix, and trim any leading/trailing whitespace + var petObjects = petResponses.map(function (petResponse) { + // Remove the "data:" prefix and trim any leading/trailing whitespace + var trimmedResponse = petResponse.replace(/^data:/, '').trim(); + console.log("Trimmed results: ", trimmedResponse) - self.owner.pets = self.owner.pets.filter(function(pet) { - return pet.petId !== petId; - }); + // Check if the trimmed response is empty + if (!trimmedResponse) { + return null; // Skip empty responses + } - $scope.$applyAsync(); - // Handle the success appropriately - }).catch(function (error) { - console.error("Error deleting pet:", error); - // Handle the error appropriately + try { + return JSON.parse(trimmedResponse); + } catch (error) { + console.error('Error parsing pet response:', error); + return null; + } }); - }; - +// Filter out any parsing errors (null values) + petObjects = petObjects.filter(function (pet) { + return pet !== null; + }); + // Assuming that each pet has a 'petId' property, you can create an array of promises to fetch detailed pet data + var petPromises = petObjects.map(function (pet) { + return $http.get(`api/gateway/pets/${pet.petId}`); + }); + return $q.all(petPromises); + }) + .then(function (responses) { + vm.pets = responses.map(function (response) { + return response.data; + }); + console.log("Pet Array:", vm.pets); + }) + .catch(function (error) { + console.error('Error fetching pet data:', error); + }); - self.toggleActiveStatus = function (petId) { - $http.get('api/gateway/pets/' + petId + '?_=' + new Date().getTime(), { headers: { 'Cache-Control': 'no-cache' } }).then(function (resp) { + // Toggle pet's active status + vm.toggleActiveStatus = function (petId) { + $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); - self.pet = resp.data; - console.log("Pet id is " + self.pet.petId); - console.log(self.pet); + 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:" + self.pet.isActive); - self.pet.isActive = self.pet.isActive === "true" ? "false" : "true"; - console.log("Active status after is:" + self.pet.isActive); + 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); - $http.patch('api/gateway/pet/' + petId, { - isActive: self.pet.isActive - }, { headers: { 'Cache-Control': 'no-cache' } }).then(function (resp) { - console.log("Pet active status updated successfully"); - self.pet = resp.data; - $scope.$applyAsync() - $timeout(); // Manually trigger the $digest cycle to update the UI - }).catch(function (error) { - console.error("Error updating pet active status:", error); - // Handle the error appropriately - }); + 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; + $timeout(); // Manually trigger the $digest cycle to update the UI + }) + .catch(function (error) { + console.error("Error updating pet active status:", 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 e4fe0fd047..29e0006383 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 @@ -73,34 +73,30 @@

Owner Details

Pet Details

-
- Add Pet +
+ Add Pet +
-
-
- -
-
- Edit Pet -

Name: {{ pet.name }}

-

Pet Id: {{pet.petId}}

- -
-
- - - -
- +
+ +
+
+ Edit Pet +

Name: {{ pet.name }}

+ +
+
+ + +
-
+
+
+ -
diff --git a/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.component.js b/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.component.js new file mode 100644 index 0000000000..eff0fda302 --- /dev/null +++ b/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.component.js @@ -0,0 +1,8 @@ +'use strict'; + +angular.module('petRegister') + .component('petRegister', { + templateUrl: 'scripts/pet-register/pet-register.template.html', + controller: 'PetRegisterController' + }); + diff --git a/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.controller.js b/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.controller.js new file mode 100644 index 0000000000..4da59acca9 --- /dev/null +++ b/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.controller.js @@ -0,0 +1,68 @@ +'use strict'; + +angular.module('petRegister') + .controller('PetRegisterController', ["$http", '$state', '$stateParams', function ($http, $state, $stateParams) { + var self = this; + var ownerId = $stateParams.ownerId || 0; + console.log("properly running on load") + + $http.get('api/gateway/owners/petTypes').then(function (resp) { + self.types = resp.data; + }); + + + // Function to submit the form + self.submitPetForm = function () { + console.log("function calls") + var petType = { + id: self.pet.type.id, + name: self.pet.type.name + } + + var data = { + ownerId: ownerId, + petId: randomUUID, + name: self.pet.name, + birthDate: self.pet.birthDate, + type: petType.id, + isActive : "true" + } + + + $http.post("api/gateway/" + "owners/" + ownerId + "/pets", data).then(function (){ + console.log("before if") + $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")); + }); + }; + + function generateUUID() { + // Generate a random hexadecimal string of length 12 + var randomHex = 'xxxxxxxxxxxx'.replace(/x/g, function () { + return (Math.random() * 16 | 0).toString(16); + }); + + // Format the UUID + var uuid = [ + randomHex.substr(0, 8), + randomHex.substr(8, 4), + '4' + randomHex.substr(13, 3), // Set the version to 4 (random) + '89ab'[Math.floor(Math.random() * 4)] + randomHex.substr(17, 3), // Set the variant + randomHex.substr(20, 12) + ].join('-'); + + return uuid; + } + +// Example usage: + var randomUUID = generateUUID(); + console.log(randomUUID); + + + }]); + diff --git a/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.js b/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.js new file mode 100644 index 0000000000..e1a553ece0 --- /dev/null +++ b/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.js @@ -0,0 +1,14 @@ +'use strict'; + +angular.module('petRegister', ['ui.router']) + .config(['$stateProvider', function ($stateProvider) { + $stateProvider + .state('petRegister', { + parent: 'app', + url: '/owners/{ownerId}/pets/register', + param: {ownerId: null}, + template: '' + }) + + }]); + diff --git a/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.template.html b/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.template.html new file mode 100644 index 0000000000..6cdeb4caf3 --- /dev/null +++ b/api-gateway/src/main/resources/static/scripts/pet-register/pet-register.template.html @@ -0,0 +1,35 @@ +

Register New Pet

+ +
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+ +
+ diff --git a/api-gateway/src/test/java/com/petclinic/bffapigateway/domainclientlayer/CustomerServiceClientIntegrationTest.java b/api-gateway/src/test/java/com/petclinic/bffapigateway/domainclientlayer/CustomerServiceClientIntegrationTest.java index 33db4f2457..737f661568 100644 --- a/api-gateway/src/test/java/com/petclinic/bffapigateway/domainclientlayer/CustomerServiceClientIntegrationTest.java +++ b/api-gateway/src/test/java/com/petclinic/bffapigateway/domainclientlayer/CustomerServiceClientIntegrationTest.java @@ -85,7 +85,7 @@ public class CustomerServiceClientIntegrationTest { .name("Cat") .birthDate(date) .petTypeId("5") - .photoId("2") + // .photoId("2") .isActive("true") .build(); diff --git a/customers-service-reactive/src/main/java/com/petclinic/customersservice/business/PetService.java b/customers-service-reactive/src/main/java/com/petclinic/customersservice/business/PetService.java index 5ea93453e2..1547177ba7 100644 --- a/customers-service-reactive/src/main/java/com/petclinic/customersservice/business/PetService.java +++ b/customers-service-reactive/src/main/java/com/petclinic/customersservice/business/PetService.java @@ -1,6 +1,7 @@ package com.petclinic.customersservice.business; import com.petclinic.customersservice.data.Pet; +import com.petclinic.customersservice.presentationlayer.PetRequestDTO; import com.petclinic.customersservice.presentationlayer.PetResponseDTO; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/customers-service-reactive/src/main/java/com/petclinic/customersservice/business/PetServiceImpl.java b/customers-service-reactive/src/main/java/com/petclinic/customersservice/business/PetServiceImpl.java index 33480ece11..503defb425 100644 --- a/customers-service-reactive/src/main/java/com/petclinic/customersservice/business/PetServiceImpl.java +++ b/customers-service-reactive/src/main/java/com/petclinic/customersservice/business/PetServiceImpl.java @@ -2,6 +2,7 @@ import com.petclinic.customersservice.data.Pet; import com.petclinic.customersservice.data.PetRepo; +import com.petclinic.customersservice.presentationlayer.PetRequestDTO; import com.petclinic.customersservice.presentationlayer.PetResponseDTO; import com.petclinic.customersservice.util.EntityDTOUtil; import org.springframework.beans.factory.annotation.Autowired; diff --git a/customers-service-reactive/src/main/java/com/petclinic/customersservice/presentationlayer/PetRequestDTO.java b/customers-service-reactive/src/main/java/com/petclinic/customersservice/presentationlayer/PetRequestDTO.java index b0a6745457..2018e923f2 100644 --- a/customers-service-reactive/src/main/java/com/petclinic/customersservice/presentationlayer/PetRequestDTO.java +++ b/customers-service-reactive/src/main/java/com/petclinic/customersservice/presentationlayer/PetRequestDTO.java @@ -14,11 +14,10 @@ public class PetRequestDTO { private String ownerId; - private String petId; private String name; private Date birthDate; private String petTypeId; - private String photoId; + //private String photoId; private String isActive; } diff --git a/customers-service-reactive/src/main/java/com/petclinic/customersservice/presentationlayer/PetResponseDTO.java b/customers-service-reactive/src/main/java/com/petclinic/customersservice/presentationlayer/PetResponseDTO.java index e10d50d532..a3ceaa53bc 100644 --- a/customers-service-reactive/src/main/java/com/petclinic/customersservice/presentationlayer/PetResponseDTO.java +++ b/customers-service-reactive/src/main/java/com/petclinic/customersservice/presentationlayer/PetResponseDTO.java @@ -15,7 +15,7 @@ public class PetResponseDTO { private String name; private Date birthDate; private String petTypeId; - private String photoId; + // private String photoId; private String isActive; } diff --git a/customers-service-reactive/src/test/java/com/petclinic/customersservice/business/PetDTOServiceImplTest.java b/customers-service-reactive/src/test/java/com/petclinic/customersservice/business/PetDTOServiceImplTest.java index e7a0a218f3..d763939e0e 100644 --- a/customers-service-reactive/src/test/java/com/petclinic/customersservice/business/PetDTOServiceImplTest.java +++ b/customers-service-reactive/src/test/java/com/petclinic/customersservice/business/PetDTOServiceImplTest.java @@ -84,7 +84,7 @@ private PetResponseDTO petDTObuilder() throws ParseException { .petTypeId("1") .birthDate(new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-11-30")) .petTypeId(PetType.builder().id("1").name("TESTPETTYPE").build().toString()) - .photoId(Photo.builder().id("1").photo("1").name("test").type("test").build().toString()) + //.photoId(Photo.builder().id("1").photo("1").name("test").type("test").build().toString()) .ownerId("ownerId-1234") .isActive("true") .build(); diff --git a/customers-service-reactive/src/test/java/com/petclinic/customersservice/presentationlayer/PetControllerIntegrationTest.java b/customers-service-reactive/src/test/java/com/petclinic/customersservice/presentationlayer/PetControllerIntegrationTest.java index d67e9257d2..292dec54cc 100644 --- a/customers-service-reactive/src/test/java/com/petclinic/customersservice/presentationlayer/PetControllerIntegrationTest.java +++ b/customers-service-reactive/src/test/java/com/petclinic/customersservice/presentationlayer/PetControllerIntegrationTest.java @@ -119,7 +119,7 @@ void insertPet() { .jsonPath("$.name").isEqualTo(petEntity.getName()) .jsonPath("$.petTypeId").isEqualTo(petEntity.getPetTypeId()) .jsonPath("$.ownerId").isEqualTo(petEntity.getOwnerId()) - .jsonPath("$.photoId").isEqualTo(petEntity.getPhotoId()) +// .jsonPath("$.photoId").isEqualTo(petEntity.getPhotoId()) .jsonPath("$.isActive").isEqualTo(petEntity.getIsActive());