From d81758c8d2002f34dd85ae83c946a4b39101530b Mon Sep 17 00:00:00 2001 From: CptDoritos Date: Mon, 23 Oct 2023 17:22:35 -0400 Subject: [PATCH 1/7] Linked Visits Service to Bills Service to display Bill Id and Bill Details upon clicking Bill Id --- .../dtos/Visits/VisitDetails.java | 7 ++- .../dtos/Visits/VisitResponseDTO.java | 2 + .../bffapigateway/dtos/Visits/Visits.java | 8 +++- .../visit-list/visit-list.template.html | 8 ++-- .../VisitsServiceClientIntegrationTest.java | 14 +++--- .../ApiGatewayControllerTest.java | 10 ++-- .../src/main/resources/application.yml | 10 ++-- docker-compose.yml | 12 +++-- .../DataLayer/DataSetupService.java | 47 +++++++++++++++---- .../visitsservicenew/DataLayer/Visit.java | 4 ++ .../DomainClientLayer/BillRequestDTO.java | 23 +++++++++ .../DomainClientLayer/BillResponseDTO.java | 24 ++++++++++ .../DomainClientLayer/BillServiceClient.java | 35 ++++++++++++++ .../DomainClientLayer/BillStatus.java | 8 ++++ .../PresentationLayer/VisitResponseDTO.java | 2 + .../src/main/resources/application.yml | 12 ++++- 16 files changed, 186 insertions(+), 40 deletions(-) create mode 100644 visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillRequestDTO.java create mode 100644 visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillResponseDTO.java create mode 100644 visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java create mode 100644 visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillStatus.java diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitDetails.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitDetails.java index 8dc66bdd0f..65f1780d9b 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitDetails.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitDetails.java @@ -1,17 +1,19 @@ package com.petclinic.bffapigateway.dtos.Visits; + /* -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDateTime; -*/ + */ + /* @author Maciej Szarlinski Copied from https://github.com/spring-petclinic/spring-petclinic-microservices */ + /* @Data @NoArgsConstructor @@ -33,5 +35,6 @@ public class VisitDetails { private String description = null; private Status status = null; + private String billId = null; } */ \ No newline at end of file diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitResponseDTO.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitResponseDTO.java index 2a5a43a4ed..09c9d9bdae 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitResponseDTO.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitResponseDTO.java @@ -20,4 +20,6 @@ public class VisitResponseDTO { private String petId; private String practitionerId; private Status status; + private String billId; + private String customerId; } \ No newline at end of file diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/Visits.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/Visits.java index a57cf9a035..f5e31705a3 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/Visits.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/Visits.java @@ -1,16 +1,20 @@ package com.petclinic.bffapigateway.dtos.Visits; + /* import lombok.Value; import java.util.ArrayList; import java.util.List; -*/ + */ + /* * @author Maciej Szarlinski * Copied from https://github.com/spring-petclinic/spring-petclinic-microservices */ + /* @Value public class Visits { private List items = new ArrayList<>(); } -*/ \ No newline at end of file + + */ diff --git a/api-gateway/src/main/resources/static/scripts/visit-list/visit-list.template.html b/api-gateway/src/main/resources/static/scripts/visit-list/visit-list.template.html index 4dcd506331..143d6ff7df 100644 --- a/api-gateway/src/main/resources/static/scripts/visit-list/visit-list.template.html +++ b/api-gateway/src/main/resources/static/scripts/visit-list/visit-list.template.html @@ -110,7 +110,7 @@

Upcoming Visits

