Skip to content

Commit

Permalink
Merge branch 'main' into feat-INVT-CPC-991_Ability_to_make_the_produc…
Browse files Browse the repository at this point in the history
…ts_row_hoverable
  • Loading branch information
Abdur-Siddiqui authored Oct 21, 2023
2 parents d021b8a + c9a727c commit c2c9fdb
Show file tree
Hide file tree
Showing 19 changed files with 516 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.petclinic.bffapigateway.dtos.Visits.*;
import com.petclinic.bffapigateway.exceptions.BadRequestException;
import com.petclinic.bffapigateway.exceptions.DuplicateTimeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -117,9 +118,14 @@ public Mono<VisitResponseDTO> createVisitForPet(VisitRequestDTO visit) {

if (httpStatus == HttpStatus.NOT_FOUND) {
return Mono.error(new NotFoundException(message));
} else {
}
else if (httpStatus == HttpStatus.CONFLICT){
return Mono.error(new DuplicateTimeException(message));
}
else {
return Mono.error(new BadRequestException(message));
}

} catch (IOException e) {
// Handle parsing error
return Mono.error(new BadRequestException("Bad Request"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.petclinic.bffapigateway.exceptions;

public class DuplicateTimeException extends RuntimeException{
public DuplicateTimeException(final String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@ angular.module('inventoryProductList')
if (queryString !== '') {
apiUrl += "?" + queryString;
}

let response = [];
$http.get(apiUrl)
.then(function(resp) {
self.inventoryProductList = resp.data;
resp.data.forEach(function (current) {
current.productPrice = current.productPrice.toFixed(2);
current.productSalePrice = current.productSalePrice.toFixed(2);
response.push(current);
});
self.inventoryProductList = response;
loadTotalItem(productName, productPrice, productQuantity)
InventoryService.setInventoryId(inventoryId);
})
Expand Down Expand Up @@ -125,8 +130,14 @@ angular.module('inventoryProductList')
self.lastParams.productPrice = null;
self.lastParams.productQuantity = null;
let inventoryId = $stateParams.inventoryId;
let response = [];
$http.get('api/gateway/inventory/' + $stateParams.inventoryId + '/products-pagination?page=' + self.currentPage + '&size=' + self.pageSize).then(function (resp) {
self.inventoryProductList = resp.data;
resp.data.forEach(function (current) {
current.productPrice = current.productPrice.toFixed(2);
current.productSalePrice = current.productSalePrice.toFixed(2);
response.push(current);
});
self.inventoryProductList = response;
inventoryId = $stateParams.inventoryId;
loadTotalItem(productName, productPrice, productQuantity, productSalePrice)
InventoryService.setInventoryId(inventoryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ <h2>Inventory Products</h2>
</thead>
<tr ng-repeat="product in $ctrl.inventoryProductList | filter:$ctrl.query track by product.productId">
<td><span>{{product.productName}}</span></td>
<td><span>{{product.productId}}</span></td>
<td><span>{{product.productId}}</span></td>
<td><span>{{product.productQuantity}}</span></td>
<td><span>{{product.productPrice}}</span></td>
<td><span>{{product.productPrice}}$</span></td>
<td><span>{{product.productDescription}}</span></td>
<td><span>{{product.productSalePrice}}</span></td>
<td><span>{{product.productSalePrice}}$</span></td>

<td>
<a href="#!/inventory/{{$ctrl.inventory.inventoryId}}/products/{{product.productId}}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,18 @@ 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';
}
};



// Fetch owner data
$http.get('api/gateway/owners/' + $stateParams.ownerId)
.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);
Expand All @@ -47,13 +34,13 @@ function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $
.then(function (response) {
// Split the response by newline characters to get individual pet objects
var petResponses = response.data.split('\n');

// Parse each pet response as JSON, remove the "data:" prefix, and trim any leading/trailing whitespace
// 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)


// Check if the trimmed response is empty
if (!trimmedResponse) {
return null; // Skip empty responses
Expand All @@ -67,12 +54,11 @@ function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $
}
});

// Filter out any parsing errors (null values)
// 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}`);
Expand All @@ -81,7 +67,9 @@ function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $
return $q.all(petPromises);
})
.then(function (responses) {

vm.pets = responses.map(function (response) {

return response.data;
});
console.log("Pet Array:", vm.pets);
Expand All @@ -90,9 +78,11 @@ function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $
console.error('Error fetching pet data:', error);
});



// Toggle pet's active status
vm.toggleActiveStatus = function (petId) {
$http.get('api/gateway/pets/' + petId + '?_=' + new Date().getTime(), { headers: { 'Cache-Control': 'no-cache' } })
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);
Expand All @@ -112,11 +102,58 @@ function OwnerDetailsController($http, $state, $stateParams, $scope, $timeout, $
.then(function (resp) {
console.log("Pet active status updated successfully");
vm.pet = resp.data;
$timeout(); // Manually trigger the $digest cycle to update the UI
// 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
});
};
}

};

Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,54 @@ <h3 class="">Owner Details</h3>

<div class="d-flex flex-column">
<div class="d-flex flex-column p-5 shadow">

<div class="d-flex justify-content-between gap-5">
<h3 class="">Pet Details</h3>


<div class="border-5 rounded">
<a style="color: rgba(0,0,0,0.5);" class="btn btn-light" ui-sref="petRegister({ownerId: $ctrl.owner.ownerId})">Add Pet</a>
<a style="color: rgba(0,0,0,0.5);" class="btn btn-light" ui-sref="ownerEdit({ownerId: $ctrl.owner.ownerId, method: 'edit'})">Add Pet</a>
</div>
</div>

<div>
<!-- Use ng-repeat to iterate through the owner's pets -->
<div ng-repeat="pet in $ctrl.pets" class="d-flex justify-content-between">
<div class="mt-3">
<a style="color: rgba(0,0,0,0.5);" class="btn btn-light" ui-sref="editPet({ownerId: $ctrl.owner.ownerId, petId: pet.petId, method: 'edit'})">Edit Pet</a>
<p ui-sref="petDetails({petId: pet.petId})">Name: {{ pet.name }}</p>
<!-- Add more pet details as needed -->
<div>
<!-- Use ng-repeat to iterate through the owner's pets -->
<div ng-repeat="pet in $ctrl.owner.pets" ng-show="$ctrl.owner.pets.length > 0" class="d-flex justify-content-between">
<div class="mt-3">
<a style="color: rgba(0,0,0,0.5);" class="btn btn-light" ui-sref="editPet({ownerId: $ctrl.owner.ownerId, petId: pet.petId, method: 'edit'})">Edit Pet</a>
<p>Name: {{ pet.name }}</p>
<p>Pet Id: {{pet.petId}}</p>
<!-- Add more pet details as needed -->
</div>
<div class="border-5 rounded">
<input type="checkbox" ng-model="pet.isActive" ng-click="$ctrl.toggleActiveStatus(pet.petId)">

<label ng-if="pet.isActive" style="color: rgba(0,0,0,0.5);">Deactivate Pet</label>
<label ng-if="!pet.isActive" style="color: rgba(0,0,0,0.5);">Activate Pet</label>
</div>


<div class="border-5 rounded">
<a style="color: rgba(0,0,0,0.5);" class="btn btn-light" ng-click="$ctrl.deletePet(pet.petId)">Delete Pet</a>
</div>
</div>
<div class="border-5 rounded">
<input type="checkbox" ng-model="$ctrl.pet.isActive" ng-change="$ctrl.toggleActiveStatus(pet.petId)">
<label ng-if="$ctrl.pet.isActive === 'true'" style="color: rgba(0,0,0,0.5);">Deactivate Pet</label>
<label ng-if="$ctrl.pet.isActive !== 'true'" style="color: rgba(0,0,0,0.5);">Activate Pet</label>
</div>
</div>
</div>
</div>

</div>


</div>

</div>
</div>

</div>
<div ng-repeat="pet in $ctrl.pets" class="d-flex justify-content-between">
<div class="mt-3">
<p ui-sref="petDetails({petId: pet.petId})">Name: {{ pet.name }}</p>
<!-- Add more pet details as needed -->
</div>
</div>
</div>
</div>

</div>

</div>


Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ function PetDetailsController($http, $state, $stateParams, $scope, $timeout, $q)
// Initialize properties
vm.pet = {};

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';
}
};
// Fetch owner data
$http.get('api/gateway/pets/' + $stateParams.petId)
.then(function (resp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ <h3 class="">Pet Details</h3>
<label class="inputLabel">Name</label>
</div>
<div class="d-flex flex-column">
<input class="inputFieldsStyle bg-white" value="{{$ctrl.pet.birthDate}}" readonly disabled/>
<input class="inputFieldsStyle bg-white" value="{{$ctrl.pet.birthDate | date:'yyyy-MM-dd'}}" readonly disabled/>
<label class="inputLabel">Birthday</label>
</div>
</div>

<div class="d-flex flex-row gap-3 pt-1">
<div class="d-flex flex-column">
<input class="inputFieldsStyle bg-white" value="{{$ctrl.pet.petTypeId}}" readonly disabled/>
<input class="inputFieldsStyle bg-white" value="{{$ctrl.getPetTypeName($ctrl.pet.petTypeId)}}" readonly disabled/>
<label class="inputLabel">Pet Type</label>
</div>
<div class="d-flex flex-column">
Expand All @@ -50,19 +50,16 @@ <h3 class="">Pet Details</h3>

<div class="d-flex flex-row gap-3 justify-content-end">
<div>
<a style="color: rgba(0,0,0,0.5);" class="btn btn-light" ui-sref="ownerEdit({ownerId: $ctrl.owner.ownerId, method: 'edit'})">Edit</a>
<a style="color: rgba(0,0,0,0.5);" class="btn btn-light" ui-sref="editPet({ownerId: $ctrl.pet.ownerId, petId: $ctrl.pet.petId, method: 'edit'})">Edit Pet</a><!-- Add more pet details as needed -->

</div>
<div>
<a style="color: rgba(0,0,0,0.5);" class="btn btn-light" ui-sref="ownerEdit({ownerId: $ctrl.owner.ownerId, method: 'delete'})">Delete</a>
</div>
</div>

</form>

</div>

</div>

</div>

</div>
Expand Down
Loading

0 comments on commit c2c9fdb

Please sign in to comment.