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/BILL-CPC-905_Implement_Pagination_System_For_BillHistory_Page #599

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -2,16 +2,26 @@

import com.petclinic.bffapigateway.dtos.Bills.BillRequestDTO;
import com.petclinic.bffapigateway.dtos.Bills.BillResponseDTO;
import com.petclinic.bffapigateway.dtos.Bills.BillStatus;

Check warning on line 5 in api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import com.petclinic.bffapigateway.dtos.Bills.BillStatus;`
import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerResponseDTO;

Check warning on line 6 in api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerResponseDTO;`
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties;

Check warning on line 9 in api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties;`
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.awt.print.Pageable;

Check warning on line 18 in api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import java.awt.print.Pageable;`
import java.time.LocalDate;

Check warning on line 19 in api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import java.time.LocalDate;`
import java.util.Optional;


@Component
@Slf4j
public class BillServiceClient {

private final WebClient.Builder webClientBuilder;
Expand Down Expand Up @@ -56,6 +66,102 @@
.bodyToFlux(BillResponseDTO.class);
}

//to be changed
// public Flux<BillResponseDTO> getAllBillsByPage(Optional<Integer> page, Optional<Integer> size) {

Check notice on line 70 in api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (6 lines)
// return webClientBuilder.build().get()
// .uri(billServiceUrl + "/bills-pagination?page="+page.orElse(0)+"&size="+size.orElse(5))
// .retrieve()
// .bodyToFlux(BillResponseDTO.class);
// }

public Flux<BillResponseDTO> getAllBillsByPage(Optional<Integer> page, Optional<Integer> size, String billId, String customerId,
String ownerFirstName, String ownerLastName, String visitType,
String vetId, String vetFirstName, String vetLastName) {

UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(billServiceUrl + "/bills-pagination");

builder.queryParam("page", page);
builder.queryParam("size",size);

// Add query parameters conditionally if they are not null or empty
if (billId != null && !billId.isEmpty()) {

Check notice on line 87 in api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Duplicated code fragment

Duplicated code
builder.queryParam("billId", billId);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have been done using switch or if-else statements but this works fine as well!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think about that, it could definitely work. My usual preference are if statements so I'll stick with that

Copy link
Collaborator

@swafit swafit Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have been done using switch or if-else statements but this works fine as well!

In this case an if-else is better since you might have more than one query param that is not provided.

if (customerId != null && !customerId.isEmpty()) {
builder.queryParam("customerId", customerId);
}
if (ownerFirstName != null && !ownerFirstName.isEmpty()) {
builder.queryParam("ownerFirstName", ownerFirstName);
}
if (ownerLastName != null && !ownerLastName.isEmpty()) {
builder.queryParam("ownerLastName", ownerLastName);
}
if (visitType != null && !visitType.isEmpty()) {
builder.queryParam("visitType", visitType);
}
if (vetId != null && !vetId.isEmpty()) {
builder.queryParam("vetId", vetId);
}
if (vetFirstName != null && !vetFirstName.isEmpty()) {
builder.queryParam("vetFirstName", vetFirstName);
}
if (vetLastName != null && !vetLastName.isEmpty()) {
builder.queryParam("vetLastName", vetLastName);
}

return webClientBuilder.build()
.get()
.uri(builder.build().toUri())
.retrieve()
.bodyToFlux(BillResponseDTO.class);
}

//to be changed
public Mono<Long> getTotalNumberOfBills() {
return webClientBuilder.build().get()
.uri(billServiceUrl + "/bills-count")
.retrieve()
.bodyToMono(Long.class);
}

public Mono<Long> getTotalNumberOfBillsWithFilters(String billId, String customerId,
String ownerFirstName, String ownerLastName, String visitType,
String vetId, String vetFirstName, String vetLastName){
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(billServiceUrl + "/bills-filtered-count");

// Add query parameters conditionally if they are not null or empty
if (billId != null && !billId.isEmpty()) {
builder.queryParam("billId", billId);
}
if (customerId != null && !customerId.isEmpty()) {
builder.queryParam("customerId", customerId);
}
if (ownerFirstName != null && !ownerFirstName.isEmpty()) {
builder.queryParam("ownerFirstName", ownerFirstName);
}
if (ownerLastName != null && !ownerLastName.isEmpty()) {
builder.queryParam("ownerLastName", ownerLastName);
}
if (visitType != null && !visitType.isEmpty()) {
builder.queryParam("visitType", visitType);
}
if (vetId != null && !vetId.isEmpty()) {
builder.queryParam("vetId", vetId);
}
if (vetFirstName != null && !vetFirstName.isEmpty()) {
builder.queryParam("vetFirstName", vetFirstName);
}
if (vetLastName != null && !vetLastName.isEmpty()) {
builder.queryParam("vetLastName", vetLastName);
}

return webClientBuilder.build()
.get()
.uri(builder.build().toUri())
.retrieve()
.bodyToMono(Long.class);
}

public Flux<BillResponseDTO> getAllPaidBilling() {
return webClientBuilder.build().get()
.uri(billServiceUrl + "/paid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.petclinic.bffapigateway.dtos.Auth.*;
import com.petclinic.bffapigateway.dtos.Bills.BillRequestDTO;
import com.petclinic.bffapigateway.dtos.Bills.BillResponseDTO;
import com.petclinic.bffapigateway.dtos.Bills.BillStatus;

Check warning on line 8 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import com.petclinic.bffapigateway.dtos.Bills.BillStatus;`
import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerRequestDTO;
import com.petclinic.bffapigateway.dtos.Inventory.*;
import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerResponseDTO;
Expand All @@ -28,13 +29,15 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDate;