{{v.practitionerId}} {{v.petId}} - + {{v.billId}} {{v.status}} Confirmed Visits {{v.practitionerId}} {{v.petId}} - + {{v.billId}} {{v.status}} Cancelled Visits {{v.practitionerId}} {{v.petId}} - + {{v.billId}} {{v.status}} Completed Visits {{v.practitionerId}} {{v.petId}} - + {{v.billId}} {{v.status}} visits = visitsServiceClient.getVisitsForPet("2"); @@ -258,7 +260,7 @@ void getVisitsForPet() throws Exception { } @Test void getVisitById() throws Exception { - VisitResponseDTO visitResponseDTO = new VisitResponseDTO("773fa7b2-e04e-47b8-98e7-4adf7cfaaeee", LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING); + VisitResponseDTO visitResponseDTO = new VisitResponseDTO("773fa7b2-e04e-47b8-98e7-4adf7cfaaeee", LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING, "2", "2"); server.enqueue(new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setBody(objectMapper.writeValueAsString(visitResponseDTO)).addHeader("Content-Type", "application/json")); Mono visitResponseDTOMono = visitsServiceClient.getVisitByVisitId("773fa7b2-e04e-47b8-98e7-4adf7cfaaeee"); diff --git a/api-gateway/src/test/java/com/petclinic/bffapigateway/presentationlayer/ApiGatewayControllerTest.java b/api-gateway/src/test/java/com/petclinic/bffapigateway/presentationlayer/ApiGatewayControllerTest.java index 4a085bf069..13f9decae3 100755 --- a/api-gateway/src/test/java/com/petclinic/bffapigateway/presentationlayer/ApiGatewayControllerTest.java +++ b/api-gateway/src/test/java/com/petclinic/bffapigateway/presentationlayer/ApiGatewayControllerTest.java @@ -51,13 +51,11 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import org.springframework.web.server.ResponseStatusException; import org.springframework.web.util.UriComponentsBuilder; import org.webjars.NotFoundException; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import javax.print.attribute.standard.Media; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; @@ -2288,8 +2286,8 @@ void ShouldUpdateStatusForVisitByVisitId(){ } @Test void shouldGetAllVisits() { - VisitResponseDTO visitResponseDTO = new VisitResponseDTO("73b5c112-5703-4fb7-b7bc-ac8186811ae1", LocalDateTime.parse("2022-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING); - VisitResponseDTO visitResponseDTO2 = new VisitResponseDTO("73b5c112-5703-4fb7-b7bc-ac8186811ae1", LocalDateTime.parse("2022-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING); + VisitResponseDTO visitResponseDTO = new VisitResponseDTO("73b5c112-5703-4fb7-b7bc-ac8186811ae1", LocalDateTime.parse("2022-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING, "2", "2"); + VisitResponseDTO visitResponseDTO2 = new VisitResponseDTO("73b5c112-5703-4fb7-b7bc-ac8186811ae1", LocalDateTime.parse("2022-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING, "2", "2"); when(visitsServiceClient.getAllVisits()).thenReturn(Flux.just(visitResponseDTO,visitResponseDTO2)); client.get() @@ -2337,7 +2335,7 @@ void getVisitsByOwnerId_shouldReturnOk(){ } @Test void shouldGetAVisit() { - VisitResponseDTO visit = new VisitResponseDTO("73b5c112-5703-4fb7-b7bc-ac8186811ae1", LocalDateTime.parse("2022-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING); + VisitResponseDTO visit = new VisitResponseDTO("73b5c112-5703-4fb7-b7bc-ac8186811ae1", LocalDateTime.parse("2022-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING, "2", "2"); when(visitsServiceClient.getVisitsForPet(visit.getPetId())) .thenReturn(Flux.just(visit)); @@ -2421,7 +2419,7 @@ void shouldGetAVisitByPractitionerIdAndMonth(){ @Test void getSingleVisit_Valid() { - VisitResponseDTO visitResponseDTO = new VisitResponseDTO("73b5c112-5703-4fb7-b7bc-ac8186811ae1", LocalDateTime.parse("2022-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING); + VisitResponseDTO visitResponseDTO = new VisitResponseDTO("73b5c112-5703-4fb7-b7bc-ac8186811ae1", LocalDateTime.parse("2022-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")), "this is a dummy description", "2", "2", Status.UPCOMING, "2", "2"); when(visitsServiceClient.getVisitByVisitId(anyString())).thenReturn(Mono.just(visitResponseDTO)); client.get() diff --git a/billing-service/src/main/resources/application.yml b/billing-service/src/main/resources/application.yml index 9045c2ac66..9810e29bd3 100644 --- a/billing-service/src/main/resources/application.yml +++ b/billing-service/src/main/resources/application.yml @@ -50,7 +50,7 @@ spring: username: root password: password authentication-database: admin -#server.port: 8080 +server.port: 8080 #app: # vet-service: # host: localhost @@ -59,10 +59,10 @@ spring: # host: localhost # port: 8080 # -#logging: -# level: -# root: INFO -# com.petclinic: DEBUG +logging: + level: + root: INFO + com.petclinic: DEBUG #server: # error: diff --git a/docker-compose.yml b/docker-compose.yml index b04dd18273..87c2859cd6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker depends_on: + - billing-service - mongo2 # visits: @@ -65,6 +66,7 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker depends_on: + - billing-service - customers-service-reactive - vet-service - visits-service-new @@ -263,11 +265,11 @@ services: environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: password - # healthcheck: - # test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet - # retries: 5 - # interval: 15s - # start_period: 30s + healthcheck: + test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet + retries: 5 + interval: 15s + start_period: 30s mongo-express1: image: mongo-express diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java index 2a8d024dc6..20314bdaf4 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java @@ -1,31 +1,59 @@ package com.petclinic.visits.visitsservicenew.DataLayer; +import com.petclinic.visits.visitsservicenew.DomainClientLayer.BillResponseDTO; +import com.petclinic.visits.visitsservicenew.DomainClientLayer.BillServiceClient; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.List; + @Service @RequiredArgsConstructor public class DataSetupService implements CommandLineRunner { private final VisitRepo visitRepo; + @Autowired + private BillServiceClient billServiceClient; + + List billResponseList; + + List customerResponseList; + @Override public void run(String... args) throws Exception { - Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED); - Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED); - Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED); - Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "1", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING); - Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING); - Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animal Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING); - Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED); + + Flux billResponseFlux = billServiceClient.getAllBilling(); + + Mono> billResponseListMono = billResponseFlux.flatMap(s -> { + return Mono.just(s.getBillId()); + }).collectList(); + + billResponseList = billResponseListMono.block(); + + Mono> customerResponseListMono = billResponseFlux.flatMap(s -> { + return Mono.just(s.getCustomerId()); + }).collectList(); + + customerResponseList = customerResponseListMono.block(); + + Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(0), customerResponseList.get(0)); + Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(2), customerResponseList.get(2)); + Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(3), customerResponseList.get(3)); + Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "1", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(4), customerResponseList.get(4)); + Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(3), customerResponseList.get(3)); + Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animals Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(1), customerResponseList.get(1)); + Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED, billResponseList.get(2), customerResponseList.get(2)); Flux.just(visit1, visit2, visit3, visit4, visit5, visit6, visit7).flatMap(x -> visitRepo.insert(Mono.just(x)).log(x.toString())).subscribe(); + } - private Visit buildVisit(String visitId, String visitDate, String description, String petId, String practitionerId, Status status){ + private Visit buildVisit(String visitId, String visitDate, String description, String petId, String practitionerId, Status status, String billId, String customerId){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); LocalDateTime parsedVisitDate = LocalDateTime.parse(visitDate, formatter); @@ -36,7 +64,8 @@ private Visit buildVisit(String visitId, String visitDate, String description, S .petId(petId) .practitionerId(practitionerId) .status(status) + .billId(billId) + .customerId(customerId) .build(); } - } \ No newline at end of file diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/Visit.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/Visit.java index f42e6ad8a8..188e197d3d 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/Visit.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/Visit.java @@ -28,4 +28,8 @@ public class Visit { private Status status; + private String billId; + + private String customerId; + } diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillRequestDTO.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillRequestDTO.java new file mode 100644 index 0000000000..8e80a94d44 --- /dev/null +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillRequestDTO.java @@ -0,0 +1,23 @@ +package com.petclinic.visits.visitsservicenew.DomainClientLayer; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class BillRequestDTO { + + private String customerId; + private String visitType; + private String vetId; + private LocalDate date; + private double amount; + private BillStatus billStatus; + private LocalDate dueDate; +} diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillResponseDTO.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillResponseDTO.java new file mode 100644 index 0000000000..dab559cfe4 --- /dev/null +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillResponseDTO.java @@ -0,0 +1,24 @@ +package com.petclinic.visits.visitsservicenew.DomainClientLayer; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class BillResponseDTO { + + private String billId; + private String customerId; + private String visitType; + private String vetId; + private LocalDate date; + private double amount; + private BillStatus billStatus; + private LocalDate dueDate; +} diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java new file mode 100644 index 0000000000..46e8199596 --- /dev/null +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java @@ -0,0 +1,35 @@ +package com.petclinic.visits.visitsservicenew.DomainClientLayer; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Flux; + + +@Component +public class BillServiceClient { + + private final WebClient.Builder webClientBuilder; + private final String billServiceUrl; + + + public BillServiceClient( + WebClient.Builder webClientBuilder, + @Value("${app.billing-service.host}") String billingServiceHost, + @Value("${app.billing-service.port}") String billingServicePort + ) { + this.webClientBuilder = webClientBuilder; + + billServiceUrl = "http://" + billingServiceHost + ":" + billingServicePort + "/bills"; + + } + public Flux getAllBilling() { + return webClientBuilder.build().get() + .uri(billServiceUrl) + .retrieve() + .bodyToFlux(BillResponseDTO.class); + } + +} + + diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillStatus.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillStatus.java new file mode 100644 index 0000000000..c72275d662 --- /dev/null +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillStatus.java @@ -0,0 +1,8 @@ +package com.petclinic.visits.visitsservicenew.DomainClientLayer; + +public enum BillStatus { + + PAID, + UNPAID, + OVERDUE +} diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/PresentationLayer/VisitResponseDTO.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/PresentationLayer/VisitResponseDTO.java index 3790540737..6f87a2be96 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/PresentationLayer/VisitResponseDTO.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/PresentationLayer/VisitResponseDTO.java @@ -25,4 +25,6 @@ public class VisitResponseDTO { private String petId; private String practitionerId; private Status status; + private String billId; + private String customerId; } \ No newline at end of file diff --git a/visits-service-new/src/main/resources/application.yml b/visits-service-new/src/main/resources/application.yml index 68a98165df..56416800bb 100644 --- a/visits-service-new/src/main/resources/application.yml +++ b/visits-service-new/src/main/resources/application.yml @@ -8,6 +8,9 @@ app: customers-service-reactive: host: localhost port: 8090 + billing-service: + host: localhost + port: 7004 logging: @@ -67,7 +70,14 @@ app: host: customers-service-reactive port: 8080 + billing-service: + host: billing-service + port: 8080 + logging: level: root: INFO - com.petclinic: DEBUG \ No newline at end of file + com.petclinic: DEBUG + +server: + port: 8080 From 78a31f1d8a762500ad5c0011eba6ccc2f495e6f7 Mon Sep 17 00:00:00 2001 From: William Chalifoux Date: Mon, 23 Oct 2023 21:13:57 -0400 Subject: [PATCH 2/7] Got dataSetupService working with async bill call --- .../presentationlayer/BillResource.java | 1 + .../src/main/resources/application.yml | 3 +- docker-compose.yml | 22 ++++----- .../DataLayer/DataSetupService.java | 45 +++++++------------ .../DomainClientLayer/BillServiceClient.java | 26 ++++------- 5 files changed, 40 insertions(+), 57 deletions(-) diff --git a/billing-service/src/main/java/com/petclinic/billing/presentationlayer/BillResource.java b/billing-service/src/main/java/com/petclinic/billing/presentationlayer/BillResource.java index f6158b6040..65d2fad41e 100644 --- a/billing-service/src/main/java/com/petclinic/billing/presentationlayer/BillResource.java +++ b/billing-service/src/main/java/com/petclinic/billing/presentationlayer/BillResource.java @@ -14,6 +14,7 @@ import javax.validation.Valid; @RestController +@RequestMapping("") @Slf4j public class BillResource { private final BillService SERVICE; diff --git a/billing-service/src/main/resources/application.yml b/billing-service/src/main/resources/application.yml index 9810e29bd3..81e3410b3d 100644 --- a/billing-service/src/main/resources/application.yml +++ b/billing-service/src/main/resources/application.yml @@ -1,4 +1,5 @@ server.port: 7004 +server.error.include-message: always logging: level: @@ -44,7 +45,7 @@ spring: on-profile: docker data: mongodb: - host: mongo + host: mongo1 port: 27017 database: billings username: root diff --git a/docker-compose.yml b/docker-compose.yml index 87c2859cd6..c7e6858b4b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,17 @@ services: - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ./nginx/njs:/etc/nginx/njs + billing-service: + build: billing-service +# hostname: billing + #mem_limit: 350m + environment: + - SPRING_PROFILES_ACTIVE=docker + depends_on: + - mongo1 + # mysql5: + # condition: service_healthy + visits-service-new: build: visits-service-new environment: @@ -84,16 +95,7 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker - billing-service: - build: billing-service - hostname: billing - #mem_limit: 350m - environment: - - SPRING_PROFILES_ACTIVE=docker - depends_on: - - mongo1 - # mysql5: - # condition: service_healthy + mailer-service: build: mailer-service diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java index 20314bdaf4..5c4b78ea96 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java @@ -10,6 +10,7 @@ import reactor.core.publisher.Mono; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.List; @@ -20,37 +21,25 @@ public class DataSetupService implements CommandLineRunner { @Autowired private BillServiceClient billServiceClient; - List billResponseList; - - List customerResponseList; - @Override public void run(String... args) throws Exception { - Flux billResponseFlux = billServiceClient.getAllBilling(); - - Mono> billResponseListMono = billResponseFlux.flatMap(s -> { - return Mono.just(s.getBillId()); - }).collectList(); - - billResponseList = billResponseListMono.block(); - - Mono> customerResponseListMono = billResponseFlux.flatMap(s -> { - return Mono.just(s.getCustomerId()); - }).collectList(); - - customerResponseList = customerResponseListMono.block(); - - Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(0), customerResponseList.get(0)); - Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(2), customerResponseList.get(2)); - Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(3), customerResponseList.get(3)); - Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "1", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(4), customerResponseList.get(4)); - Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(3), customerResponseList.get(3)); - Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animals Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(1), customerResponseList.get(1)); - Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED, billResponseList.get(2), customerResponseList.get(2)); - - Flux.just(visit1, visit2, visit3, visit4, visit5, visit6, visit7).flatMap(x -> visitRepo.insert(Mono.just(x)).log(x.toString())).subscribe(); - + List billResponseList=new ArrayList<>(); + List customerResponseList=new ArrayList<>(); + billServiceClient.getAllBilling().flatMap(s -> { + billResponseList.add(s.getBillId()); + customerResponseList.add(s.getCustomerId()); + return Mono.just(s); + }).subscribe(s->{ + Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(1), customerResponseList.get(1)); + Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(2), customerResponseList.get(2)); + Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(3), customerResponseList.get(3)); + Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "1", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(4), customerResponseList.get(4)); + Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(3), customerResponseList.get(3)); + Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animals Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(1), customerResponseList.get(1)); + Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED, billResponseList.get(2), customerResponseList.get(2)); + Flux.just(visit1, visit2, visit3, visit4, visit5, visit6, visit7).flatMap(x -> visitRepo.insert(Mono.just(x)).log(x.toString())).subscribe(); + }); } private Visit buildVisit(String visitId, String visitDate, String description, String petId, String practitionerId, Status status, String billId, String customerId){ diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java index 46e8199596..53e0dd79bc 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java @@ -1,35 +1,25 @@ package com.petclinic.visits.visitsservicenew.DomainClientLayer; import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; -@Component +@Service public class BillServiceClient { - - private final WebClient.Builder webClientBuilder; - private final String billServiceUrl; - - + private final WebClient webClient; public BillServiceClient( - WebClient.Builder webClientBuilder, @Value("${app.billing-service.host}") String billingServiceHost, @Value("${app.billing-service.port}") String billingServicePort ) { - this.webClientBuilder = webClientBuilder; - - billServiceUrl = "http://" + billingServiceHost + ":" + billingServicePort + "/bills"; - +// this.webClient = WebClient.builder().baseUrl("http://" + billingServiceHost + ":" + billingServicePort).build(); + this.webClient = WebClient.builder().baseUrl("http://" + "localhost" + ":" + "7004").build(); } public Flux getAllBilling() { - return webClientBuilder.build().get() - .uri(billServiceUrl) + return webClient.get() + .uri("/bills") .retrieve() .bodyToFlux(BillResponseDTO.class); } - -} - - +} \ No newline at end of file From c601495a17b40c69298591dc80e152956223a660 Mon Sep 17 00:00:00 2001 From: CptDoritos Date: Mon, 23 Oct 2023 17:22:35 -0400 Subject: [PATCH 3/7] Rebasing Process Part 1 --- .../dtos/Visits/VisitDetails.java | 7 +- .../dtos/Visits/VisitResponseDTO.java | 2 + .../bffapigateway/dtos/Visits/Visits.java | 8 +- .../visit-list/visit-list.template.html | 6 +- .../ApiGatewayControllerTest.java | 138 +----------------- docker-compose.yml | 12 +- .../DataLayer/DataSetupService.java | 47 ++++-- .../visitsservicenew/DataLayer/Visit.java | 4 + .../DomainClientLayer/BillRequestDTO.java | 23 +++ .../DomainClientLayer/BillResponseDTO.java | 24 +++ .../DomainClientLayer/BillServiceClient.java | 35 +++++ .../DomainClientLayer/BillStatus.java | 8 + .../PresentationLayer/VisitResponseDTO.java | 2 + .../src/main/resources/application.yml | 7 + 14 files changed, 165 insertions(+), 158 deletions(-) create mode 100644 visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillRequestDTO.java create mode 100644 visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillResponseDTO.java create mode 100644 visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java create mode 100644 visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillStatus.java diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitDetails.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitDetails.java index 8dc66bdd0f..65f1780d9b 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitDetails.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitDetails.java @@ -1,17 +1,19 @@ package com.petclinic.bffapigateway.dtos.Visits; + /* -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDateTime; -*/ + */ + /* @author Maciej Szarlinski Copied from https://github.com/spring-petclinic/spring-petclinic-microservices */ + /* @Data @NoArgsConstructor @@ -33,5 +35,6 @@ public class VisitDetails { private String description = null; private Status status = null; + private String billId = null; } */ \ No newline at end of file diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitResponseDTO.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitResponseDTO.java index fe2f6c9579..bd76420c31 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitResponseDTO.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/VisitResponseDTO.java @@ -28,4 +28,6 @@ public class VisitResponseDTO { private String vetEmail; private String vetPhoneNumber; private Status status; + private String billId; + private String customerId; } \ No newline at end of file diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/Visits.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/Visits.java index a57cf9a035..f5e31705a3 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/Visits.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Visits/Visits.java @@ -1,16 +1,20 @@ package com.petclinic.bffapigateway.dtos.Visits; + /* import lombok.Value; import java.util.ArrayList; import java.util.List; -*/ + */ + /* * @author Maciej Szarlinski * Copied from https://github.com/spring-petclinic/spring-petclinic-microservices */ + /* @Value public class Visits { private List items = new ArrayList<>(); } -*/ \ No newline at end of file + + */ diff --git a/api-gateway/src/main/resources/static/scripts/visit-list/visit-list.template.html b/api-gateway/src/main/resources/static/scripts/visit-list/visit-list.template.html index 78b10b6f32..fe4be3d7f2 100644 --- a/api-gateway/src/main/resources/static/scripts/visit-list/visit-list.template.html +++ b/api-gateway/src/main/resources/static/scripts/visit-list/visit-list.template.html @@ -172,7 +172,7 @@

Confirmed Visits

{{v.vetFirstName}} {{v.vetLastName}} {{v.petName}} - +
{{v.billId}} {{v.status}} Cancelled Visits {{v.vetFirstName}} {{v.vetLastName}} {{v.petName}} - + {{v.billId}} {{v.status}} Completed Visits {{v.vetFirstName}} {{v.vetLastName}} {{v.petName}} - + {{v.billId}} {{v.status}} { - Assertions.assertTrue(response.getResponseBody().size() > 0); - VisitResponseDTO responseBody = response.getResponseBody().get(0); - // Asserting that the values match what's expected - Assertions.assertEquals(visitResponseDTO.getVisitId(), responseBody.getVisitId()); - Assertions.assertEquals(visitResponseDTO.getPetId(), responseBody.getPetId()); - Assertions.assertEquals(visitResponseDTO.getVisitDate(), responseBody.getVisitDate()); - Assertions.assertEquals(visitResponseDTO.getDescription(), responseBody.getDescription()); - Assertions.assertEquals(visitResponseDTO.getPractitionerId(), responseBody.getPractitionerId()); - }); - } - - @Test - void getVisitsByPractitionerId_Valid() { - VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder() - .visitId("73b5c112-5703-4fb7-b7bc-ac8186811ae1") - .visitDate(LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))) - .description("this is a dummy description") - .petId("2") - .petName("YourPetNameHere") - .petBirthDate(new Date()) - .practitionerId("2") - .vetFirstName("VetFirstNameHere") - .vetLastName("VetLastNameHere") - .vetEmail("vet@email.com") - .vetPhoneNumber("123-456-7890") - .status(Status.UPCOMING) - .build(); - - when(visitsServiceClient.getVisitByPractitionerId(visitResponseDTO.getPractitionerId())).thenReturn(Flux.just(visitResponseDTO)); - - client.get() - .uri("/api/gateway/visits/vets/{practitionerId}", visitResponseDTO.getPractitionerId()) - .exchange() - .expectStatus().isOk() - .expectBodyList(VisitResponseDTO.class) - .consumeWith(response -> { - Assertions.assertTrue(response.getResponseBody().size() > 0); - VisitResponseDTO responseBody = response.getResponseBody().get(0); - - Assertions.assertEquals(visitResponseDTO.getVisitId(), responseBody.getVisitId()); - Assertions.assertEquals(visitResponseDTO.getPetId(), responseBody.getPetId()); - Assertions.assertEquals(visitResponseDTO.getVisitDate(), responseBody.getVisitDate()); - Assertions.assertEquals(visitResponseDTO.getDescription(), responseBody.getDescription()); - Assertions.assertEquals(visitResponseDTO.getPractitionerId(), responseBody.getPractitionerId()); - }); - } - // @Test // void getSingleVisit_Invalid() { @@ -3121,35 +3047,6 @@ void login_invalid() throws Exception { } - @Test - @DisplayName("Should Logout with a Valid Session, Clearing Bearer Cookie, and Returning 204") - void logout_shouldClearBearerCookie() { - MultiValueMap headers = new LinkedMultiValueMap<>(); - headers.add(HttpHeaders.COOKIE, "Bearer=some.token.value; Path=/; HttpOnly; SameSite=Lax"); - when(authServiceClient.logout(any(ServerHttpRequest.class), any(ServerHttpResponse.class))) - .thenReturn(Mono.just(ResponseEntity.noContent().build())); - client.post() - .uri("/api/gateway/users/logout") - .headers(httpHeaders -> httpHeaders.putAll(headers)) - .exchange() - .expectStatus().isNoContent() - .expectHeader().doesNotExist(HttpHeaders.SET_COOKIE); - } - - @Test - @DisplayName("Given Expired Session, Logout Should Return 401") - void logout_shouldReturnUnauthorizedForExpiredSession() { - MultiValueMap headers = new LinkedMultiValueMap<>(); - when(authServiceClient.logout(any(ServerHttpRequest.class), any(ServerHttpResponse.class))) - .thenReturn(Mono.just(ResponseEntity.status(HttpStatus.UNAUTHORIZED).build())); - client.post() - .uri("/api/gateway/users/logout") - .headers(httpHeaders -> httpHeaders.putAll(headers)) - .exchange() - .expectStatus().isUnauthorized() - .expectHeader().doesNotExist(HttpHeaders.SET_COOKIE); - } - private InventoryResponseDTO buildInventoryDTO(){ return InventoryResponseDTO.builder() @@ -3530,9 +3427,6 @@ void testAddProductToInventory_InvalidInventoryId_ShouldReturnNotFoundException( - - - private ProductResponseDTO buildProductDTO(){ return ProductResponseDTO.builder() .id("1") @@ -3555,11 +3449,6 @@ private VetResponseDTO buildVetResponseDTO() { .phoneNumber("947-238-2847") .resume("Just became a vet") .workday(new HashSet<>()) - .workHoursJson("{\n" + - " \"Monday\": [\"Hour_8_9\",\"Hour_9_10\",\"Hour_10_11\",\"Hour_11_12\",\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\"],\n" + - " \"Wednesday\": [\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\",\"Hour_16_17\",\"Hour_17_18\",\"Hour_18_19\",\"Hour_19_20\"],\n" + - " \"Thursday\": [\"Hour_10_11\",\"Hour_11_12\",\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\",\"Hour_16_17\",\"Hour_17_18\"]\n" + - " }") .specialties(new HashSet<>()) .active(false) .build(); @@ -3573,11 +3462,6 @@ private VetResponseDTO buildVetResponseDTO2() { .phoneNumber("947-238-2847") .resume("Just became a vet") .workday(new HashSet<>()) - .workHoursJson("{\n" + - " \"Monday\": [\"Hour_8_9\",\"Hour_9_10\",\"Hour_10_11\",\"Hour_11_12\",\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\"],\n" + - " \"Wednesday\": [\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\",\"Hour_16_17\",\"Hour_17_18\",\"Hour_18_19\",\"Hour_19_20\"],\n" + - " \"Thursday\": [\"Hour_10_11\",\"Hour_11_12\",\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\",\"Hour_16_17\",\"Hour_17_18\"]\n" + - " }") .specialties(new HashSet<>()) .active(true) .build(); @@ -3881,26 +3765,6 @@ public void getUserById_ValidUserId_ShouldReturnUser() { assertEquals(userDetails.getEmail(), u.getEmail()); }); } - - @Test - void deleteUserById_ValidUserId_ShouldDeleteUser() { - UserDetails userDetails = UserDetails.builder() - .userId("validUserId") - .username("validUsername") - .email("validEmail") - .build(); - - when(authServiceClient.deleteUser(anyString(), anyString())) - .thenReturn(Mono.empty()); - - client.delete() - .uri("/api/gateway/users/validUserId") - .cookie("Bearer", "validToken") - .exchange() - .expectStatus().isNoContent(); - } - - private EducationResponseDTO buildEducation(){ return EducationResponseDTO.builder() .educationId("1") diff --git a/docker-compose.yml b/docker-compose.yml index 08c4acc8f7..e60df5a99c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker depends_on: + - billing-service - mongo2 - mailer-service @@ -46,6 +47,7 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker depends_on: + - billing-service - customers-service-reactive - vet-service - visits-service-new @@ -263,11 +265,11 @@ services: environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: password - # healthcheck: - # test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet - # retries: 5 - # interval: 15s - # start_period: 30s + healthcheck: + test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet + retries: 5 + interval: 15s + start_period: 30s mongo-express1: image: mongo-express diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java index 1c09f062f3..20314bdaf4 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java @@ -1,31 +1,59 @@ package com.petclinic.visits.visitsservicenew.DataLayer; +import com.petclinic.visits.visitsservicenew.DomainClientLayer.BillResponseDTO; +import com.petclinic.visits.visitsservicenew.DomainClientLayer.BillServiceClient; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.List; + @Service @RequiredArgsConstructor public class DataSetupService implements CommandLineRunner { private final VisitRepo visitRepo; + @Autowired + private BillServiceClient billServiceClient; + + List billResponseList; + + List customerResponseList; + @Override public void run(String... args) throws Exception { - Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "ecb109cd-57ea-4b85-b51e-99751fd1c349", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED); - Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "0e4d8481-b611-4e52-baed-af16caa8bf8a", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED); - Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "0e4d8481-b611-4e52-baed-af16caa8bf8a", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED); - Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "0e4d8481-b611-4e52-baed-af16caa8bf8a", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING); - Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "53163352-8398-4513-bdff-b7715c056d1d", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING); - Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animal Needs Operation", "53163352-8398-4513-bdff-b7715c056d1d", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING); - Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "7056652d-f2fd-4873-a480-5d2e86bed641", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED); + + Flux billResponseFlux = billServiceClient.getAllBilling(); + + Mono> billResponseListMono = billResponseFlux.flatMap(s -> { + return Mono.just(s.getBillId()); + }).collectList(); + + billResponseList = billResponseListMono.block(); + + Mono> customerResponseListMono = billResponseFlux.flatMap(s -> { + return Mono.just(s.getCustomerId()); + }).collectList(); + + customerResponseList = customerResponseListMono.block(); + + Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(0), customerResponseList.get(0)); + Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(2), customerResponseList.get(2)); + Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(3), customerResponseList.get(3)); + Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "1", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(4), customerResponseList.get(4)); + Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(3), customerResponseList.get(3)); + Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animals Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(1), customerResponseList.get(1)); + Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED, billResponseList.get(2), customerResponseList.get(2)); Flux.just(visit1, visit2, visit3, visit4, visit5, visit6, visit7).flatMap(x -> visitRepo.insert(Mono.just(x)).log(x.toString())).subscribe(); + } - private Visit buildVisit(String visitId, String visitDate, String description, String petId, String practitionerId, Status status){ + private Visit buildVisit(String visitId, String visitDate, String description, String petId, String practitionerId, Status status, String billId, String customerId){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); LocalDateTime parsedVisitDate = LocalDateTime.parse(visitDate, formatter); @@ -36,7 +64,8 @@ private Visit buildVisit(String visitId, String visitDate, String description, S .petId(petId) .practitionerId(practitionerId) .status(status) + .billId(billId) + .customerId(customerId) .build(); } - } \ No newline at end of file diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/Visit.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/Visit.java index f42e6ad8a8..188e197d3d 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/Visit.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/Visit.java @@ -28,4 +28,8 @@ public class Visit { private Status status; + private String billId; + + private String customerId; + } diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillRequestDTO.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillRequestDTO.java new file mode 100644 index 0000000000..8e80a94d44 --- /dev/null +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillRequestDTO.java @@ -0,0 +1,23 @@ +package com.petclinic.visits.visitsservicenew.DomainClientLayer; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class BillRequestDTO { + + private String customerId; + private String visitType; + private String vetId; + private LocalDate date; + private double amount; + private BillStatus billStatus; + private LocalDate dueDate; +} diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillResponseDTO.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillResponseDTO.java new file mode 100644 index 0000000000..dab559cfe4 --- /dev/null +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillResponseDTO.java @@ -0,0 +1,24 @@ +package com.petclinic.visits.visitsservicenew.DomainClientLayer; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class BillResponseDTO { + + private String billId; + private String customerId; + private String visitType; + private String vetId; + private LocalDate date; + private double amount; + private BillStatus billStatus; + private LocalDate dueDate; +} diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java new file mode 100644 index 0000000000..46e8199596 --- /dev/null +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java @@ -0,0 +1,35 @@ +package com.petclinic.visits.visitsservicenew.DomainClientLayer; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Flux; + + +@Component +public class BillServiceClient { + + private final WebClient.Builder webClientBuilder; + private final String billServiceUrl; + + + public BillServiceClient( + WebClient.Builder webClientBuilder, + @Value("${app.billing-service.host}") String billingServiceHost, + @Value("${app.billing-service.port}") String billingServicePort + ) { + this.webClientBuilder = webClientBuilder; + + billServiceUrl = "http://" + billingServiceHost + ":" + billingServicePort + "/bills"; + + } + public Flux getAllBilling() { + return webClientBuilder.build().get() + .uri(billServiceUrl) + .retrieve() + .bodyToFlux(BillResponseDTO.class); + } + +} + + diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillStatus.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillStatus.java new file mode 100644 index 0000000000..c72275d662 --- /dev/null +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillStatus.java @@ -0,0 +1,8 @@ +package com.petclinic.visits.visitsservicenew.DomainClientLayer; + +public enum BillStatus { + + PAID, + UNPAID, + OVERDUE +} diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/PresentationLayer/VisitResponseDTO.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/PresentationLayer/VisitResponseDTO.java index 5d549b71f5..0fa1c3c3b9 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/PresentationLayer/VisitResponseDTO.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/PresentationLayer/VisitResponseDTO.java @@ -29,4 +29,6 @@ public class VisitResponseDTO { private String vetEmail; private String vetPhoneNumber; private Status status; + private String billId; + private String customerId; } \ No newline at end of file diff --git a/visits-service-new/src/main/resources/application.yml b/visits-service-new/src/main/resources/application.yml index 6a3ff3720b..5401efe891 100644 --- a/visits-service-new/src/main/resources/application.yml +++ b/visits-service-new/src/main/resources/application.yml @@ -8,6 +8,9 @@ app: customers-service-reactive: host: localhost port: 8090 + billing-service: + host: localhost + port: 7004 auth-service: host: localhost port: 7005 @@ -78,6 +81,10 @@ app: host: mailer-service port: 8080 + billing-service: + host: billing-service + port: 8080 + logging: level: root: INFO From 66aa727f5960d47043de168d5dd57b78a615e98a Mon Sep 17 00:00:00 2001 From: William Chalifoux Date: Mon, 23 Oct 2023 21:13:57 -0400 Subject: [PATCH 4/7] Got dataSetupService working with async bill call --- .../presentationlayer/BillResource.java | 1 + .../src/main/resources/application.yml | 3 +- docker-compose.yml | 22 ++++----- .../DataLayer/DataSetupService.java | 45 +++++++------------ .../DomainClientLayer/BillServiceClient.java | 26 ++++------- 5 files changed, 40 insertions(+), 57 deletions(-) diff --git a/billing-service/src/main/java/com/petclinic/billing/presentationlayer/BillResource.java b/billing-service/src/main/java/com/petclinic/billing/presentationlayer/BillResource.java index 4c910da1c2..bb9e08bed2 100644 --- a/billing-service/src/main/java/com/petclinic/billing/presentationlayer/BillResource.java +++ b/billing-service/src/main/java/com/petclinic/billing/presentationlayer/BillResource.java @@ -14,6 +14,7 @@ import javax.validation.Valid; @RestController +@RequestMapping("") @Slf4j public class BillResource { private final BillService SERVICE; diff --git a/billing-service/src/main/resources/application.yml b/billing-service/src/main/resources/application.yml index 5f4fd4a1ea..2549bdbfad 100644 --- a/billing-service/src/main/resources/application.yml +++ b/billing-service/src/main/resources/application.yml @@ -1,4 +1,5 @@ server.port: 7004 +server.error.include-message: always logging: level: @@ -44,7 +45,7 @@ spring: on-profile: docker data: mongodb: - host: mongo + host: mongo1 port: 27017 database: billings username: root diff --git a/docker-compose.yml b/docker-compose.yml index e60df5a99c..22c0abc7ed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,17 @@ services: - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ./nginx/njs:/etc/nginx/njs + billing-service: + build: billing-service +# hostname: billing + #mem_limit: 350m + environment: + - SPRING_PROFILES_ACTIVE=docker + depends_on: + - mongo1 + # mysql5: + # condition: service_healthy + visits-service-new: build: visits-service-new environment: @@ -65,16 +76,7 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker - billing-service: - build: billing-service - hostname: billing - #mem_limit: 350m - environment: - - SPRING_PROFILES_ACTIVE=docker - depends_on: - - mongo1 - # mysql5: - # condition: service_healthy + mailer-service: build: mailer-service diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java index 20314bdaf4..5c4b78ea96 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java @@ -10,6 +10,7 @@ import reactor.core.publisher.Mono; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.List; @@ -20,37 +21,25 @@ public class DataSetupService implements CommandLineRunner { @Autowired private BillServiceClient billServiceClient; - List billResponseList; - - List customerResponseList; - @Override public void run(String... args) throws Exception { - Flux billResponseFlux = billServiceClient.getAllBilling(); - - Mono> billResponseListMono = billResponseFlux.flatMap(s -> { - return Mono.just(s.getBillId()); - }).collectList(); - - billResponseList = billResponseListMono.block(); - - Mono> customerResponseListMono = billResponseFlux.flatMap(s -> { - return Mono.just(s.getCustomerId()); - }).collectList(); - - customerResponseList = customerResponseListMono.block(); - - Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(0), customerResponseList.get(0)); - Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(2), customerResponseList.get(2)); - Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(3), customerResponseList.get(3)); - Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "1", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(4), customerResponseList.get(4)); - Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(3), customerResponseList.get(3)); - Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animals Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(1), customerResponseList.get(1)); - Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED, billResponseList.get(2), customerResponseList.get(2)); - - Flux.just(visit1, visit2, visit3, visit4, visit5, visit6, visit7).flatMap(x -> visitRepo.insert(Mono.just(x)).log(x.toString())).subscribe(); - + List billResponseList=new ArrayList<>(); + List customerResponseList=new ArrayList<>(); + billServiceClient.getAllBilling().flatMap(s -> { + billResponseList.add(s.getBillId()); + customerResponseList.add(s.getCustomerId()); + return Mono.just(s); + }).subscribe(s->{ + Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(1), customerResponseList.get(1)); + Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(2), customerResponseList.get(2)); + Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(3), customerResponseList.get(3)); + Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "1", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(4), customerResponseList.get(4)); + Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(3), customerResponseList.get(3)); + Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animals Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(1), customerResponseList.get(1)); + Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED, billResponseList.get(2), customerResponseList.get(2)); + Flux.just(visit1, visit2, visit3, visit4, visit5, visit6, visit7).flatMap(x -> visitRepo.insert(Mono.just(x)).log(x.toString())).subscribe(); + }); } private Visit buildVisit(String visitId, String visitDate, String description, String petId, String practitionerId, Status status, String billId, String customerId){ diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java index 46e8199596..53e0dd79bc 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java @@ -1,35 +1,25 @@ package com.petclinic.visits.visitsservicenew.DomainClientLayer; import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; -@Component +@Service public class BillServiceClient { - - private final WebClient.Builder webClientBuilder; - private final String billServiceUrl; - - + private final WebClient webClient; public BillServiceClient( - WebClient.Builder webClientBuilder, @Value("${app.billing-service.host}") String billingServiceHost, @Value("${app.billing-service.port}") String billingServicePort ) { - this.webClientBuilder = webClientBuilder; - - billServiceUrl = "http://" + billingServiceHost + ":" + billingServicePort + "/bills"; - +// this.webClient = WebClient.builder().baseUrl("http://" + billingServiceHost + ":" + billingServicePort).build(); + this.webClient = WebClient.builder().baseUrl("http://" + "localhost" + ":" + "7004").build(); } public Flux getAllBilling() { - return webClientBuilder.build().get() - .uri(billServiceUrl) + return webClient.get() + .uri("/bills") .retrieve() .bodyToFlux(BillResponseDTO.class); } - -} - - +} \ No newline at end of file From 0b3aba9c83a33831fbde5f1620f4f7d815e4b9ee Mon Sep 17 00:00:00 2001 From: CptDoritos Date: Mon, 23 Oct 2023 22:44:04 -0400 Subject: [PATCH 5/7] Fixed Database --- .../src/main/resources/application.yml | 2 +- docker-compose.yml | 1 - .../DomainClientLayer/BillServiceClient.java | 36 ++++++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/billing-service/src/main/resources/application.yml b/billing-service/src/main/resources/application.yml index 2549bdbfad..99a2958585 100644 --- a/billing-service/src/main/resources/application.yml +++ b/billing-service/src/main/resources/application.yml @@ -45,7 +45,7 @@ spring: on-profile: docker data: mongodb: - host: mongo1 + host: mongo port: 27017 database: billings username: root diff --git a/docker-compose.yml b/docker-compose.yml index 22c0abc7ed..008cc22c2c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -58,7 +58,6 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker depends_on: - - billing-service - customers-service-reactive - vet-service - visits-service-new diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java index 53e0dd79bc..c4105ff6c7 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java @@ -1,25 +1,45 @@ package com.petclinic.visits.visitsservicenew.DomainClientLayer; import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; -@Service +@Component public class BillServiceClient { - private final WebClient webClient; + + private final WebClient.Builder webClientBuilder; + private final String billServiceUrl; + + public BillServiceClient( + WebClient.Builder webClientBuilder, @Value("${app.billing-service.host}") String billingServiceHost, @Value("${app.billing-service.port}") String billingServicePort ) { -// this.webClient = WebClient.builder().baseUrl("http://" + billingServiceHost + ":" + billingServicePort).build(); - this.webClient = WebClient.builder().baseUrl("http://" + "localhost" + ":" + "7004").build(); + this.webClientBuilder = webClientBuilder; + + billServiceUrl = "http://" + billingServiceHost + ":" + billingServicePort + "/bills"; + } + + public Mono getBilling(final String billId) { + return webClientBuilder.build().get() + .uri(billServiceUrl + "/{billId}", billId) + .retrieve() + .bodyToMono(BillResponseDTO.class); + } + public Flux getAllBilling() { - return webClient.get() - .uri("/bills") + return webClientBuilder.build().get() + .uri(billServiceUrl) .retrieve() .bodyToFlux(BillResponseDTO.class); } -} \ No newline at end of file +} + + From 090abc8f901af34df1499bcf0e63a58656279f6b Mon Sep 17 00:00:00 2001 From: CptDoritos Date: Tue, 24 Oct 2023 00:58:19 -0400 Subject: [PATCH 6/7] Testing Database fixes --- docker-compose.yml | 13 ++++++++----- .../DataLayer/DataSetupService.java | 10 ++++++---- .../DomainClientLayer/BillServiceClient.java | 14 ++------------ 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 008cc22c2c..e0323fdfdd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,8 @@ services: billing-service: build: billing-service + ports: + - "7004:8080" # hostname: billing #mem_limit: 350m environment: @@ -58,6 +60,7 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker depends_on: + - billing-service - customers-service-reactive - vet-service - visits-service-new @@ -266,11 +269,11 @@ services: environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: password - healthcheck: - test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet - retries: 5 - interval: 15s - start_period: 30s + #healthcheck: + #test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet + #retries: 5 + #interval: 15s + #start_period: 30s mongo-express1: image: mongo-express diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java index 5c4b78ea96..e0816cf88f 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java @@ -18,19 +18,22 @@ @RequiredArgsConstructor public class DataSetupService implements CommandLineRunner { private final VisitRepo visitRepo; + + List billResponseList = new ArrayList<>(); + + List customerResponseList = new ArrayList<>(); @Autowired private BillServiceClient billServiceClient; @Override public void run(String... args) throws Exception { - List billResponseList=new ArrayList<>(); - List customerResponseList=new ArrayList<>(); billServiceClient.getAllBilling().flatMap(s -> { billResponseList.add(s.getBillId()); customerResponseList.add(s.getCustomerId()); return Mono.just(s); - }).subscribe(s->{ + }); + Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(1), customerResponseList.get(1)); Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(2), customerResponseList.get(2)); Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(3), customerResponseList.get(3)); @@ -39,7 +42,6 @@ public void run(String... args) throws Exception { Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animals Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(1), customerResponseList.get(1)); Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED, billResponseList.get(2), customerResponseList.get(2)); Flux.just(visit1, visit2, visit3, visit4, visit5, visit6, visit7).flatMap(x -> visitRepo.insert(Mono.just(x)).log(x.toString())).subscribe(); - }); } private Visit buildVisit(String visitId, String visitDate, String description, String petId, String practitionerId, Status status, String billId, String customerId){ diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java index c4105ff6c7..bd13ee9d92 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java @@ -1,15 +1,12 @@ package com.petclinic.visits.visitsservicenew.DomainClientLayer; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -@Component +@Service public class BillServiceClient { private final WebClient.Builder webClientBuilder; @@ -27,13 +24,6 @@ public BillServiceClient( } - public Mono getBilling(final String billId) { - return webClientBuilder.build().get() - .uri(billServiceUrl + "/{billId}", billId) - .retrieve() - .bodyToMono(BillResponseDTO.class); - } - public Flux getAllBilling() { return webClientBuilder.build().get() .uri(billServiceUrl) From 964eae1265e74db7ddc0201bab63a45adcb08810 Mon Sep 17 00:00:00 2001 From: CptDoritos Date: Tue, 24 Oct 2023 02:36:37 -0400 Subject: [PATCH 7/7] Final Fix Commit --- .../billing/datalayer/DataSetupService.java | 4 +- docker-compose.yml | 2 +- .../DataLayer/DataSetupService.java | 53 +++++++++++-------- .../DomainClientLayer/BillServiceClient.java | 6 +-- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/billing-service/src/main/java/com/petclinic/billing/datalayer/DataSetupService.java b/billing-service/src/main/java/com/petclinic/billing/datalayer/DataSetupService.java index c37208315c..5814ed91c8 100644 --- a/billing-service/src/main/java/com/petclinic/billing/datalayer/DataSetupService.java +++ b/billing-service/src/main/java/com/petclinic/billing/datalayer/DataSetupService.java @@ -3,14 +3,14 @@ import com.petclinic.billing.businesslayer.BillService; import org.springframework.boot.CommandLineRunner; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.time.LocalDate; -@Service +@Component public class DataSetupService implements CommandLineRunner { private final BillService billService; public DataSetupService(BillService billService) { diff --git a/docker-compose.yml b/docker-compose.yml index e0323fdfdd..06db9779cb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,7 @@ services: visits-service-new: build: visits-service-new + restart: always environment: - SPRING_PROFILES_ACTIVE=docker depends_on: @@ -60,7 +61,6 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker depends_on: - - billing-service - customers-service-reactive - vet-service - visits-service-new diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java index e0816cf88f..09c59571f3 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DataLayer/DataSetupService.java @@ -5,43 +5,54 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; import java.util.List; -@Service +@Component @RequiredArgsConstructor public class DataSetupService implements CommandLineRunner { private final VisitRepo visitRepo; - - List billResponseList = new ArrayList<>(); - - List customerResponseList = new ArrayList<>(); @Autowired private BillServiceClient billServiceClient; + List billResponseList; + + List customerResponseList; + @Override public void run(String... args) throws Exception { - billServiceClient.getAllBilling().flatMap(s -> { - billResponseList.add(s.getBillId()); - customerResponseList.add(s.getCustomerId()); - return Mono.just(s); - }); - - Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(1), customerResponseList.get(1)); - Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(2), customerResponseList.get(2)); - Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(3), customerResponseList.get(3)); - Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "1", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(4), customerResponseList.get(4)); - Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(3), customerResponseList.get(3)); - Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animals Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(1), customerResponseList.get(1)); - Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED, billResponseList.get(2), customerResponseList.get(2)); - Flux.just(visit1, visit2, visit3, visit4, visit5, visit6, visit7).flatMap(x -> visitRepo.insert(Mono.just(x)).log(x.toString())).subscribe(); + Flux billResponseFlux = billServiceClient.getAllBilling(); + + Mono> customerResponseListMono = billResponseFlux.flatMap(s -> { + return Mono.just(s.getCustomerId()); + }).collectList(); + + customerResponseList = customerResponseListMono.block(); + + + Mono> billResponseListMono = billResponseFlux.flatMap(s -> { + return Mono.just(s.getBillId()); + }).collectList(); + + billResponseList = billResponseListMono.block(); + + Visit visit1 = buildVisit("visitId1", "2022-11-24 13:00", "this is a dummy description", "2", "69f852ca-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(0), customerResponseList.get(0)); + Visit visit2 = buildVisit("visitId2", "2022-03-01 13:00", "Dog Needs Meds", "1", "69f85766-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(2), customerResponseList.get(2)); + Visit visit3 = buildVisit("visitId3", "2020-07-19 13:00","Dog Needs Surgery After Meds", "1", "69f85bda-625b-11ee-8c99-0242ac120002", Status.COMPLETED, billResponseList.get(3), customerResponseList.get(3)); + Visit visit4 = buildVisit("visitId4", "2022-12-24 13:00", "Dog Needs Physio-Therapy", "1", "69f85d2e-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(4), customerResponseList.get(4)); + Visit visit5 = buildVisit("visitId5", "2023-12-24 13:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(3), customerResponseList.get(3)); + Visit visit6 = buildVisit("visitId6", "2023-12-05 15:00", "Animals Needs Operation", "3", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.UPCOMING, billResponseList.get(1), customerResponseList.get(1)); + Visit visit7 = buildVisit("visitId7", "2022-05-20 09:00", "Cat Needs Check-Up", "4", "ac9adeb8-625b-11ee-8c99-0242ac120002", Status.CONFIRMED, billResponseList.get(2), customerResponseList.get(2)); + + + Flux.just(visit1, visit2, visit3, visit4, visit5, visit6, visit7).flatMap(x -> visitRepo.insert(Mono.just(x)).log(x.toString())).subscribe(); + } private Visit buildVisit(String visitId, String visitDate, String description, String petId, String practitionerId, Status status, String billId, String customerId){ diff --git a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java index bd13ee9d92..46e8199596 100644 --- a/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java +++ b/visits-service-new/src/main/java/com/petclinic/visits/visitsservicenew/DomainClientLayer/BillServiceClient.java @@ -1,12 +1,12 @@ package com.petclinic.visits.visitsservicenew.DomainClientLayer; import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; -@Service +@Component public class BillServiceClient { private final WebClient.Builder webClientBuilder; @@ -23,13 +23,13 @@ public BillServiceClient( billServiceUrl = "http://" + billingServiceHost + ":" + billingServicePort + "/bills"; } - public Flux getAllBilling() { return webClientBuilder.build().get() .uri(billServiceUrl) .retrieve() .bodyToFlux(BillResponseDTO.class); } + }