From a2680c023ddb7a883dd2062a1d8a9295f8d4c063 Mon Sep 17 00:00:00 2001 From: gabrielgennaro Date: Mon, 30 Sep 2024 07:33:54 -0300 Subject: [PATCH] =?UTF-8?q?Ajustes=20na=20implementa=C3=A7=C3=A3o=20do=20c?= =?UTF-8?q?lean=20architecture,=20instanciando=20o=20gateway=20na=20contro?= =?UTF-8?q?ller=20e=20passando=20para=20o=20use=20case=20utilizar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ListAllCategoriesInMenuUseCase.java | 7 ++--- .../customer/FindCustomerByCpfUseCase.java | 7 ++--- .../customer/RegisterNewCustomerUseCase.java | 7 ++--- .../order/AddProductToOrderUseCase.java | 9 ++----- .../usecases/order/DeliverOrderUseCase.java | 7 ++--- .../order/FinishPreparingOrderUseCase.java | 7 ++--- .../usecases/order/GetOrderUseCase.java | 7 ++--- .../order/ListOrdersByStatusUseCase.java | 7 ++--- ...ListOrdersWithSpecificStatusesUseCase.java | 7 ++--- .../order/RemoveProductFromOrderUseCase.java | 9 ++----- .../usecases/order/StartNewOrderUseCase.java | 13 +++------- .../order/StartPreparingOrderUseCase.java | 7 ++--- .../usecases/order/SubmitOrderUseCase.java | 5 +--- .../CollectOrderPaymentViaCashUseCase.java | 6 ++--- ...lectOrderPaymentViaMercadoPagoUseCase.java | 11 +++----- .../payment/GeneratePaymentQrCodeUseCase.java | 9 ++----- .../product/CreateProductUseCase.java | 17 +++++------- .../product/DeleteProductUseCase.java | 7 ++--- .../usecases/product/GetProductUseCase.java | 7 ++--- .../ListProductsByCategoryUseCase.java | 7 ++--- .../product/UpdateProductUseCase.java | 8 ++---- .../controllers/CategoryController.java | 3 ++- .../controllers/CustomerController.java | 7 +++-- .../controllers/OrderController.java | 26 ++++++++++++++----- .../controllers/PaymentResource.java | 8 +++--- .../controllers/ProductController.java | 19 +++++++++++--- .../controllers/WebhookResource.java | 4 ++- 27 files changed, 100 insertions(+), 138 deletions(-) diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/category/ListAllCategoriesInMenuUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/category/ListAllCategoriesInMenuUseCase.java index 3b737d9..1d06044 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/category/ListAllCategoriesInMenuUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/category/ListAllCategoriesInMenuUseCase.java @@ -7,13 +7,10 @@ public class ListAllCategoriesInMenuUseCase { - private final CategoryGateway categoryGateway; - - public ListAllCategoriesInMenuUseCase(CategoryGateway categoryGateway) { - this.categoryGateway = categoryGateway; + public ListAllCategoriesInMenuUseCase() { } - public List execute() { + public List execute(CategoryGateway categoryGateway) { return categoryGateway.findAll().stream().map(Category::toDTO).toList(); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/FindCustomerByCpfUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/FindCustomerByCpfUseCase.java index 734a712..99b6a6e 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/FindCustomerByCpfUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/FindCustomerByCpfUseCase.java @@ -7,13 +7,10 @@ public class FindCustomerByCpfUseCase { - private final CustomerGateway customerGateway; - - public FindCustomerByCpfUseCase(CustomerGateway customerGateway) { - this.customerGateway = customerGateway; + public FindCustomerByCpfUseCase() { } - public CustomerDTO execute(String cpf) { + public CustomerDTO execute(CustomerGateway customerGateway, String cpf) { if (!CPF.isValid(cpf)) { throw new InvalidCpfException(cpf); } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/RegisterNewCustomerUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/RegisterNewCustomerUseCase.java index 7a3df2a..9ab9b28 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/RegisterNewCustomerUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/RegisterNewCustomerUseCase.java @@ -8,13 +8,10 @@ public class RegisterNewCustomerUseCase { - private final CustomerGateway customerGateway; - - public RegisterNewCustomerUseCase(CustomerGateway customerGateway) { - this.customerGateway = customerGateway; + public RegisterNewCustomerUseCase() { } - public CustomerDTO execute(String name, String cpf, String email) { + public CustomerDTO execute(CustomerGateway customerGateway, String name, String cpf, String email) { if (!CPF.isValid(cpf)) { throw new InvalidCpfException(cpf); } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/AddProductToOrderUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/AddProductToOrderUseCase.java index adc5cd1..9a0928c 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/AddProductToOrderUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/AddProductToOrderUseCase.java @@ -10,15 +10,10 @@ public class AddProductToOrderUseCase { - private final OrderGateway orderGateway; - private final ProductGateway productGateway; - - public AddProductToOrderUseCase(OrderGateway orderGateway, ProductGateway productGateway) { - this.orderGateway = orderGateway; - this.productGateway = productGateway; + public AddProductToOrderUseCase() { } - public OrderDTO execute(Long orderId, Long productId, Long productQuantity) { + public OrderDTO execute(OrderGateway orderGateway, ProductGateway productGateway, Long orderId, Long productId, Long productQuantity) { Order order = orderGateway.findByIdForUpdate(orderId); Product product = productGateway.findById(productId); diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/DeliverOrderUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/DeliverOrderUseCase.java index 95775cd..a013a0f 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/DeliverOrderUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/DeliverOrderUseCase.java @@ -8,13 +8,10 @@ public class DeliverOrderUseCase { - private final OrderGateway orderGateway; - - public DeliverOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; + public DeliverOrderUseCase() { } - public OrderDTO execute(Long orderId) { + public OrderDTO execute(OrderGateway orderGateway, Long orderId) { Order order = orderGateway.findById(orderId); if (order.getStatus() != OrderStatus.READY) { diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/FinishPreparingOrderUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/FinishPreparingOrderUseCase.java index 0599f45..ecde9c3 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/FinishPreparingOrderUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/FinishPreparingOrderUseCase.java @@ -8,13 +8,10 @@ public class FinishPreparingOrderUseCase { - private final OrderGateway orderGateway; - - public FinishPreparingOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; + public FinishPreparingOrderUseCase() { } - public OrderDTO execute(Long orderId) { + public OrderDTO execute(OrderGateway orderGateway, Long orderId) { Order order = orderGateway.findById(orderId); if (order.getStatus() != OrderStatus.PREPARING) { diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/GetOrderUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/GetOrderUseCase.java index e807a15..99538b1 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/GetOrderUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/GetOrderUseCase.java @@ -5,13 +5,10 @@ public class GetOrderUseCase { - private final OrderGateway orderGateway; - - public GetOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; + public GetOrderUseCase() { } - public OrderDTO execute(Long orderId) { + public OrderDTO execute(OrderGateway orderGateway, Long orderId) { return orderGateway.findById(orderId).toDTO(); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/ListOrdersByStatusUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/ListOrdersByStatusUseCase.java index b1f2d28..6a4bbae 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/ListOrdersByStatusUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/ListOrdersByStatusUseCase.java @@ -10,13 +10,10 @@ public class ListOrdersByStatusUseCase { - private final OrderGateway orderGateway; - - public ListOrdersByStatusUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; + public ListOrdersByStatusUseCase() { } - public List execute(String status) { + public List execute(OrderGateway orderGateway, String status) { OrderStatus statusFilter = null; if (status != null && !status.isEmpty()) { try { diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/ListOrdersWithSpecificStatusesUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/ListOrdersWithSpecificStatusesUseCase.java index 69a3ebd..6ddd6cb 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/ListOrdersWithSpecificStatusesUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/ListOrdersWithSpecificStatusesUseCase.java @@ -7,13 +7,10 @@ public class ListOrdersWithSpecificStatusesUseCase { - private final OrderGateway orderGateway; - - public ListOrdersWithSpecificStatusesUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; + public ListOrdersWithSpecificStatusesUseCase() { } - public List execute() { + public List execute(OrderGateway orderGateway) { return orderGateway.findOrdersWithSpecificStatuses().stream().map(Order::toDTO).toList(); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/RemoveProductFromOrderUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/RemoveProductFromOrderUseCase.java index 3d44ae8..0c0f430 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/RemoveProductFromOrderUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/RemoveProductFromOrderUseCase.java @@ -10,15 +10,10 @@ public class RemoveProductFromOrderUseCase { - private final OrderGateway orderGateway; - private final ProductGateway productGateway; - - public RemoveProductFromOrderUseCase(OrderGateway orderGateway, ProductGateway productGateway) { - this.orderGateway = orderGateway; - this.productGateway = productGateway; + public RemoveProductFromOrderUseCase() { } - public OrderDTO execute(Long orderId, Long productId) { + public OrderDTO execute(OrderGateway orderGateway, ProductGateway productGateway, Long orderId, Long productId) { Order order = orderGateway.findById(orderId); Product product = productGateway.findById(productId); diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/StartNewOrderUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/StartNewOrderUseCase.java index 9129361..eede15b 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/StartNewOrderUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/StartNewOrderUseCase.java @@ -11,25 +11,20 @@ public class StartNewOrderUseCase { - private final OrderGateway orderGateway; - private final CustomerGateway customerGateway; - - public StartNewOrderUseCase(OrderGateway orderGateway, CustomerGateway customerGateway) { - this.orderGateway = orderGateway; - this.customerGateway = customerGateway; + public StartNewOrderUseCase() { } - public OrderDTO execute(String customerCpf) { + public OrderDTO execute(OrderGateway orderGateway, CustomerGateway customerGateway, String customerCpf) { if (!CPF.isValid(customerCpf)) { throw new InvalidCpfException(customerCpf); } - Customer customer = findCustomerOrCreateAnonymous(new CPF(customerCpf)); + Customer customer = findCustomerOrCreateAnonymous(customerGateway, new CPF(customerCpf)); Order newOrder = Order.createFor(customer); return orderGateway.save(newOrder).toDTO(); } - private Customer findCustomerOrCreateAnonymous(CPF customerCpf) { + private Customer findCustomerOrCreateAnonymous(CustomerGateway customerGateway, CPF customerCpf) { if (customerCpf != null) { return customerGateway.findCustomerByCpf(customerCpf.value()); } else { diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/StartPreparingOrderUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/StartPreparingOrderUseCase.java index fbcf014..7fa1255 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/StartPreparingOrderUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/StartPreparingOrderUseCase.java @@ -8,13 +8,10 @@ public class StartPreparingOrderUseCase { - private final OrderGateway orderGateway; - - public StartPreparingOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; + public StartPreparingOrderUseCase() { } - public OrderDTO execute(Long orderId) { + public OrderDTO execute(OrderGateway orderGateway, Long orderId) { Order order = orderGateway.findById(orderId); if (order.getStatus() != OrderStatus.SUBMITTED) { diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/SubmitOrderUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/SubmitOrderUseCase.java index 975dfd2..ef07296 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/SubmitOrderUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/SubmitOrderUseCase.java @@ -7,10 +7,7 @@ public class SubmitOrderUseCase { - private final OrderGateway orderGateway; - - public SubmitOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; + public SubmitOrderUseCase() { } public OrderDTO execute(Long orderId) { diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/CollectOrderPaymentViaCashUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/CollectOrderPaymentViaCashUseCase.java index 1d485a2..7e00205 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/CollectOrderPaymentViaCashUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/CollectOrderPaymentViaCashUseCase.java @@ -8,14 +8,12 @@ @Component public class CollectOrderPaymentViaCashUseCase { - private final OrderGateway orderGateway; @Autowired - public CollectOrderPaymentViaCashUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; + public CollectOrderPaymentViaCashUseCase() { } - public OrderDTO execute(Long orderId, Double paidAmount) { + public OrderDTO execute(OrderGateway orderGateway, Long orderId, Double paidAmount) { Order order = this.orderGateway.findById(orderId); order.setPaymentCollected(paidAmount); diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/CollectOrderPaymentViaMercadoPagoUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/CollectOrderPaymentViaMercadoPagoUseCase.java index 7b6639f..69c1d82 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/CollectOrderPaymentViaMercadoPagoUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/CollectOrderPaymentViaMercadoPagoUseCase.java @@ -13,17 +13,12 @@ @Component public class CollectOrderPaymentViaMercadoPagoUseCase { - private final OrderGateway orderGateway; - private final MercadoPagoGateway mercadoPagoGateway; - + @Autowired - public CollectOrderPaymentViaMercadoPagoUseCase( - OrderGateway orderGateway, MercadoPagoGateway mercadoPagoGateway) { - this.orderGateway = orderGateway; - this.mercadoPagoGateway = mercadoPagoGateway; + public CollectOrderPaymentViaMercadoPagoUseCase() { } - public OrderDTO execute(MercadoPagoActionEventDTO mercadoPagoPaymentEvent) { + public OrderDTO execute(OrderGateway orderGateway, MercadoPagoGateway mercadoPagoGateway, MercadoPagoActionEventDTO mercadoPagoPaymentEvent) { try { MercadoPagoPaymentDTO payment = this.mercadoPagoGateway.getPaymentState( diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/GeneratePaymentQrCodeUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/GeneratePaymentQrCodeUseCase.java index 8a00985..af17bd1 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/GeneratePaymentQrCodeUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/payment/GeneratePaymentQrCodeUseCase.java @@ -11,17 +11,12 @@ @Component public class GeneratePaymentQrCodeUseCase { - private final OrderGateway orderGateway; - private final MercadoPagoGateway mercadoPagoGateway; @Autowired - public GeneratePaymentQrCodeUseCase( - OrderGateway orderGateway, MercadoPagoGateway mercadoPagoGateway) { - this.orderGateway = orderGateway; - this.mercadoPagoGateway = mercadoPagoGateway; + public GeneratePaymentQrCodeUseCase() { } - public PaymentQrCodeDTO execute(Long orderId) { + public PaymentQrCodeDTO execute(OrderGateway orderGateway, MercadoPagoGateway mercadoPagoGateway, Long orderId) { Order order = this.orderGateway.findById(orderId); MercadoPagoQrCodeDTO qrCodeResponse; diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/CreateProductUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/CreateProductUseCase.java index 6cb29b2..9913f7b 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/CreateProductUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/CreateProductUseCase.java @@ -6,19 +6,16 @@ import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.ProductDTO; -public class CreateProductUseCase { - - private final ProductGateway productGateway; - private final CategoryGateway categoryGateway; - - public CreateProductUseCase(ProductGateway productGateway, CategoryGateway categoryGateway) { - this.productGateway = productGateway; - this.categoryGateway = categoryGateway; +public class CreateProductUseCase +{ + public CreateProductUseCase() { } public ProductDTO execute( - String name, String description, Double price, String imgUrl, String category) { - Category categoryEntity = this.categoryGateway.findOne(category); + ProductGateway productGateway, CategoryGateway categoryGateway, + String name, String description, Double price, String imgUrl, String category) + { + Category categoryEntity = categoryGateway.findOne(category); Product product = Product.create(name, description, price, imgUrl, categoryEntity); return productGateway.save(product).toDTO(); } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/DeleteProductUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/DeleteProductUseCase.java index 9bab566..cebdd96 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/DeleteProductUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/DeleteProductUseCase.java @@ -4,13 +4,10 @@ public class DeleteProductUseCase { - private final ProductGateway productGateway; - - public DeleteProductUseCase(ProductGateway productGateway) { - this.productGateway = productGateway; + public DeleteProductUseCase() { } - public void execute(Long id) { + public void execute(ProductGateway productGateway, Long id) { productGateway.delete(id); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/GetProductUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/GetProductUseCase.java index e6293af..9336074 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/GetProductUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/GetProductUseCase.java @@ -5,13 +5,10 @@ public class GetProductUseCase { - private final ProductGateway productGateway; - - public GetProductUseCase(ProductGateway productGateway) { - this.productGateway = productGateway; + public GetProductUseCase() { } - public ProductDTO execute(Long id) { + public ProductDTO execute(ProductGateway productGateway, Long id) { return productGateway.findById(id).toDTO(); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListProductsByCategoryUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListProductsByCategoryUseCase.java index 19f01e5..88e144f 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListProductsByCategoryUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListProductsByCategoryUseCase.java @@ -7,13 +7,10 @@ public class ListProductsByCategoryUseCase { - private final ProductGateway productGateway; - - public ListProductsByCategoryUseCase(ProductGateway productGateway) { - this.productGateway = productGateway; + public ListProductsByCategoryUseCase() { } - public List execute(Long categoryId) { + public List execute(ProductGateway productGateway, Long categoryId) { return productGateway.findProductsByCategoryId(categoryId).stream() .map(Product::toDTO) .toList(); diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/UpdateProductUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/UpdateProductUseCase.java index 29ed21a..a48750c 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/UpdateProductUseCase.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/UpdateProductUseCase.java @@ -8,15 +8,11 @@ public class UpdateProductUseCase { - private final ProductGateway productGateway; - private final CategoryGateway categoryGateway; - - public UpdateProductUseCase(ProductGateway productGateway, CategoryGateway categoryGateway) { - this.productGateway = productGateway; - this.categoryGateway = categoryGateway; + public UpdateProductUseCase() { } public ProductDTO execute( + ProductGateway productGateway, CategoryGateway categoryGateway, Long productId, String name, String description, diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/CategoryController.java b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/CategoryController.java index 30e0150..83e4b47 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/CategoryController.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/CategoryController.java @@ -28,7 +28,8 @@ public CategoryController(ListAllCategoriesInMenuUseCase listAllCategoriesInMenu summary = "Get all categories", description = "Retrieve a list of all registered categories") public ResponseEntity> findAll() { - List categories = this.listAllCategoriesInMenuUseCase.execute(); + CategoryGateway categoryGateway = new CategoryGateway(); + List categories = this.listAllCategoriesInMenuUseCase.execute(categoryGateway); return ResponseEntity.ok().body(categories); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/CustomerController.java b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/CustomerController.java index 2243036..1556825 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/CustomerController.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/CustomerController.java @@ -2,6 +2,7 @@ import br.com.fiap.grupo30.fastfood.domain.usecases.customer.FindCustomerByCpfUseCase; import br.com.fiap.grupo30.fastfood.domain.usecases.customer.RegisterNewCustomerUseCase; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.CustomerGateway; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.CustomerDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -32,7 +33,8 @@ public CustomerController( @Operation(summary = "Get a customer", description = "Retrieve a registered customer by cpf") public ResponseEntity findCustomerByCpf( @RequestParam(value = "cpf", defaultValue = "0") String cpf) { - CustomerDTO customer = this.findCustomerByCpfUseCase.execute(cpf); + CustomerGateway customerGateway = new CustomerGateway(); + CustomerDTO customer = this.findCustomerByCpfUseCase.execute(customerGateway, cpf); return ResponseEntity.ok().body(customer); } @@ -41,8 +43,9 @@ public ResponseEntity findCustomerByCpf( summary = "Create a new customer", description = "Create a new customer and return the created customer's data") public ResponseEntity createCustomer(@RequestBody @Valid CustomerDTO dto) { + CustomerGateway customerGateway = CustomerGateway(); CustomerDTO createdCustomer = - this.registerNewCustomerUseCase.execute( + this.registerNewCustomerUseCase.execute(customerGateway, dto.getName(), dto.getCpf(), dto.getEmail()); URI uri = ServletUriComponentsBuilder.fromCurrentRequest() diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/OrderController.java b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/OrderController.java index 685c4c2..14a0d1a 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/OrderController.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/OrderController.java @@ -1,6 +1,7 @@ package br.com.fiap.grupo30.fastfood.presentation.controllers; import br.com.fiap.grupo30.fastfood.domain.usecases.order.*; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.CustomerGateway; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.AddCustomerCpfRequest; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.AddOrderProductRequest; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.OrderDTO; @@ -60,7 +61,8 @@ public OrderController( "Get a list of orders with statuses READY, PREPARING, and SUBMITTED, sorted by" + " status and date") public ResponseEntity> findOrdersWithSpecificStatuses() { - List orders = listOrdersWithSpecificStatusesUseCase.execute(); + OrderGateway orderGateway = new OrderGateway(); + List orders = listOrdersWithSpecificStatusesUseCase.execute(orderGateway); return ResponseEntity.ok().body(orders); } @@ -72,7 +74,8 @@ public ResponseEntity> findOrdersWithSpecificStatuses() { + " sorted by date via RequestParam. i.e., ?status=") public ResponseEntity> findOrdersByStatus( @RequestParam(value = "status", required = false) String status) { - List orders = listAllOrdersByStatus.execute(status); + OrderGateway orderGateway = new OrderGateway(); + List orders = listAllOrdersByStatus.execute(orderGateway, status); return ResponseEntity.ok().body(orders); } @@ -81,7 +84,8 @@ public ResponseEntity> findOrdersByStatus( summary = "Get an order by ID", description = "Retrieve a specific order based on its ID") public ResponseEntity findById(@PathVariable Long orderId) { - OrderDTO order = getOrderUseCase.execute(orderId); + OrderGateway orderGateway = new OrderGateway(); + OrderDTO order = getOrderUseCase.execute(orderGateway, orderId); return ResponseEntity.ok().body(order); } @@ -91,7 +95,9 @@ public ResponseEntity findById(@PathVariable Long orderId) { description = "Create a new order and return the new order's data") public ResponseEntity startNewOrder( @RequestBody(required = false) AddCustomerCpfRequest request) { - OrderDTO order = startNewOrderUseCase.execute(request.getCpf()); + OrderGateway orderGateway = new OrderGateway(); + CustomerGateway customerGateway= new CustomerGateway(); + OrderDTO order = startNewOrderUseCase.execute(orderGateway, customerGateway, request.getCpf()); URI uri = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{orderId}") @@ -104,8 +110,10 @@ public ResponseEntity startNewOrder( @Operation(summary = "Add a product to an order", description = "Adds a product to an order") public ResponseEntity addProduct( @PathVariable Long orderId, @RequestBody AddOrderProductRequest request) { + OrderGateway orderGateway = new OrderGateway(); + ProductGateway productGateway = new ProductGateway(); OrderDTO order = - addProductToOrderUseCase.execute( + addProductToOrderUseCase.execute(orderGateway, productGateway, orderId, request.getProductId(), request.getQuantity()); return ResponseEntity.ok().body(order); } @@ -116,6 +124,8 @@ public ResponseEntity addProduct( description = "Removes a product from an order") public ResponseEntity removeProduct( @PathVariable Long orderId, @PathVariable Long productId) { + OrderGateway orderGateway = new OrderGateway(); + ProductGateway productGateway = new ProductGateway(); OrderDTO order = removeProductFromOrderUseCase.execute(orderId, productId); return ResponseEntity.ok().body(order); } @@ -125,6 +135,7 @@ public ResponseEntity removeProduct( summary = "Submit an order for preparation", description = "Submits an order for preparation and return the order's data") public ResponseEntity submitOrder(@PathVariable Long orderId) { + OrderGateway orderGateway = new OrderGateway(); OrderDTO order = submitOrderUseCase.execute(orderId); return ResponseEntity.ok().body(order); } @@ -134,6 +145,7 @@ public ResponseEntity submitOrder(@PathVariable Long orderId) { summary = "Start preparing an order", description = "Start preparing an order and return the order's data") public ResponseEntity startPreparingOrder(@PathVariable Long orderId) { + OrderGateway orderGateway = new OrderGateway(); OrderDTO order = startPreparingOrderUseCase.execute(orderId); return ResponseEntity.ok().body(order); } @@ -143,6 +155,7 @@ public ResponseEntity startPreparingOrder(@PathVariable Long orderId) summary = "Finish preparing an order", description = "Finish preparing an order and return the order's data") public ResponseEntity finishPreparingOrder(@PathVariable Long orderId) { + OrderGateway orderGateway = new OrderGateway(); OrderDTO order = finishPreparingOrderUseCase.execute(orderId); return ResponseEntity.ok().body(order); } @@ -152,7 +165,8 @@ public ResponseEntity finishPreparingOrder(@PathVariable Long orderId) summary = "Deliver an order", description = "Deliver an order and return the order's data") public ResponseEntity deliverOrder(@PathVariable Long orderId) { - OrderDTO order = deliverOrderUseCase.execute(orderId); + OrderGateway orderGateway = new OrderGateway(); + OrderDTO order = deliverOrderUseCase.execute(orderGateway, orderId); return ResponseEntity.ok().body(order); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/PaymentResource.java b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/PaymentResource.java index 9415fd5..fb6fc03 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/PaymentResource.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/PaymentResource.java @@ -35,7 +35,9 @@ public PaymentResource( @Operation(summary = "Generate qrcode for order payment collection") public ResponseEntity generateQrCodeForPaymentCollection( @PathVariable Long orderId) { - PaymentQrCodeDTO qrCode = this.generatePaymentQrCodeUseCase.execute(orderId); + OrderGateway orderGateway = new OrderGateway(); + MercadoPagoGateway mercadoPagoGateway = new MercadoPagoGateway(); + PaymentQrCodeDTO qrCode = this.generatePaymentQrCodeUseCase.execute(orderGateway, mercadoPagoGateway, orderId); return ResponseEntity.ok().body(qrCode); } @@ -43,8 +45,8 @@ public ResponseEntity generateQrCodeForPaymentCollection( @Operation(summary = "Collect payment by cash") public ResponseEntity collectPaymentByBash( @PathVariable Long orderId, @RequestBody CollectPaymentViaCashRequest request) { - OrderDTO order = - this.collectOrderPaymentViaCashUseCase.execute(orderId, request.getAmount()); + OrderGateway orderGateway = new OrderGateway(); + OrderDTO order = this.collectOrderPaymentViaCashUseCase.execute(orderGateway, orderId, request.getAmount()); return ResponseEntity.ok().body(order); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/ProductController.java b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/ProductController.java index afb7784..e7d4120 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/ProductController.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/ProductController.java @@ -1,6 +1,7 @@ package br.com.fiap.grupo30.fastfood.presentation.controllers; import br.com.fiap.grupo30.fastfood.domain.usecases.product.*; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.CategoryGateway; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.ProductDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -48,7 +49,8 @@ public ProductController( + "via RequestParam. i.e., ?categoryId=1") public ResponseEntity> findProductsByCategoryId( @RequestParam(value = "categoryId", defaultValue = "0") Long categoryId) { - List products = this.listProductsByCategoryUseCase.execute(categoryId); + ProductGateway productGateway = new ProductGateway(); + List products = this.listProductsByCategoryUseCase.execute(productGateway, categoryId); return ResponseEntity.ok().body(products); } @@ -57,7 +59,8 @@ public ResponseEntity> findProductsByCategoryId( summary = "Get a product by ID", description = "Retrieve a specific product based on its ID") public ResponseEntity findProductById(@PathVariable Long id) { - ProductDTO dto = this.getProductUseCase.execute(id); + ProductGateway productGateway = new ProductGateway(); + ProductDTO dto = this.getProductUseCase.execute(productGateway, id); return ResponseEntity.ok().body(dto); } @@ -66,8 +69,13 @@ public ResponseEntity findProductById(@PathVariable Long id) { summary = "Create a new product", description = "Create a new product and return the created product's data") public ResponseEntity createProduct(@RequestBody @Valid ProductDTO dto) { + ProductGateway productGateway = new ProductGateway(); + CategoryGateway categoryGateway= new CategoryGateway(); + ProductDTO dtoCreated = this.createProductUseCase.execute( + productGateway, + categoryGateway, dto.getName(), dto.getDescription(), dto.getPrice(), @@ -87,8 +95,12 @@ public ResponseEntity createProduct(@RequestBody @Valid ProductDTO d description = "Update the data of an existing product based on its ID") public ResponseEntity updateProduct( @PathVariable Long id, @RequestBody @Valid ProductDTO dto) { + ProductGateway productGateway = new ProductGateway(); + CategoryGateway categoryGateway= new CategoryGateway(); ProductDTO dtoUpdated = this.updateProductUseCase.execute( + productGateway, + categoryGateway, id, dto.getName(), dto.getDescription(), @@ -103,7 +115,8 @@ public ResponseEntity updateProduct( summary = "Delete a product", description = "Delete an existing product based on its ID") public ResponseEntity deleteProduct(@PathVariable Long id) { - this.deleteProductUseCase.execute(id); + ProductGateway productGateway = new ProductGateway(); + this.deleteProductUseCase.execute(productGateway, id); return ResponseEntity.noContent().build(); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/WebhookResource.java b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/WebhookResource.java index fc199bf..1eabca8 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/WebhookResource.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/presentation/controllers/WebhookResource.java @@ -72,8 +72,10 @@ else if (payload.containsKey("action") && !payload.containsKey("topic")) { } private void handlePaymentEvent(MercadoPagoActionEventDTO event) { + OrderGateway orderGateway = new OrderGateway(); + MercadoPagoGateway mercadoPagoGateway = new MercadoPagoGateway(); if (MercadoPagoAction.PAYMENT_CREATED.getValue().equals(event.getAction())) { - collectOrderPaymentMercadoPago.execute(event); + collectOrderPaymentMercadoPago.execute(orderGateway, mercadoPagoGateway, event); } else { LOG.warn("Ignoring unimplemented payment event", event); }