Check warning on line 32 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import java.time.LocalDate;`
import java.util.Map;
import java.awt.print.Pageable;

Check warning on line 34 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import java.awt.print.Pageable;`
import java.util.Optional;

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

Check warning on line 40 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Link specified as plain text

Link specified as plain text
* Modified to remove circuitbreaker
*/

Expand Down Expand Up @@ -81,6 +84,54 @@
return billServiceClient.getAllBilling();
}

//to be changed
@SecuredEndpoint(allowedRoles = {Roles.ADMIN})
@GetMapping(value = "bills/bills-pagination", produces = MediaType.APPLICATION_JSON_VALUE)
public Flux<BillResponseDTO> getAllBillingByPage(@RequestParam Optional<Integer> page, @RequestParam Optional<Integer> size,
@RequestParam(required = false) String billId,
@RequestParam(required = false) String customerId,
@RequestParam(required = false) String ownerFirstName,
@RequestParam(required = false) String ownerLastName,
@RequestParam(required = false) String visitType,
@RequestParam(required = false) String vetId,
@RequestParam(required = false) String vetFirstName,
@RequestParam(required = false) String vetLastName) {
if(page.isEmpty()){
page = Optional.of(0);
}

if (size.isEmpty()) {
size = Optional.of(5);
}

return billServiceClient.getAllBillsByPage(page, size, billId, customerId, ownerFirstName, ownerLastName, visitType,
vetId, vetFirstName, vetLastName);
}

//to be changed
@SecuredEndpoint(allowedRoles = {Roles.ADMIN,Roles.VET})
@GetMapping(value = "bills/bills-count")
public Mono<Long> getTotalNumberOfBills(){
return billServiceClient.getTotalNumberOfBills();
}


@SecuredEndpoint(allowedRoles = {Roles.ADMIN,Roles.VET})
@GetMapping(value = "bills/bills-filtered-count")
public Mono<Long> getTotalNumberOfBillsWithFilters (@RequestParam(required = false) String billId,
@RequestParam(required = false) String customerId,
@RequestParam(required = false) String ownerFirstName,
@RequestParam(required = false) String ownerLastName,
@RequestParam(required = false) String visitType,
@RequestParam(required = false) String vetId,
@RequestParam(required = false) String vetFirstName,
@RequestParam(required = false) String vetLastName)
{
return billServiceClient.getTotalNumberOfBillsWithFilters(billId, customerId, ownerFirstName, ownerLastName, visitType,
vetId, vetFirstName, vetLastName);
}


