Skip to content

Commit

Permalink
Merge branch 'main' into feat/CUST-CPC-1075_Being_Able_To_Add_A_Custo…
Browse files Browse the repository at this point in the history
…mer_To_The_Website
  • Loading branch information
NotZagreus authored Sep 15, 2024
2 parents 05913ff + e6b1811 commit 90e9d8a
Show file tree
Hide file tree
Showing 16 changed files with 356 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.petclinic.bffapigateway.presentationlayer.v2;

import com.petclinic.bffapigateway.domainclientlayer.BillServiceClient;
import com.petclinic.bffapigateway.dtos.Bills.BillResponseDTO;
import com.petclinic.bffapigateway.utils.Security.Annotations.IsUserSpecific;
import com.petclinic.bffapigateway.utils.Security.Variables.Roles;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/api/v2/gateway/bills")
@Validated
@CrossOrigin(origins = "http://localhost:3000, http://localhost:80")
public class BillController {
private final BillServiceClient billService;

@IsUserSpecific(idToMatch = {"customerId"}, bypassRoles = {Roles.ADMIN})
@GetMapping(value = "/customer/{customerId}", produces= MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<BillResponseDTO> getBillsByOwnerId(final @PathVariable String customerId)
{
return billService.getBillsByOwnerId(customerId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.petclinic.bffapigateway.presentationlayer.v2;

import com.petclinic.bffapigateway.domainclientlayer.BillServiceClient;
import com.petclinic.bffapigateway.dtos.Bills.BillResponseDTO;
import com.petclinic.bffapigateway.dtos.Bills.BillStatus;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;

import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Flux;

import java.time.LocalDate;

import static org.mockito.Mockito.when;

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {
BillController.class,
BillServiceClient.class
})
@WebFluxTest(controllers = BillController.class)
@AutoConfigureWebTestClient
public class BillControllerUnitTest {

@Autowired
private WebTestClient webTestClient;
@MockBean
private BillServiceClient billServiceClient;

private final String baseBillURL = "/api/v2/gateway/bills";

private BillResponseDTO billresponse = BillResponseDTO.builder()
.billId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")
.customerId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")
.visitType("general")
.vetId("3")
.date(LocalDate.parse("2024-10-11"))
.amount(100.0)
.taxedAmount(0.0)
.billStatus(BillStatus.UNPAID)
.dueDate(LocalDate.parse("2024-10-13"))
.build();

private BillResponseDTO billresponse2 = BillResponseDTO.builder()
.billId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361b")
.customerId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")
.visitType("general")
.vetId("2")
.date(LocalDate.parse("2024-10-11"))
.amount(120.0)
.taxedAmount(10.0)
.billStatus(BillStatus.UNPAID)
.dueDate(LocalDate.parse("2024-10-13"))
.build();


@Test
public void whenGetAllBillsByCustomerId_ThenReturnCustomerBills() {
when(billServiceClient.getBillsByOwnerId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")).thenReturn(Flux.just(billresponse, billresponse2));
webTestClient.get()
.uri(baseBillURL + "/customer/{customerId}", "e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")
.exchange()
.expectStatus().isOk()
.expectBodyList(BillResponseDTO.class)
.hasSize(2)
.contains(billresponse, billresponse2);
}


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.petclinic.billing.util;


import com.petclinic.billing.businesslayer.BillService;
import com.petclinic.billing.datalayer.BillRequestDTO;
import com.petclinic.billing.datalayer.BillStatus;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDate;


@Service
public class DataSetupService implements CommandLineRunner {
private final BillService billService;
public DataSetupService(BillService billService) {
this.billService = billService;
}


@Override
public void run(String... args) throws Exception {


BillRequestDTO b1 = new BillRequestDTO( "f470653d-05c5-4c45-b7a0-7d70f003d2ac", "general", "1", LocalDate.of(2023,9,19),59.99, BillStatus.PAID, LocalDate.of(2023, 10,3));
BillRequestDTO b3 = new BillRequestDTO( "f470653d-05c5-4c45-b7a0-7d70f003d2ac", "operation", "1", LocalDate.of(2023,9,27), 199.99,BillStatus.PAID,LocalDate.of(2023, 10,11));
BillRequestDTO b4 = new BillRequestDTO( "f470653d-05c5-4c45-b7a0-7d70f003d2ac", "injury", "1", LocalDate.of(2023,10,11), 199.99,BillStatus.UNPAID,LocalDate.of(2023, 10,25));
BillRequestDTO b2 = new BillRequestDTO( "f470653d-05c5-4c45-b7a0-7d70f003d2ac", "operation", "2", LocalDate.of(2023,10,6), 199.99,BillStatus.OVERDUE,LocalDate.of(2023, 10,20));
BillRequestDTO b5 = new BillRequestDTO( "e6c7398e-8ac4-4e10-9ee0-03ef33f0361a", "chronic", "3", LocalDate.of(2023,10,13), 199.99,BillStatus.UNPAID,LocalDate.of(2023, 10,27));
BillRequestDTO b6 = new BillRequestDTO("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a", "general", "2", LocalDate.of(2023, 10, 5), 59.99, BillStatus.PAID, LocalDate.of(2023, 10, 10));
BillRequestDTO b7 = new BillRequestDTO("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a", "operation", "3", LocalDate.of(2023, 10, 8), 199.99, BillStatus.PAID, LocalDate.of(2023, 10, 14));
BillRequestDTO b8 = new BillRequestDTO("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a", "injury", "2", LocalDate.of(2023, 10, 15), 199.99, BillStatus.OVERDUE, LocalDate.of(2023, 10, 30));
BillRequestDTO b9 = new BillRequestDTO("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a", "chronic", "1", LocalDate.of(2023, 10, 18), 199.99, BillStatus.UNPAID, LocalDate.of(2023, 11, 2));
BillRequestDTO b10 = new BillRequestDTO("3f59dca2-903e-495c-90c3-7f4d01f3a2aa", "general", "3", LocalDate.of(2023, 10, 21), 59.99, BillStatus.UNPAID, LocalDate.of(2023, 11, 6));
BillRequestDTO b11 = new BillRequestDTO("3f59dca2-903e-495c-90c3-7f4d01f3a2aa", "operation", "1", LocalDate.of(2023, 10, 24), 199.99, BillStatus.PAID, LocalDate.of(2023, 11, 10));
BillRequestDTO b12 = new BillRequestDTO("a6e0e5b0-5f60-45f0-8ac7-becd8b330486", "injury", "3", LocalDate.of(2023, 10, 27), 199.99, BillStatus.OVERDUE, LocalDate.of(2023, 11, 14));
BillRequestDTO b13 = new BillRequestDTO("a6e0e5b0-5f60-45f0-8ac7-becd8b330486", "chronic", "2", LocalDate.of(2023, 10, 30), 199.99, BillStatus.UNPAID, LocalDate.of(2023, 11, 18));
BillRequestDTO b14 = new BillRequestDTO("a6e0e5b0-5f60-45f0-8ac7-becd8b330486", "general", "1", LocalDate.of(2023, 11, 2), 59.99, BillStatus.PAID, LocalDate.of(2023, 11, 22));
BillRequestDTO b15 = new BillRequestDTO("c6a0fb9d-fc6f-4c21-95fc-4f5e7311d0e2", "operation", "2", LocalDate.of(2023, 11, 5), 199.99, BillStatus.UNPAID, LocalDate.of(2023, 11, 26));
BillRequestDTO b16 = new BillRequestDTO("c6a0fb9d-fc6f-4c21-95fc-4f5e7311d0e2", "injury", "1", LocalDate.of(2023, 11, 8), 199.99, BillStatus.PAID, LocalDate.of(2023, 12, 2));
BillRequestDTO b17 = new BillRequestDTO("b3d09eab-4085-4b2d-a121-78a0a2f9e501", "chronic", "3", LocalDate.of(2023, 11, 11), 199.99, BillStatus.OVERDUE, LocalDate.of(2023, 12, 6));
BillRequestDTO b18 = new BillRequestDTO("b3d09eab-4085-4b2d-a121-78a0a2f9e501", "general", "2", LocalDate.of(2023, 11, 14), 59.99, BillStatus.PAID, LocalDate.of(2023, 12, 10));
BillRequestDTO b19 = new BillRequestDTO("b3d09eab-4085-4b2d-a121-78a0a2f9e501", "operation", "3", LocalDate.of(2023, 11, 17), 199.99, BillStatus.UNPAID, LocalDate.of(2023, 12, 14));
BillRequestDTO b20 = new BillRequestDTO("b3d09eab-4085-4b2d-a121-78a0a2f9e501", "injury", "1", LocalDate.of(2023, 11, 20), 199.99, BillStatus.PAID, LocalDate.of(2023, 12, 18));
BillRequestDTO b21 = new BillRequestDTO("b3d09eab-4085-4b2d-a121-78a0a2f9e501", "chronic", "2", LocalDate.of(2023, 11, 23), 199.99, BillStatus.OVERDUE, LocalDate.of(2023, 12, 22));
BillRequestDTO b22 = new BillRequestDTO("5fe81e29-1f1d-4f9d-b249-8d3e0cc0b7dd", "general", "3", LocalDate.of(2023, 11, 26), 59.99, BillStatus.PAID, LocalDate.of(2023, 12, 26));
BillRequestDTO b23 = new BillRequestDTO("48f9945a-4ee0-4b0b-9b44-3da829a0f0f7", "operation", "2", LocalDate.of(2023, 11, 29), 199.99, BillStatus.UNPAID, LocalDate.of(2023, 12, 30));
BillRequestDTO b24 = new BillRequestDTO("48f9945a-4ee0-4b0b-9b44-3da829a0f0f7", "injury", "1", LocalDate.of(2023, 12, 2), 199.99, BillStatus.PAID, LocalDate.of(2024, 1, 2));
BillRequestDTO b25 = new BillRequestDTO("48f9945a-4ee0-4b0b-9b44-3da829a0f0f7", "chronic", "3", LocalDate.of(2023, 12, 5), 199.99, BillStatus.OVERDUE, LocalDate.of(2024, 1, 6));
BillRequestDTO b26 = new BillRequestDTO("48f9945a-4ee0-4b0b-9b44-3da829a0f0f7", "general", "2", LocalDate.of(2023, 12, 8), 59.99, BillStatus.UNPAID, LocalDate.of(2024, 1, 10));
BillRequestDTO b27 = new BillRequestDTO("48f9945a-4ee0-4b0b-9b44-3da829a0f0f7", "operation", "3", LocalDate.of(2023, 12, 11), 199.99, BillStatus.PAID, LocalDate.of(2024, 1, 14));
BillRequestDTO b28 = new BillRequestDTO("9f6accd1-e943-4322-932e-199d93824317", "injury", "1", LocalDate.of(2023, 12, 14), 199.99, BillStatus.PAID, LocalDate.of(2024, 1, 18));
BillRequestDTO b29 = new BillRequestDTO("9f6accd1-e943-4322-932e-199d93824317", "chronic", "2", LocalDate.of(2023, 12, 17), 199.99, BillStatus.OVERDUE, LocalDate.of(2024, 1, 22));
BillRequestDTO b30 = new BillRequestDTO("7c0d42c2-0c2d-41ce-bd9c-6ca67478956f", "general", "3", LocalDate.of(2023, 12, 20), 59.99, BillStatus.UNPAID, LocalDate.of(2024, 1, 26));

Flux.just(b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30)
.flatMap(b -> billService.CreateBill(Mono.just(b))
.log(b.toString()))
.subscribe();

Flux.just(b1,b2,b3,b4,b5)
.flatMap(b -> billService.CreateBill(Mono.just(b))
.log(b.toString()))
.subscribe();
}
}
12 changes: 6 additions & 6 deletions billing-service/src/main/resources/data-h2.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT INTO billings VALUES (1, 1, 1, 'general', '2021-09-19',59.99);
INSERT INTO billings VALUES (2, 2, 2, 'operation', '2021-09-20',199.99);
INSERT INTO billings VALUES (3, 3, 3, 'operation', '2021-09-21',199.99);
INSERT INTO billings VALUES (4, 4, 4, 'operation', '2021-09-22',199.99);
INSERT INTO billings VALUES (5, 5, 5, 'operation', '2021-09-23',199.99);
INSERT INTO billings VALUES (6, 6, 6, 'operation', '2021-09-23',199.99);
INSERT INTO billings VALUES (1, 1, 'f470653d-05c5-4c45-b7a0-7d70f003d2ac', 'general', '2021-09-19',59.99);
INSERT INTO billings VALUES (2, 2, 'e6c7398e-8ac4-4e10-9ee0-03ef33f0361a', 'operation', '2021-09-20',199.99);
INSERT INTO billings VALUES (3, 3, '3f59dca2-903e-495c-90c3-7f4d01f3a2aa', 'operation', '2021-09-21',199.99);
INSERT INTO billings VALUES (4, 4, 'a6e0e5b0-5f60-45f0-8ac7-becd8b330486', 'operation', '2021-09-22',199.99);
INSERT INTO billings VALUES (5, 5, 'c6a0fb9d-fc6f-4c21-95fc-4f5e7311d0e2', 'operation', '2021-09-23',199.99);
INSERT INTO billings VALUES (6, 6, 'b3d09eab-4085-4b2d-a121-78a0a2f9e501', 'operation', '2021-09-23',199.99);
12 changes: 6 additions & 6 deletions billing-service/src/main/resources/data-mysql.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT IGNORE INTO billings VALUES (1, 1, 1, 'general', '2021-09-19',59.99);
INSERT IGNORE INTO billings VALUES (2, 2, 2, 'operation', '2021-09-20',199.99);
INSERT IGNORE INTO billings VALUES (3, 3, 3, 'operation', '2021-09-21',199.99);
INSERT IGNORE INTO billings VALUES (4, 4, 4, 'operation', '2021-09-22',199.99);
INSERT IGNORE INTO billings VALUES (5, 5, 5, 'operation', '2021-09-23',199.99);
INSERT IGNORE INTO billings VALUES (6, 6, 6, 'operation', '2021-09-23',199.99);
INSERT IGNORE INTO billings VALUES (1, 1, 'f470653d-05c5-4c45-b7a0-7d70f003d2ac', 'general', '2021-09-19',59.99);
INSERT IGNORE INTO billings VALUES (2, 2, 'e6c7398e-8ac4-4e10-9ee0-03ef33f0361a', 'operation', '2021-09-20',199.99);
INSERT IGNORE INTO billings VALUES (3, 3, '3f59dca2-903e-495c-90c3-7f4d01f3a2aa', 'operation', '2021-09-21',199.99);
INSERT IGNORE INTO billings VALUES (4, 4, 'a6e0e5b0-5f60-45f0-8ac7-becd8b330486', 'operation', '2021-09-22',199.99);
INSERT IGNORE INTO billings VALUES (5, 5, 'c6a0fb9d-fc6f-4c21-95fc-4f5e7311d0e2', 'operation', '2021-09-23',199.99);
INSERT IGNORE INTO billings VALUES (6, 6, 'b3d09eab-4085-4b2d-a121-78a0a2f9e501', 'operation', '2021-09-23',199.99);
12 changes: 6 additions & 6 deletions billing-service/src/main/resources/db/hsqldb/data.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT INTO billings VALUES (1,1, '2021-09-19','general',59.99);
INSERT INTO billings VALUES (2,2, '2021-09-20','operation',199.99);
INSERT INTO billings VALUES (3,3, '2021-09-21','operation',199.99);
INSERT INTO billings VALUES (4,4, '2021-09-22','operation',199.99);
INSERT INTO billings VALUES (5,5, '2021-09-23','operation',199.99);
INSERT INTO billings VALUES (6,6, '2021-09-23','operation',199.99);
INSERT INTO billings VALUES (1,'f470653d-05c5-4c45-b7a0-7d70f003d2ac', '2021-09-19','general',59.99);
INSERT INTO billings VALUES (2,'e6c7398e-8ac4-4e10-9ee0-03ef33f0361a', '2021-09-20','operation',199.99);
INSERT INTO billings VALUES (3,'3f59dca2-903e-495c-90c3-7f4d01f3a2aa', '2021-09-21','operation',199.99);
INSERT INTO billings VALUES (4,'a6e0e5b0-5f60-45f0-8ac7-becd8b330486', '2021-09-22','operation',199.99);
INSERT INTO billings VALUES (5,'c6a0fb9d-fc6f-4c21-95fc-4f5e7311d0e2', '2021-09-23','operation',199.99);
INSERT INTO billings VALUES (6,'b3d09eab-4085-4b2d-a121-78a0a2f9e501', '2021-09-23','operation',199.99);
Loading

0 comments on commit 90e9d8a

Please sign in to comment.