This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from 7SOATSquad30/feature/order-endpoints
feat: feature/order endpoints
- Loading branch information
Showing
18 changed files
with
372 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,25 @@ INSERT INTO tb_customer (name, cpf, email, created_at) VALUES ('John', '20195054 | |
INSERT INTO tb_customer (name, cpf, email, created_at) VALUES ('Mary', '81018255095', '[email protected]', NOW()); | ||
INSERT INTO tb_customer (name, cpf, email, created_at) VALUES ('Jack', '50260304085', '[email protected]', NOW()); | ||
INSERT INTO tb_customer (name, cpf, email, created_at) VALUES ('Lysa', '38877348070', '[email protected]', NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('DRAFT', 1, NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('SUBMITTED', 2, NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('DRAFT', 3, NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('PREPARING', 4, NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('READY', 1, NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('SUBMITTED', 3, NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('DELIVERED', 2, NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('PREPARING', 2, NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('READY', 4, NOW()); | ||
INSERT INTO tb_order (status, customer_id, created_at) VALUES ('DELIVERED', 4, NOW()); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (2, 1, 1, 14.9); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (4, 3, 2, 29.8); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (5, 17, 2, 11.8); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (5, 6, 1, 9.9); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (6, 17, 3, 17.7); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (7, 5, 1, 12.9); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (7, 2, 1, 12.9); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (7, 8, 2, 23.8); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (8, 20, 1, 7.9); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (9, 22, 2, 17.8); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (10, 12, 1, 8.9); | ||
INSERT INTO tb_order_item (order_id, product_id, quantity, total_price) VALUES (10, 15, 1, 13.9); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/br/com/fiap/grupo30/fastfood/application/dto/AddCustomerCpfRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package br.com.fiap.grupo30.fastfood.application.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class AddCustomerCpfRequest { | ||
private String cpf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...astfood/application/exceptions/CantChangeOrderStatusDeliveredOtherThanReadyException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package br.com.fiap.grupo30.fastfood.application.exceptions; | ||
|
||
import java.io.Serial; | ||
|
||
public class CantChangeOrderStatusDeliveredOtherThanReadyException | ||
extends DomainValidationException { | ||
|
||
@Serial private static final long serialVersionUID = 1L; | ||
private static final String MESSAGE = | ||
"Can not to finish the delivery an order that does not have the ready status"; | ||
|
||
public CantChangeOrderStatusDeliveredOtherThanReadyException() { | ||
super(MESSAGE); | ||
} | ||
|
||
public CantChangeOrderStatusDeliveredOtherThanReadyException(Throwable exception) { | ||
super(MESSAGE, exception); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ood/application/exceptions/CantChangeOrderStatusPreparingOtherThanSubmittedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package br.com.fiap.grupo30.fastfood.application.exceptions; | ||
|
||
import java.io.Serial; | ||
|
||
public class CantChangeOrderStatusPreparingOtherThanSubmittedException | ||
extends DomainValidationException { | ||
|
||
@Serial private static final long serialVersionUID = 1L; | ||
private static final String MESSAGE = | ||
"Can not to prepare an order that does not have the submitted status"; | ||
|
||
public CantChangeOrderStatusPreparingOtherThanSubmittedException() { | ||
super(MESSAGE); | ||
} | ||
|
||
public CantChangeOrderStatusPreparingOtherThanSubmittedException(Throwable exception) { | ||
super(MESSAGE, exception); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...astfood/application/exceptions/CantChangeOrderStatusReadyOtherThanPreparingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package br.com.fiap.grupo30.fastfood.application.exceptions; | ||
|
||
import java.io.Serial; | ||
|
||
public class CantChangeOrderStatusReadyOtherThanPreparingException | ||
extends DomainValidationException { | ||
|
||
@Serial private static final long serialVersionUID = 1L; | ||
private static final String MESSAGE = | ||
"Can not to finish the prepare an order that does not have the preparing status"; | ||
|
||
public CantChangeOrderStatusReadyOtherThanPreparingException() { | ||
super(MESSAGE); | ||
} | ||
|
||
public CantChangeOrderStatusReadyOtherThanPreparingException(Throwable exception) { | ||
super(MESSAGE, exception); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...java/br/com/fiap/grupo30/fastfood/application/exceptions/InvalidOrderStatusException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package br.com.fiap.grupo30.fastfood.application.exceptions; | ||
|
||
import java.io.Serial; | ||
|
||
public class InvalidOrderStatusException extends RuntimeException { | ||
|
||
@Serial private static final long serialVersionUID = 1L; | ||
|
||
private static final String MESSAGE_TEMPLATE = "Invalid order status: %s"; | ||
|
||
public InvalidOrderStatusException(String status) { | ||
super(String.format(MESSAGE_TEMPLATE, status)); | ||
} | ||
|
||
public InvalidOrderStatusException(String status, Throwable exception) { | ||
super(String.format(MESSAGE_TEMPLATE, status), exception); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/DeliverOrderUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.usecases.order; | ||
|
||
import br.com.fiap.grupo30.fastfood.application.dto.OrderDTO; | ||
import br.com.fiap.grupo30.fastfood.application.exceptions.CantChangeOrderStatusDeliveredOtherThanReadyException; | ||
import br.com.fiap.grupo30.fastfood.application.exceptions.ResourceNotFoundException; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.out.persistence.jpa.entities.OrderEntity; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.out.persistence.jpa.entities.OrderStatus; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.out.persistence.jpa.repositories.OrderRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class DeliverOrderUseCase { | ||
|
||
private final OrderRepository orderRepository; | ||
|
||
@Autowired | ||
public DeliverOrderUseCase(OrderRepository orderRepository) { | ||
this.orderRepository = orderRepository; | ||
} | ||
|
||
public OrderDTO execute(Long orderId) { | ||
OrderEntity order = | ||
this.orderRepository | ||
.findById(orderId) | ||
.orElseThrow(() -> new ResourceNotFoundException("Order not found")); | ||
|
||
if (order.getStatus() != OrderStatus.READY) { | ||
throw new CantChangeOrderStatusDeliveredOtherThanReadyException(); | ||
} | ||
|
||
order.setStatus(OrderStatus.DELIVERED); | ||
return this.orderRepository.save(order).toDTO(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../java/br/com/fiap/grupo30/fastfood/domain/usecases/order/FinishPreparingOrderUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.usecases.order; | ||
|
||
import br.com.fiap.grupo30.fastfood.application.dto.OrderDTO; | ||
import br.com.fiap.grupo30.fastfood.application.exceptions.CantChangeOrderStatusReadyOtherThanPreparingException; | ||
import br.com.fiap.grupo30.fastfood.application.exceptions.ResourceNotFoundException; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.out.persistence.jpa.entities.OrderEntity; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.out.persistence.jpa.entities.OrderStatus; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.out.persistence.jpa.repositories.OrderRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class FinishPreparingOrderUseCase { | ||
|
||
private final OrderRepository orderRepository; | ||
|
||
@Autowired | ||
public FinishPreparingOrderUseCase(OrderRepository orderRepository) { | ||
this.orderRepository = orderRepository; | ||
} | ||
|
||
public OrderDTO execute(Long orderId) { | ||
OrderEntity order = | ||
this.orderRepository | ||
.findById(orderId) | ||
.orElseThrow(() -> new ResourceNotFoundException("Order not found")); | ||
|
||
if (order.getStatus() != OrderStatus.PREPARING) { | ||
throw new CantChangeOrderStatusReadyOtherThanPreparingException(); | ||
} | ||
|
||
order.setStatus(OrderStatus.READY); | ||
return this.orderRepository.save(order).toDTO(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.