@SecuredEndpoint(allowedRoles = {Roles.ADMIN})
@GetMapping(value = "bills/paid", produces= MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<BillResponseDTO> getAllPaidBilling() {
Expand Down Expand Up @@ -158,7 +209,7 @@
.defaultIfEmpty(ResponseEntity.badRequest().build());
}

/*@GetMapping(value = "owners/{ownerId}/pets")

Check notice on line 212 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (4 lines)
public Flux<PetResponseDTO> getAllPetsFromOwnerId(@PathVariable String ownerId){
return customersServiceClient.getAllPets(ownerId);
}*/
Expand Down Expand Up @@ -284,7 +335,7 @@
.defaultIfEmpty(ResponseEntity.notFound().build());
}
// @PutMapping(value = "owners/*/pets/{petId}/visits/{visitId}", consumes = "application/json", produces = "application/json")
/*

Check notice on line 338 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (33 lines)
Mono<ResponseEntity<VisitDetails>> updateVisit(@RequestBody VisitDetails visit, @PathVariable String petId, @PathVariable String visitId) {
visit.setPetId(petId);
visit.setVisitId(visitId);
Expand Down Expand Up @@ -327,7 +378,7 @@
.defaultIfEmpty(ResponseEntity.badRequest().build());
}

// @PutMapping(value = "owners/*/pets/{petId}/visits/{visitId}", consumes = "application/json", produces = "application/json")

Check notice on line 381 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (7 lines)
// Mono<ResponseEntity<VisitDetails>> updateVisit(@RequestBody VisitDetails visit, @PathVariable String petId, @PathVariable String visitId) {
// visit.setPetId(petId);
// visit.setVisitId(visitId);
Expand All @@ -336,7 +387,7 @@
// }
/* End of Visit Methods */

/**

Check warning on line 390 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Dangling Javadoc comment

Dangling Javadoc comment
* End of Visit Methods
**/

Expand Down Expand Up @@ -500,7 +551,7 @@

@IsUserSpecific(idToMatch = {"vetId"})
@GetMapping("/vets/vetBillId/{vetId}")
public Mono<ResponseEntity<VetResponseDTO>> getVetByVetBillId(@PathVariable String vetBillId) {

Check notice on line 554 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Mismatch in @PathVariable declarations and usages

Path variable 'vetId' is not consumed

Check warning on line 554 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Mismatch in @PathVariable declarations and usages

Cannot resolve path variable 'vetBillId' in request mapping
return vetsServiceClient.getVetByVetBillId(VetsEntityDtoUtil.verifyId(vetBillId))
.map(ResponseEntity::ok)
.defaultIfEmpty(ResponseEntity.notFound().build());
Expand Down Expand Up @@ -539,10 +590,10 @@
.defaultIfEmpty(ResponseEntity.notFound().build());
}

/**

Check warning on line 593 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Dangling Javadoc comment

Dangling Javadoc comment
* End of Vet Methods
**/
//

Check notice on line 596 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (16 lines)
// @DeleteMapping(value = "users/{userId}")
// public Mono<UserDetails> deleteUser(@RequestHeader(AUTHORIZATION) String auth, final @PathVariable long userId) {
// return authServiceClient.deleteUser(auth, userId);
Expand Down Expand Up @@ -632,7 +683,7 @@
}


// @PostMapping(value = "owners",

Check notice on line 686 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (6 lines)
// consumes = "application/json",
// produces = "application/json")
// public Mono<OwnerResponseDTO> createOwner(@RequestBody OwnerResponseDTO model){
Expand All @@ -646,12 +697,12 @@
.defaultIfEmpty(ResponseEntity.badRequest().build());
}

/*@GetMapping(value = "owners/photo/{ownerId}")

Check notice on line 700 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (4 lines)
public Mono<PhotoDetails> getOwnerPhoto(@PathVariable int ownerId) {
return customersServiceClient.getOwnerPhoto(ownerId);
}*/

// @PostMapping(value = "owners/{ownerId}/pet/photo/{petId}")

Check notice on line 705 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (19 lines)
// public Mono<String> setPetPhoto(@PathVariable String ownerId, @RequestBody PhotoDetails photoDetails, @PathVariable String petId) {
// return customersServiceClient.setPetPhoto(ownerId, photoDetails, petId);
// }
Expand All @@ -675,7 +726,7 @@



/*

Check notice on line 729 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (9 lines)

// Endpoint to update an owner
@PutMapping("owners/{ownerId}")
Expand Down Expand Up @@ -710,7 +761,7 @@
.defaultIfEmpty(ResponseEntity.notFound().build());
}

/**

Check warning on line 764 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Dangling Javadoc comment

Dangling Javadoc comment
* End of Owner Methods
**/

Expand Down
2 changes: 1 addition & 1 deletion api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ app:
host: customers-service-reactive
port: 8080
billing-service:
host: billing
host: billing-service
port: 8080
auth-service:
host: auth
Expand Down
Loading
Loading