Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/cstm cpc 1013 add pet weight #571

Merged
merged 16 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public class PetRequestDTO {
private String petTypeId;
//private String photoId;
private String isActive;

private String weight;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* @author Maciej Szarlinski
* Copied from https://github.com/spring-petclinic/spring-petclinic-microservices

Check warning on line 12 in api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Pets/PetResponseDTO.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Link specified as plain text

Link specified as plain text
*/
@Builder
@AllArgsConstructor
Expand All @@ -24,7 +24,7 @@
private String petTypeId;
//private String photoId;
private String isActive;

private String weight;

//private final List<VisitDetails> visits = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,27 @@
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) {

Check notice on line 35 in api-gateway/src/main/resources/static/scripts/owner-details/owner-details.controller.js

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Duplicated code fragment

Duplicated code
if (birthday) {
var date = new Date(birthday);
var year = date.getUTCFullYear();
Expand All @@ -32,6 +50,11 @@
.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 Down Expand Up @@ -88,5 +111,76 @@
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);

Check notice on line 119 in api-gateway/src/main/resources/static/scripts/owner-details/owner-details.controller.js

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Duplicated code fragment

Duplicated code
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
});
};
};



Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h3 class="">Pets</h3>
<div class="bg-white shadow-sm m-2" style="width: 40px; height: 40px; border-radius: 50px;">
<img style="width: 100%; height: 100%; border-radius: 50px" src="../../images/animaldefault.png"/>


</div>
<div class="d-flex align-items-center">
<p class="mt-2 mx-4">({{$ctrl.getPetTypeName(pet.petTypeId)}}) - {{pet.name}}<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ <h3>No pet found</h3>
<input class="inputFieldsStyle bg-white" value="{{$ctrl.getBirthday($ctrl.pet.birthDate)}}" readonly disabled/>
<label class="inputLabel">Birthday</label>
</div>
<div class="d-flex flex-column">
<input class="inputFieldsStyle bg-white" value="{{$ctrl.pet.weight}}" readonly disabled/>
<label class="inputLabel">Weight (KG)</label>
</div>
</div>

<div class="d-flex flex-row gap-3 pt-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@
</div>

<div class="form-group formColor">
<label class="col-sm-2 control-label">Birth date</label>
<label class="col-sm-2 control-label"> Birth date </label>
<div class="pet col-sm-6">
<input class="form-control" ng-model="$ctrl.pet.birthDate" name="dbo" required type="date" ng-disabled="$ctrl.checked"/>
<span ng-show="petForm.name.$error.required" class="help-inline"> birth date is required.</span>
<p ng-hide="true">Current Birth Date: {{ $ctrl.pet.birthDate | date:'yyyy-MM-dd'}}</p>
</div>
</div>

<div class="form-group formColor">
<label class="col-sm-2 control-label"> Pet Weight (Kilograms) </label>
<div class="pet col-sm-6">
<input class="form-control col-sm-4" ng-model="$ctrl.pet.weight" name="weight" required type="text" ng-disabled="$ctrl.checked"/>
<span ng-show="petForm.name.$error.required" class="help-inline">Weight is required.</span>
</div>
</div>

<div class="form-group formColor">
<label class="col-sm-2 control-label">Type</label>
<!--<div class="pet col-sm-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ angular.module('petRegister')
name: self.pet.name,
birthDate: self.pet.birthDate,
type: petType.id,
isActive : "true"
isActive : "true",
weight: self.pet.weight
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
</div>
</div>

<div class="form-group formColor">
<label class="col-sm-2 control-label"> Pet Weight (Kilograms) </label>
<div class="pet col-sm-6">
<input class="form-control col-sm-4" ng-model="$ctrl.pet.weight" name="weight" required type="text" ng-disabled="$ctrl.checked"/>
</div>
</div>

<div class="form-group formColor">
<label class="col-sm-2 control-label">Pet Type</label>
<div class="pet col-sm-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
import reactor.core.publisher.Mono;


import java.text.DateFormat;

Check warning on line 15 in customers-service-reactive/src/main/java/com/petclinic/customersservice/business/DataSetupService.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import java.text.DateFormat;`
import java.text.SimpleDateFormat;
import java.util.ArrayList;

Check warning on line 17 in customers-service-reactive/src/main/java/com/petclinic/customersservice/business/DataSetupService.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import java.util.ArrayList;`
import java.util.Date;

