Skip to content

Commit

Permalink
refactor: change client id data type (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelovbcfilho authored Jan 29, 2024
2 parents 512b229 + 64b04c1 commit 98a39f6
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class OrderAdapter {

public static void fillEntity(CreateOrderRequestDTO dto, Long clientId, Order order) {
public static void fillEntity(CreateOrderRequestDTO dto, String clientId, Order order) {
OrderControllerDTO orderDTO = new OrderControllerDTO();
orderDTO.setClientId(clientId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class OrderAPIController extends AbstractAPIController {
public ResponseEntity<OrderControllerDTO> create(@Valid @RequestBody CreateOrderRequestDTO createOrderRequestDTO,
HttpServletRequest request) throws ValidationException, NotFoundException {
return ResponseEntity.ok(controller
.create(Long.parseLong((String) request.getAttribute("clientId")),
.create((String) request.getAttribute("clientId"),
createOrderRequestDTO));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class OrderController {

private final OrderUseCase orderUseCase;

public OrderControllerDTO create(Long clientId, CreateOrderRequestDTO dto) throws ValidationException, NotFoundException {
public OrderControllerDTO create(String clientId, CreateOrderRequestDTO dto) throws ValidationException, NotFoundException {
Order entity = new Order();
OrderAdapter.fillEntity(dto, clientId, entity);
entity = orderUseCase.create(entity, clientId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class OrderControllerDTO extends AbstractControllerDTO {

private Double totalPrice;
private Long clientId;
private String clientId;
private List<OrderItemControllerDTO> items = new ArrayList<>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
public class Order extends Entity {

private Double totalPrice;
private Long clientId;
private String clientId;
private List<OrderItem> items = new ArrayList<>();

public Order(Long id, boolean deleted, Double totalPrice, Long clientId, List<OrderItem> items) {
public Order(Long id, boolean deleted, Double totalPrice, String clientId, List<OrderItem> items) {
super(id, deleted);
this.totalPrice = totalPrice;
this.clientId = clientId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import java.util.Optional;

@FeignClient(name = "identification", url = "/identification/clients")
@FeignClient(name = "identification", url = "${urls.baseurl-identification}")
public interface IIdentificationGateway {

@RequestMapping(method = RequestMethod.GET, value = "/{id}")
Optional<ClientDTO> getById(@PathVariable("id") Long orderId);
@RequestMapping(method = RequestMethod.GET, value = "/identification/clients/{id}")
Optional<ClientDTO> getById(@PathVariable("id") String id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@NoArgsConstructor
public class ClientDTO {

Long id;
String id;

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class OrderPersistenceEntity extends PersistenceEntity {

@Basic
@Column(name = "ord_client", nullable = false)
private Long clientId;
private String clientId;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "order")
private List<OrderItemPersistenceEntity> items = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public interface IOrderUseCase {

Order create(Order entity, Long clientId) throws ValidationException, NotFoundException;
Order create(Order entity, String clientId) throws ValidationException, NotFoundException;

Order read(Long id) throws NotFoundException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private void fillCurrentPrices(Order order) throws NotFoundException {
}

@Override
public Order create(Order entity, Long clientId) throws NotFoundException {
public Order create(Order entity, String clientId) throws NotFoundException {
identificationGateway.getById(clientId).orElseThrow(NotFoundException::new);

fillCurrentPrices(entity);
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jwt:
key:
public: "${JWT_PUBLIC_KEY:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqStd8n4SGNM0eZhV/hzU+urHA5/IMZPoP9YQ9ZcLKWiX33nI6bSuZMCrLZcJExf63xS+uxDpGxM8Mnk2zOdl+lPwANXLzP1us5P1PyA3YPycW9J7C5YTQW0GiEL3M93ZX7vMJiVoBYblP3JPlYnoYlBORuc0JPk33KtfEZP+78qXpPHM8imYrJLe8ceiDLLFDU/nh5KC2dWAy3ci1ahoJ1Q9ELhp3IZLvOTX57H/T2VKOYOya5+ST41h+JjzI+qGTVnLcKaW+k25YLlVnkSspvdx98+yQDi7kbOTS6yRZHUPD6wPk/nUozpD0nZKccoH4W+zMwmQVtsAA6JCA9gfGwIDAQAB}"

urls:
baseurl-identification: '${BASE_URL_IDENTIFICATION:localhost:8081}'

server:
servlet:
context-path: "/order"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS ord_order (
id BIGSERIAL PRIMARY KEY,
deleted BOOLEAN NOT NULL,
total_price DOUBLE PRECISION NOT NULL,
ord_client BIGINT NOT NULL,
ord_client VARCHAR(255) NOT NULL,
creation_date TIMESTAMP(6) NOT NULL,
last_update_date TIMESTAMP(6) NOT NULL
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class OrderIntegrationTest {
private final Category defaultCategory = new Category(1L, false, "category");
private final Product defaultProduct = new Product(1L, false, "product", 10.0, defaultCategory);
private final CreateOrderRequestDTO.Item defaultItem = new CreateOrderRequestDTO.Item(1L, 1L);
private final Order defaultOrder = new Order(1L, false, 10.0, 1L, List.of());
private final Order defaultOrder = new Order(1L, false, 10.0, "hash", List.of());

private final OrderPersistenceEntity defaultOrderPersistenceEntity =
new OrderPersistenceEntity(defaultOrder);
Expand Down Expand Up @@ -96,9 +96,9 @@ void testList_EndToEnd() {
@Test
void testCreate_EndToEnd() {
HttpServletRequest mockedRequest = new MockHttpServletRequest();
mockedRequest.setAttribute("clientId", Long.toString(1L));
mockedRequest.setAttribute("clientId", "hash");

when(identificationGateway.getById(1L)).thenReturn(Optional.of(defaultClientDTO));
when(identificationGateway.getById("hash")).thenReturn(Optional.of(defaultClientDTO));
when(productJpaRepository.findByIdAndDeletedFalse(1L)).thenReturn(Optional.of(defaultProductPersistenceEntity));
when(orderJpaRepository.saveAndFlush(any())).thenReturn(defaultOrderPersistenceEntity);

Expand Down

0 comments on commit 98a39f6

Please sign in to comment.