Skip to content

Commit

Permalink
feat: PPI-21 - adicionando numeração do pedido automático
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderleik committed Jul 11, 2024
1 parent 49544ff commit 84a63e3
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Builder
public record OrderProjection(
UUID id,
Long orderNumber,
String orderNumber,
LocalDate orderDate,
String status,
List<OrderItemProjection> items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@Builder
public record OrderRequest(
Long orderNumber,
LocalDate orderDate,
String status,
String discount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Builder
public record OrderResponse(
UUID id,
Long orderNumber,
String orderNumber,
LocalDate orderDate,
String status,
// List<OrderItemResponse> items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class OrderEntity {
private UUID id;

@NotNull(message = MessagesConstants.ORDER_NUMBER_NOT_NULL)
@Column(name = "ordernumber", unique = true)
private Long orderNumber;
@Column(name = "ordernumber")
private String orderNumber;

@NotNull(message = MessagesConstants.ORDER_DATE_NOT_NULL)
@Column(name = "orderdate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.math.BigDecimal;
import java.util.List;
import java.util.Random;
import java.util.UUID;

@RequiredArgsConstructor
Expand All @@ -24,13 +25,19 @@ public class OrderConverter {

public OrderEntity toEntity(OrderRequest orderRequest) {
return OrderEntity.builder()
.orderNumber(orderRequest.orderNumber())
.orderNumber(getOrderNumber())
.orderDate(orderRequest.orderDate())
.status(EnumConverter.fromString(orderRequest.status(), EnumOrderStatus.class))
.discount(new BigDecimal(orderRequest.discount()))
.build();
}

private String getOrderNumber() {
Random random = new Random();
int randomNumber = random.nextInt(1001);
return "PED-" + randomNumber + "-2024";
}

public OrderResponse toResponse(OrderEntity entitySaved) {
return OrderResponse.builder()
.id(entitySaved.getId())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE IF NOT EXISTS tborder (
idorder UUID PRIMARY KEY DEFAULT gen_random_uuid(),
ordernumber BIGINT NOT NULL,
ordernumber VARCHAR(30) NOT NULL,
orderdate DATE NOT NULL,
status VARCHAR(255) NOT NULL,
grosstotal NUMERIC(19,2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
@ActiveProfiles("test")
class OrderItemRepositoryTest {

private static final String ORDER_NUMBER = "PED-81-2024";

@Autowired
private OrderItemRepository orderItemRepository;
@Autowired
Expand All @@ -44,7 +46,7 @@ void setUp() {
productRepository.save(productEntity);

OrderEntity orderEntity = OrderEntity.builder()
.orderNumber(1L)
.orderNumber(ORDER_NUMBER)
.orderDate(LocalDate.now())
.status(EnumOrderStatus.OPEN)
.items(new ArrayList<>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
@ActiveProfiles("test")
class OrderRepositoryTest {

private static final String ORDER_NUMBER = "PED-81-2024";

@Autowired
private OrderRepository orderRepository;

Expand All @@ -28,7 +30,7 @@ class OrderRepositoryTest {
@BeforeEach
void setUp() {
orderEntity = OrderEntity.builder()
.orderNumber(1L)
.orderNumber(ORDER_NUMBER)
.orderDate(LocalDate.now())
.status(EnumOrderStatus.OPEN)
.items(new ArrayList<>())
Expand Down

0 comments on commit 84a63e3

Please sign in to comment.