Check warning on line 18 in customers-service-reactive/src/main/java/com/petclinic/customersservice/business/DataSetupService.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import java.util.Date;`
import java.util.List;

@Service
public class DataSetupService implements CommandLineRunner {
@Autowired

Check notice on line 23 in customers-service-reactive/src/main/java/com/petclinic/customersservice/business/DataSetupService.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Non recommended 'field' injections

Field injection is not recommended
private PetTypeService petTypeService;

@Autowired

Check notice on line 26 in customers-service-reactive/src/main/java/com/petclinic/customersservice/business/DataSetupService.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Non recommended 'field' injections

Field injection is not recommended
private PetService petService;

@Autowired

Check notice on line 29 in customers-service-reactive/src/main/java/com/petclinic/customersservice/business/DataSetupService.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Non recommended 'field' injections

Field injection is not recommended
private OwnerService ownerService;

@Autowired

Check notice on line 32 in customers-service-reactive/src/main/java/com/petclinic/customersservice/business/DataSetupService.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Non recommended 'field' injections

Field injection is not recommended
private PhotoService photoService;

@Override
Expand All @@ -49,19 +49,19 @@



Pet p1 = new Pet("c3eecf3a-d732-46d6-9e51-ab03314f3c4d", "0e4d8481-b611-4e52-baed-af16caa8bf8a","f470653d-05c5-4c45-b7a0-7d70f003d2ac", "Leo", new SimpleDateFormat( "yyyyMMdd" ).parse( "2010-05-20" ), "1", "1","false");
Pet p2 = new Pet("180143e7-547d-46c2-82fd-7c84547e126c", "ecb109cd-57ea-4b85-b51e-99751fd1c349", "e6c7398e-8ac4-4e10-9ee0-03ef33f0361a", "Basil", new SimpleDateFormat( "yyyyMMdd" ).parse( "2002-08-06" ), "6", "1","true");
Pet p3 = new Pet("6566cc34-21f7-4f71-9388-c70c95b01636", "53163352-8398-4513-bdff-b7715c056d1d", "3f59dca2-903e-495c-90c3-7f4d01f3a2aa", "Rosy", new SimpleDateFormat( "yyyyMMdd" ).parse( "2001-04-17" ), "2", "1","false");
Pet p4 = new Pet("daa049e0-b6ec-4465-a20e-6bd4be11606e", "7056652d-f2fd-4873-a480-5d2e86bed641", "3f59dca2-903e-495c-90c3-7f4d01f3a2aa", "Jewel", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-03-07"), "2","1","true");
Pet p5 = new Pet("09b1085e-9ddc-468b-9a20-1bd8fe284d2c", "fde4c2a1-b663-45a2-affe-7b3d08cebf75", "a6e0e5b0-5f60-45f0-8ac7-becd8b330486", "Iggy", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-11-30"),"3", "1","false");
Pet p6 = new Pet("4713b5c9-0426-4f70-a070-47e97ed25fa6", "f42b727d-c0d2-4b37-b99e-af7c7da556c0", "c6a0fb9d-fc6f-4c21-95fc-4f5e7311d0e2", "George", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-11-30"), "6", "1","true");
Pet p7 = new Pet("534a9744-e316-461b-9ada-3552fbeb86b7", "306882c1-2019-43fe-96d3-a05ef7efad25", "b3d09eab-4085-4b2d-a121-78a0a2f9e501", "Samantha", new SimpleDateFormat( "yyyyMMdd" ).parse( "1995-09-04"), "1", "1","true");
Pet p8 = new Pet("19979a4f-cd0b-4cd3-a593-c94e96172756", "399f2e7a-3c48-486a-956f-044808b0da6b", "b3d09eab-4085-4b2d-a121-78a0a2f9e501", "Max", new SimpleDateFormat( "yyyyMMdd" ).parse( "1995-09-04"), "1", "1","true");
Pet p9 = new Pet("91f56a80-049b-4bd7-8620-3354854b9541", "7493b72f-bbd7-48bb-b535-4165ae8a94f3", "5fe81e29-1f1d-4f9d-b249-8d3e0cc0b7dd", "Lucky", new SimpleDateFormat( "yyyyMMdd" ).parse( "1999-08-06"), "5", "1","true");
Pet p10 = new Pet("15d16020-3056-4a8f-a754-18fbd19ab31c", "9d1aa0b7-be08-4cab-a1c9-db0d2af82bd7", "48f9945a-4ee0-4b0b-9b44-3da829a0f0f7", "Mulligan", new SimpleDateFormat( "yyyyMMdd" ).parse( "1997-02-24"), "2", "1","true");
Pet p11 = new Pet("913149c2-a712-4151-8b4c-a4b55b7f8d49", "aca3f26b-a8c6-4ccd-bb24-1fb12ef75142", "9f6accd1-e943-4322-932e-199d93824317", "Freddy", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-03-09"), "5", "1","true");
Pet p12 = new Pet("f9540265-6ff7-46a6-b3f9-b25a9f150733", "db2685cf-8c34-4930-828e-d07208ab39f4", "7c0d42c2-0c2d-41ce-bd9c-6ca67478956f", "Ulysses", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-06-24"), "2", "1","true");
Pet p13 = new Pet("706a12a4-5e7a-42ea-b818-5add08accece", "907d0744-e2a4-4a34-9706-95aa1bdd9bbe", "7c0d42c2-0c2d-41ce-bd9c-6ca67478956f", "Sly", new SimpleDateFormat( "yyyyMMdd" ).parse( "2002-06-08"), "1", "1","true");
Pet p1 = new Pet("c3eecf3a-d732-46d6-9e51-ab03314f3c4d", "0e4d8481-b611-4e52-baed-af16caa8bf8a","f470653d-05c5-4c45-b7a0-7d70f003d2ac", "Leo", new SimpleDateFormat( "yyyyMMdd" ).parse( "2010-05-20" ), "1", "1","false","3.7");
Pet p2 = new Pet("180143e7-547d-46c2-82fd-7c84547e126c", "ecb109cd-57ea-4b85-b51e-99751fd1c349", "e6c7398e-8ac4-4e10-9ee0-03ef33f0361a", "Basil", new SimpleDateFormat( "yyyyMMdd" ).parse( "2002-08-06" ), "6", "1","true","0.20");
Pet p3 = new Pet("6566cc34-21f7-4f71-9388-c70c95b01636", "53163352-8398-4513-bdff-b7715c056d1d", "3f59dca2-903e-495c-90c3-7f4d01f3a2aa", "Rosy", new SimpleDateFormat( "yyyyMMdd" ).parse( "2001-04-17" ), "2", "1","false","5.2");
Pet p4 = new Pet("daa049e0-b6ec-4465-a20e-6bd4be11606e", "7056652d-f2fd-4873-a480-5d2e86bed641", "3f59dca2-903e-495c-90c3-7f4d01f3a2aa", "Jewel", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-03-07"), "2","1","true","3.8");
Pet p5 = new Pet("09b1085e-9ddc-468b-9a20-1bd8fe284d2c", "fde4c2a1-b663-45a2-affe-7b3d08cebf75", "a6e0e5b0-5f60-45f0-8ac7-becd8b330486", "Iggy", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-11-30"),"3", "1","false","0.07");
Pet p6 = new Pet("4713b5c9-0426-4f70-a070-47e97ed25fa6", "f42b727d-c0d2-4b37-b99e-af7c7da556c0", "c6a0fb9d-fc6f-4c21-95fc-4f5e7311d0e2", "George", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-11-30"), "6", "1","true","1.1");
Pet p7 = new Pet("534a9744-e316-461b-9ada-3552fbeb86b7", "306882c1-2019-43fe-96d3-a05ef7efad25", "b3d09eab-4085-4b2d-a121-78a0a2f9e501", "Samantha", new SimpleDateFormat( "yyyyMMdd" ).parse( "1995-09-04"), "1", "1","true","5");
Pet p8 = new Pet("19979a4f-cd0b-4cd3-a593-c94e96172756", "399f2e7a-3c48-486a-956f-044808b0da6b", "b3d09eab-4085-4b2d-a121-78a0a2f9e501", "Max", new SimpleDateFormat( "yyyyMMdd" ).parse( "1995-09-04"), "1", "1","true","2.7");
Pet p9 = new Pet("91f56a80-049b-4bd7-8620-3354854b9541", "7493b72f-bbd7-48bb-b535-4165ae8a94f3", "5fe81e29-1f1d-4f9d-b249-8d3e0cc0b7dd", "Lucky", new SimpleDateFormat( "yyyyMMdd" ).parse( "1999-08-06"), "5", "1","true","0.64");
Pet p10 = new Pet("15d16020-3056-4a8f-a754-18fbd19ab31c", "9d1aa0b7-be08-4cab-a1c9-db0d2af82bd7", "48f9945a-4ee0-4b0b-9b44-3da829a0f0f7", "Mulligan", new SimpleDateFormat( "yyyyMMdd" ).parse( "1997-02-24"), "2", "1","true","26");
Pet p11 = new Pet("913149c2-a712-4151-8b4c-a4b55b7f8d49", "aca3f26b-a8c6-4ccd-bb24-1fb12ef75142", "9f6accd1-e943-4322-932e-199d93824317", "Freddy", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-03-09"), "5", "1","true","0.40");
Pet p12 = new Pet("f9540265-6ff7-46a6-b3f9-b25a9f150733", "db2685cf-8c34-4930-828e-d07208ab39f4", "7c0d42c2-0c2d-41ce-bd9c-6ca67478956f", "Ulysses", new SimpleDateFormat( "yyyyMMdd" ).parse( "2000-06-24"), "2", "1","true","20");
Pet p13 = new Pet("706a12a4-5e7a-42ea-b818-5add08accece", "907d0744-e2a4-4a34-9706-95aa1bdd9bbe", "7c0d42c2-0c2d-41ce-bd9c-6ca67478956f", "Sly", new SimpleDateFormat( "yyyyMMdd" ).parse( "2002-06-08"), "1", "1","true","3.4");


Flux.just(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public class Pet {
private String petTypeId;
private String photoId;
private String isActive;
private String weight;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public class PetRequestDTO {
private String petTypeId;
//private String photoId;
private String isActive;

private String weight;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public class PetResponseDTO {
private String petTypeId;
// private String photoId;
private String isActive;

private String weight;
}
Loading