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..5fd44ec 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,7 @@ public class ListAllCategoriesInMenuUseCase { - private final CategoryGateway categoryGateway; - - public ListAllCategoriesInMenuUseCase(CategoryGateway categoryGateway) { - this.categoryGateway = categoryGateway; - } - - 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..1fe4294 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,7 @@ public class FindCustomerByCpfUseCase { - private final CustomerGateway customerGateway; - - public FindCustomerByCpfUseCase(CustomerGateway customerGateway) { - this.customerGateway = customerGateway; - } - - 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..9bfaea3 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,8 @@ public class RegisterNewCustomerUseCase { - private final CustomerGateway customerGateway; - - public RegisterNewCustomerUseCase(CustomerGateway customerGateway) { - this.customerGateway = customerGateway; - } - - 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..81e0b94 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,12 @@ public class AddProductToOrderUseCase { - private final OrderGateway orderGateway; - private final ProductGateway productGateway; - - public AddProductToOrderUseCase(OrderGateway orderGateway, ProductGateway productGateway) { - this.orderGateway = orderGateway; - this.productGateway = productGateway; - } - - 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..dfc6935 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,7 @@ public class DeliverOrderUseCase { - private final OrderGateway orderGateway; - - public DeliverOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; - } - - 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..fc40603 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,7 @@ public class FinishPreparingOrderUseCase { - private final OrderGateway orderGateway; - - public FinishPreparingOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; - } - - 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..571b990 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,7 @@ public class GetOrderUseCase { - private final OrderGateway orderGateway; - - public GetOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; - } - - 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..74950a7 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,7 @@ public class ListOrdersByStatusUseCase { - private final OrderGateway orderGateway; - - public ListOrdersByStatusUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; - } - - 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..03fa338 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,7 @@ public class ListOrdersWithSpecificStatusesUseCase { - private final OrderGateway orderGateway; - - public ListOrdersWithSpecificStatusesUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; - } - - 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..14ede5f 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,11 @@ public class RemoveProductFromOrderUseCase { - private final OrderGateway orderGateway; - private final ProductGateway productGateway; - - public RemoveProductFromOrderUseCase(OrderGateway orderGateway, ProductGateway productGateway) { - this.orderGateway = orderGateway; - this.productGateway = productGateway; - } - - 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..f9bfa74 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,19 @@ public class StartNewOrderUseCase { - private final OrderGateway orderGateway; - private final CustomerGateway customerGateway; - - public StartNewOrderUseCase(OrderGateway orderGateway, CustomerGateway customerGateway) { - this.orderGateway = orderGateway; - this.customerGateway = customerGateway; - } - - 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..6c388b9 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,7 @@ public class StartPreparingOrderUseCase { - private final OrderGateway orderGateway; - - public StartPreparingOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; - } - - 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..9091d21 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,13 +7,7 @@ public class SubmitOrderUseCase { - private final OrderGateway orderGateway; - - public SubmitOrderUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; - } - - public OrderDTO execute(Long orderId) { + public OrderDTO execute(OrderGateway orderGateway, Long orderId) { Order order = orderGateway.findById(orderId); order.setStatus(OrderStatus.SUBMITTED); return orderGateway.save(order).toDTO(); 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..f753836 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 @@ -3,20 +3,13 @@ import br.com.fiap.grupo30.fastfood.domain.entities.Order; import br.com.fiap.grupo30.fastfood.infrastructure.gateways.OrderGateway; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.OrderDTO; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class CollectOrderPaymentViaCashUseCase { - private final OrderGateway orderGateway; - @Autowired - public CollectOrderPaymentViaCashUseCase(OrderGateway orderGateway) { - this.orderGateway = orderGateway; - } - - public OrderDTO execute(Long orderId, Double paidAmount) { - Order order = this.orderGateway.findById(orderId); + public OrderDTO execute(OrderGateway orderGateway, Long orderId, Double paidAmount) { + Order order = 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..0c5dbe9 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 @@ -8,29 +8,20 @@ import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.mercadopago.MercadoPagoPaymentStatus; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.mercadopago.events.MercadoPagoActionEventDTO; import br.com.fiap.grupo30.fastfood.presentation.presenters.exceptions.PaymentProcessingFailedException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @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 OrderDTO execute(MercadoPagoActionEventDTO mercadoPagoPaymentEvent) { + public OrderDTO execute( + OrderGateway orderGateway, + MercadoPagoGateway mercadoPagoGateway, + MercadoPagoActionEventDTO mercadoPagoPaymentEvent) { try { MercadoPagoPaymentDTO payment = - this.mercadoPagoGateway.getPaymentState( - mercadoPagoPaymentEvent.getData().getId()); + mercadoPagoGateway.getPaymentState(mercadoPagoPaymentEvent.getData().getId()); - Order order = - this.orderGateway.findById(Long.parseLong(payment.getExternalReference())); + Order order = orderGateway.findById(Long.parseLong(payment.getExternalReference())); if (MercadoPagoPaymentStatus.APPROVED.getValue().equals(payment.getStatus())) { order.setPaymentCollected(payment.getTransactionAmount()); 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..d0acafd 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 @@ -6,34 +6,25 @@ import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.PaymentQrCodeDTO; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.mercadopago.MercadoPagoQrCodeDTO; import br.com.fiap.grupo30.fastfood.presentation.presenters.exceptions.PaymentProcessingFailedException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @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 PaymentQrCodeDTO execute(Long orderId) { - Order order = this.orderGateway.findById(orderId); + public PaymentQrCodeDTO execute( + OrderGateway orderGateway, MercadoPagoGateway mercadoPagoGateway, Long orderId) { + Order order = orderGateway.findById(orderId); MercadoPagoQrCodeDTO qrCodeResponse; try { qrCodeResponse = - this.mercadoPagoGateway.createQrCodeForOrderPaymentCollection(order.toDTO()); + mercadoPagoGateway.createQrCodeForOrderPaymentCollection(order.toDTO()); } catch (Exception e) { throw new PaymentProcessingFailedException("Could not start payment processing", e); } order.setPaymentProcessing(); - this.orderGateway.save(order); + orderGateway.save(order); return new PaymentQrCodeDTO(qrCodeResponse.getQrData()); } 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..b780b7a 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 @@ -8,17 +8,15 @@ public class CreateProductUseCase { - private final ProductGateway productGateway; - private final CategoryGateway categoryGateway; - - public CreateProductUseCase(ProductGateway productGateway, CategoryGateway categoryGateway) { - this.productGateway = productGateway; - this.categoryGateway = categoryGateway; - } - 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..9cd559a 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,7 @@ public class DeleteProductUseCase { - private final ProductGateway productGateway; - - public DeleteProductUseCase(ProductGateway productGateway) { - this.productGateway = productGateway; - } - - 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..2f613db 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,7 @@ public class GetProductUseCase { - private final ProductGateway productGateway; - - public GetProductUseCase(ProductGateway productGateway) { - this.productGateway = productGateway; - } - - 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..811a5e4 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,7 @@ public class ListProductsByCategoryUseCase { - private final ProductGateway productGateway; - - public ListProductsByCategoryUseCase(ProductGateway productGateway) { - this.productGateway = productGateway; - } - - 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..acc9e3b 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,24 +8,18 @@ public class UpdateProductUseCase { - private final ProductGateway productGateway; - private final CategoryGateway categoryGateway; - - public UpdateProductUseCase(ProductGateway productGateway, CategoryGateway categoryGateway) { - this.productGateway = productGateway; - this.categoryGateway = categoryGateway; - } - public ProductDTO execute( + ProductGateway productGateway, + CategoryGateway categoryGateway, Long productId, String name, String description, Double price, String imgUrl, String category) { - Category categoryEntity = this.categoryGateway.findOne(category); + Category categoryEntity = categoryGateway.findOne(category); - Product product = this.productGateway.findById(productId); + Product product = productGateway.findById(productId); product.setName(name); product.setDescription(description); product.setPrice(price); diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/CategoryConfiguration.java b/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/CategoryConfiguration.java index b668c1e..f31138b 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/CategoryConfiguration.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/CategoryConfiguration.java @@ -16,8 +16,7 @@ public CategoryRepository categoryRepository(JpaCategoryRepository jpaCategoryRe } @Bean - public ListAllCategoriesInMenuUseCase listAllCategoriesInMenuUseCase( - CategoryGateway categoryGateway) { - return new ListAllCategoriesInMenuUseCase(categoryGateway); + public ListAllCategoriesInMenuUseCase listAllCategoriesInMenuUseCase() { + return new ListAllCategoriesInMenuUseCase(); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/CustomerConfiguration.java b/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/CustomerConfiguration.java index b055182..2040bd0 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/CustomerConfiguration.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/CustomerConfiguration.java @@ -17,12 +17,12 @@ public CustomerRepository customerRepository(JpaCustomerRepository jpaCustomerRe } @Bean - public FindCustomerByCpfUseCase findCustomerByCpfUseCase(CustomerGateway customerGateway) { - return new FindCustomerByCpfUseCase(customerGateway); + public FindCustomerByCpfUseCase findCustomerByCpfUseCase() { + return new FindCustomerByCpfUseCase(); } @Bean - public RegisterNewCustomerUseCase registerNewCustomerUseCase(CustomerGateway customerGateway) { - return new RegisterNewCustomerUseCase(customerGateway); + public RegisterNewCustomerUseCase registerNewCustomerUseCase() { + return new RegisterNewCustomerUseCase(); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/OrderConfiguration.java b/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/OrderConfiguration.java index 7fbe815..f1cfb8c 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/OrderConfiguration.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/OrderConfiguration.java @@ -2,9 +2,7 @@ import br.com.fiap.grupo30.fastfood.domain.repositories.OrderRepository; import br.com.fiap.grupo30.fastfood.domain.usecases.order.*; -import br.com.fiap.grupo30.fastfood.infrastructure.gateways.CustomerGateway; import br.com.fiap.grupo30.fastfood.infrastructure.gateways.OrderGateway; -import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaOrderRepository; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -18,56 +16,52 @@ public OrderRepository orderRepository(JpaOrderRepository jpaOrderRepository) { } @Bean - public ListOrdersWithSpecificStatusesUseCase listOrdersBySpecificStatusesUseCase( - OrderGateway orderGateway) { - return new ListOrdersWithSpecificStatusesUseCase(orderGateway); + public ListOrdersWithSpecificStatusesUseCase listOrdersBySpecificStatusesUseCase() { + return new ListOrdersWithSpecificStatusesUseCase(); } @Bean - public ListOrdersByStatusUseCase listOrdersByStatusUseCase(OrderGateway orderGateway) { - return new ListOrdersByStatusUseCase(orderGateway); + public ListOrdersByStatusUseCase listOrdersByStatusUseCase() { + return new ListOrdersByStatusUseCase(); } @Bean - public GetOrderUseCase getOrderUseCase(OrderGateway orderGateway) { - return new GetOrderUseCase(orderGateway); + public GetOrderUseCase getOrderUseCase() { + return new GetOrderUseCase(); } @Bean - public StartNewOrderUseCase startNewOrderUseCase( - OrderGateway orderGateway, CustomerGateway customerGateway) { - return new StartNewOrderUseCase(orderGateway, customerGateway); + public StartNewOrderUseCase startNewOrderUseCase() { + return new StartNewOrderUseCase(); } @Bean - public AddProductToOrderUseCase addProductToOrderUseCase( - OrderGateway orderGateway, ProductGateway productGateway) { - return new AddProductToOrderUseCase(orderGateway, productGateway); + public AddProductToOrderUseCase addProductToOrderUseCase() { + return new AddProductToOrderUseCase(); } @Bean - public RemoveProductFromOrderUseCase removeProductFromOrderUseCase( - OrderGateway orderGateway, ProductGateway productGateway) { - return new RemoveProductFromOrderUseCase(orderGateway, productGateway); + public RemoveProductFromOrderUseCase removeProductFromOrderUseCase() { + return new RemoveProductFromOrderUseCase(); } @Bean - public SubmitOrderUseCase submitOrderUseCase(OrderGateway orderGateway) { - return new SubmitOrderUseCase(orderGateway); + public SubmitOrderUseCase submitOrderUseCase() { + return new SubmitOrderUseCase(); } @Bean - public StartPreparingOrderUseCase startPreparingOrderUseCase(OrderGateway orderGateway) { - return new StartPreparingOrderUseCase(orderGateway); + public StartPreparingOrderUseCase startPreparingOrderUseCase() { + return new StartPreparingOrderUseCase(); } @Bean - public FinishPreparingOrderUseCase finishPreparingOrderUseCase(OrderGateway orderGateway) { - return new FinishPreparingOrderUseCase(orderGateway); + public FinishPreparingOrderUseCase finishPreparingOrderUseCase() { + return new FinishPreparingOrderUseCase(); } @Bean - public DeliverOrderUseCase deliverOrderUseCase(OrderGateway orderGateway) { - return new DeliverOrderUseCase(orderGateway); + public DeliverOrderUseCase deliverOrderUseCase() { + return new DeliverOrderUseCase(); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/ProductConfiguration.java b/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/ProductConfiguration.java index 9b1b0db..4a6d2de 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/ProductConfiguration.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/ProductConfiguration.java @@ -2,7 +2,6 @@ import br.com.fiap.grupo30.fastfood.domain.repositories.ProductRepository; import br.com.fiap.grupo30.fastfood.domain.usecases.product.*; -import br.com.fiap.grupo30.fastfood.infrastructure.gateways.CategoryGateway; import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaProductRepository; import org.springframework.context.annotation.Bean; @@ -17,30 +16,27 @@ public ProductRepository productRepository(JpaProductRepository jpaProductReposi } @Bean - public ListProductsByCategoryUseCase listProductsByCategoryUseCase( - ProductGateway productGateway) { - return new ListProductsByCategoryUseCase(productGateway); + public ListProductsByCategoryUseCase listProductsByCategoryUseCase() { + return new ListProductsByCategoryUseCase(); } @Bean - public GetProductUseCase getProductUseCase(ProductGateway productGateway) { - return new GetProductUseCase(productGateway); + public GetProductUseCase getProductUseCase() { + return new GetProductUseCase(); } @Bean - public CreateProductUseCase createProductUseCase( - ProductGateway productGateway, CategoryGateway categoryGateway) { - return new CreateProductUseCase(productGateway, categoryGateway); + public CreateProductUseCase createProductUseCase() { + return new CreateProductUseCase(); } @Bean - public UpdateProductUseCase updateProductUseCase( - ProductGateway productGateway, CategoryGateway categoryGateway) { - return new UpdateProductUseCase(productGateway, categoryGateway); + public UpdateProductUseCase updateProductUseCase() { + return new UpdateProductUseCase(); } @Bean - public DeleteProductUseCase deleteProductUseCase(ProductGateway productGateway) { - return new DeleteProductUseCase(productGateway); + public DeleteProductUseCase deleteProductUseCase() { + return new DeleteProductUseCase(); } } 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..d49ea1d 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 @@ -1,6 +1,8 @@ package br.com.fiap.grupo30.fastfood.presentation.controllers; import br.com.fiap.grupo30.fastfood.domain.usecases.category.ListAllCategoriesInMenuUseCase; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.CategoryGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaCategoryRepository; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.CategoryDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -17,10 +19,14 @@ public class CategoryController { private final ListAllCategoriesInMenuUseCase listAllCategoriesInMenuUseCase; + public final JpaCategoryRepository jpaCategoryRepository; @Autowired - public CategoryController(ListAllCategoriesInMenuUseCase listAllCategoriesInMenuUseCase) { + public CategoryController( + ListAllCategoriesInMenuUseCase listAllCategoriesInMenuUseCase, + JpaCategoryRepository jpaCategoryRepository) { this.listAllCategoriesInMenuUseCase = listAllCategoriesInMenuUseCase; + this.jpaCategoryRepository = jpaCategoryRepository; } @GetMapping @@ -28,7 +34,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(jpaCategoryRepository); + 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..dd597eb 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,8 @@ 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.infrastructure.persistence.repositories.JpaCustomerRepository; 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; @@ -19,20 +21,24 @@ public class CustomerController { private final FindCustomerByCpfUseCase findCustomerByCpfUseCase; private final RegisterNewCustomerUseCase registerNewCustomerUseCase; + private final JpaCustomerRepository jpaCustomerRepository; @Autowired public CustomerController( FindCustomerByCpfUseCase findCustomerByCpfUseCase, - RegisterNewCustomerUseCase registerNewCustomerUseCase) { + RegisterNewCustomerUseCase registerNewCustomerUseCase, + JpaCustomerRepository jpaCustomerRepository) { this.findCustomerByCpfUseCase = findCustomerByCpfUseCase; this.registerNewCustomerUseCase = registerNewCustomerUseCase; + this.jpaCustomerRepository = jpaCustomerRepository; } @GetMapping @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(jpaCustomerRepository); + CustomerDTO customer = this.findCustomerByCpfUseCase.execute(customerGateway, cpf); return ResponseEntity.ok().body(customer); } @@ -41,9 +47,10 @@ 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 = new CustomerGateway(jpaCustomerRepository); CustomerDTO createdCustomer = this.registerNewCustomerUseCase.execute( - dto.getName(), dto.getCpf(), dto.getEmail()); + customerGateway, dto.getName(), dto.getCpf(), dto.getEmail()); URI uri = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{cpf}") 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 b078232..47dc740 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 @@ -2,6 +2,12 @@ import br.com.fiap.grupo30.fastfood.domain.usecases.order.*; import br.com.fiap.grupo30.fastfood.infrastructure.auth.AdminRequired; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.CustomerGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.OrderGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaCustomerRepository; +import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaOrderRepository; +import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaProductRepository; 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; @@ -29,6 +35,9 @@ public class OrderController { private final StartPreparingOrderUseCase startPreparingOrderUseCase; private final FinishPreparingOrderUseCase finishPreparingOrderUseCase; private final DeliverOrderUseCase deliverOrderUseCase; + private final JpaOrderRepository jpaOrderRepository; + private final JpaProductRepository jpaProductRepository; + private final JpaCustomerRepository jpaCustomerRepository; @Autowired public OrderController( @@ -41,7 +50,10 @@ public OrderController( ListOrdersByStatusUseCase listAllOrdersByStatus, StartPreparingOrderUseCase startPreparingOrderUseCase, FinishPreparingOrderUseCase finishPreparingOrderUseCase, - DeliverOrderUseCase deliverOrderUseCase) { + DeliverOrderUseCase deliverOrderUseCase, + JpaOrderRepository jpaOrderRepository, + JpaProductRepository jpaProductRepository, + JpaCustomerRepository jpaCustomerRepository) { this.startNewOrderUseCase = startNewOrderUseCase; this.addProductToOrderUseCase = addProductToOrderUseCase; this.removeProductFromOrderUseCase = removeProductFromOrderUseCase; @@ -52,6 +64,9 @@ public OrderController( this.startPreparingOrderUseCase = startPreparingOrderUseCase; this.finishPreparingOrderUseCase = finishPreparingOrderUseCase; this.deliverOrderUseCase = deliverOrderUseCase; + this.jpaOrderRepository = jpaOrderRepository; + this.jpaProductRepository = jpaProductRepository; + this.jpaCustomerRepository = jpaCustomerRepository; } @GetMapping() @@ -61,7 +76,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(jpaOrderRepository); + List orders = listOrdersWithSpecificStatusesUseCase.execute(orderGateway); return ResponseEntity.ok().body(orders); } @@ -73,7 +89,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(jpaOrderRepository); + List orders = listAllOrdersByStatus.execute(orderGateway, status); return ResponseEntity.ok().body(orders); } @@ -82,7 +99,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(jpaOrderRepository); + OrderDTO order = getOrderUseCase.execute(orderGateway, orderId); return ResponseEntity.ok().body(order); } @@ -92,7 +110,10 @@ 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(jpaOrderRepository); + CustomerGateway customerGateway = new CustomerGateway(jpaCustomerRepository); + OrderDTO order = + startNewOrderUseCase.execute(orderGateway, customerGateway, request.getCpf()); URI uri = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{orderId}") @@ -105,9 +126,15 @@ 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(jpaOrderRepository); + ProductGateway productGateway = new ProductGateway(jpaProductRepository); OrderDTO order = addProductToOrderUseCase.execute( - orderId, request.getProductId(), request.getQuantity()); + orderGateway, + productGateway, + orderId, + request.getProductId(), + request.getQuantity()); return ResponseEntity.ok().body(order); } @@ -117,7 +144,11 @@ public ResponseEntity addProduct( description = "Removes a product from an order") public ResponseEntity removeProduct( @PathVariable Long orderId, @PathVariable Long productId) { - OrderDTO order = removeProductFromOrderUseCase.execute(orderId, productId); + OrderGateway orderGateway = new OrderGateway(jpaOrderRepository); + ProductGateway productGateway = new ProductGateway(jpaProductRepository); + OrderDTO order = + removeProductFromOrderUseCase.execute( + orderGateway, productGateway, orderId, productId); return ResponseEntity.ok().body(order); } @@ -126,7 +157,8 @@ 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) { - OrderDTO order = submitOrderUseCase.execute(orderId); + OrderGateway orderGateway = new OrderGateway(jpaOrderRepository); + OrderDTO order = submitOrderUseCase.execute(orderGateway, orderId); return ResponseEntity.ok().body(order); } @@ -136,7 +168,8 @@ 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) { - OrderDTO order = startPreparingOrderUseCase.execute(orderId); + OrderGateway orderGateway = new OrderGateway(jpaOrderRepository); + OrderDTO order = startPreparingOrderUseCase.execute(orderGateway, orderId); return ResponseEntity.ok().body(order); } @@ -146,7 +179,8 @@ 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) { - OrderDTO order = finishPreparingOrderUseCase.execute(orderId); + OrderGateway orderGateway = new OrderGateway(jpaOrderRepository); + OrderDTO order = finishPreparingOrderUseCase.execute(orderGateway, orderId); return ResponseEntity.ok().body(order); } @@ -156,7 +190,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(jpaOrderRepository); + 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 246a9dd..956d4d1 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 @@ -3,9 +3,13 @@ import br.com.fiap.grupo30.fastfood.domain.usecases.payment.CollectOrderPaymentViaCashUseCase; import br.com.fiap.grupo30.fastfood.domain.usecases.payment.GeneratePaymentQrCodeUseCase; import br.com.fiap.grupo30.fastfood.infrastructure.auth.AdminRequired; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.MercadoPagoGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.OrderGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaOrderRepository; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.CollectPaymentViaCashRequest; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.OrderDTO; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.PaymentQrCodeDTO; +import br.com.fiap.grupo30.fastfood.presentation.presenters.mapper.impl.MercadoPagoOrderMapper; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; @@ -23,20 +27,30 @@ public class PaymentResource { private final GeneratePaymentQrCodeUseCase generatePaymentQrCodeUseCase; private final CollectOrderPaymentViaCashUseCase collectOrderPaymentViaCashUseCase; + private final JpaOrderRepository jpaOrderRepository; + private final MercadoPagoOrderMapper orderMapper; @Autowired public PaymentResource( GeneratePaymentQrCodeUseCase generatePaymentQrCodeUseCase, - CollectOrderPaymentViaCashUseCase collectOrderPaymentViaCashUseCase) { + CollectOrderPaymentViaCashUseCase collectOrderPaymentViaCashUseCase, + JpaOrderRepository jpaOrderRepository, + MercadoPagoOrderMapper orderMapper) { this.generatePaymentQrCodeUseCase = generatePaymentQrCodeUseCase; this.collectOrderPaymentViaCashUseCase = collectOrderPaymentViaCashUseCase; + this.jpaOrderRepository = jpaOrderRepository; + this.orderMapper = orderMapper; } @PostMapping(value = "/{orderId}/qrcode") @Operation(summary = "Generate qrcode for order payment collection") public ResponseEntity generateQrCodeForPaymentCollection( @PathVariable Long orderId) { - PaymentQrCodeDTO qrCode = this.generatePaymentQrCodeUseCase.execute(orderId); + OrderGateway orderGateway = new OrderGateway(jpaOrderRepository); + MercadoPagoGateway mercadoPagoGateway = new MercadoPagoGateway(orderMapper); + PaymentQrCodeDTO qrCode = + this.generatePaymentQrCodeUseCase.execute( + orderGateway, mercadoPagoGateway, orderId); return ResponseEntity.ok().body(qrCode); } @@ -45,8 +59,10 @@ public ResponseEntity generateQrCodeForPaymentCollection( @Operation(summary = "Collect payment by cash") public ResponseEntity collectPaymentByBash( @PathVariable Long orderId, @RequestBody CollectPaymentViaCashRequest request) { + OrderGateway orderGateway = new OrderGateway(jpaOrderRepository); OrderDTO order = - this.collectOrderPaymentViaCashUseCase.execute(orderId, request.getAmount()); + 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 50740c6..47d0a11 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 @@ -2,6 +2,10 @@ import br.com.fiap.grupo30.fastfood.domain.usecases.product.*; import br.com.fiap.grupo30.fastfood.infrastructure.auth.AdminRequired; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.CategoryGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaCategoryRepository; +import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaProductRepository; 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; @@ -25,6 +29,8 @@ public class ProductController { private final CreateProductUseCase createProductUseCase; private final UpdateProductUseCase updateProductUseCase; private final DeleteProductUseCase deleteProductUseCase; + private final JpaProductRepository jpaProductRepository; + private final JpaCategoryRepository jpaCategoryRepository; @Autowired public ProductController( @@ -32,13 +38,17 @@ public ProductController( GetProductUseCase getProductUseCase, CreateProductUseCase createProductUseCase, UpdateProductUseCase updateProductUseCase, - DeleteProductUseCase deleteProductUseCase) { + DeleteProductUseCase deleteProductUseCase, + JpaProductRepository jpaProductRepository, + JpaCategoryRepository jpaCategoryRepository) { this.listProductsByCategoryUseCase = listProductsByCategoryUseCase; this.getProductUseCase = getProductUseCase; this.createProductUseCase = createProductUseCase; this.updateProductUseCase = updateProductUseCase; this.deleteProductUseCase = deleteProductUseCase; + this.jpaProductRepository = jpaProductRepository; + this.jpaCategoryRepository = jpaCategoryRepository; } @GetMapping @@ -49,7 +59,9 @@ 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(jpaProductRepository); + List products = + this.listProductsByCategoryUseCase.execute(productGateway, categoryId); return ResponseEntity.ok().body(products); } @@ -58,7 +70,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(jpaProductRepository); + ProductDTO dto = this.getProductUseCase.execute(productGateway, id); return ResponseEntity.ok().body(dto); } @@ -68,8 +81,12 @@ 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(jpaProductRepository); + CategoryGateway categoryGateway = new CategoryGateway(jpaCategoryRepository); ProductDTO dtoCreated = this.createProductUseCase.execute( + productGateway, + categoryGateway, dto.getName(), dto.getDescription(), dto.getPrice(), @@ -90,8 +107,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(jpaProductRepository); + CategoryGateway categoryGateway = new CategoryGateway(jpaCategoryRepository); ProductDTO dtoUpdated = this.updateProductUseCase.execute( + productGateway, + categoryGateway, id, dto.getName(), dto.getDescription(), @@ -107,7 +128,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(jpaProductRepository); + 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..f092204 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 @@ -1,8 +1,12 @@ package br.com.fiap.grupo30.fastfood.presentation.controllers; import br.com.fiap.grupo30.fastfood.domain.usecases.payment.CollectOrderPaymentViaMercadoPagoUseCase; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.MercadoPagoGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.gateways.OrderGateway; +import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaOrderRepository; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.mercadopago.events.MercadoPagoAction; import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.mercadopago.events.MercadoPagoActionEventDTO; +import br.com.fiap.grupo30.fastfood.presentation.presenters.mapper.impl.MercadoPagoOrderMapper; import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -26,11 +30,17 @@ public class WebhookResource { private static final Logger LOG = LoggerFactory.getLogger(WebhookResource.class); private final CollectOrderPaymentViaMercadoPagoUseCase collectOrderPaymentMercadoPago; + private final JpaOrderRepository jpaOrderRepository; + private final MercadoPagoOrderMapper orderMapper; @Autowired public WebhookResource( - CollectOrderPaymentViaMercadoPagoUseCase collectOrderPaymentMercadoPago) { + CollectOrderPaymentViaMercadoPagoUseCase collectOrderPaymentMercadoPago, + JpaOrderRepository jpaOrderRepository, + MercadoPagoOrderMapper orderMapper) { this.collectOrderPaymentMercadoPago = collectOrderPaymentMercadoPago; + this.jpaOrderRepository = jpaOrderRepository; + this.orderMapper = orderMapper; } @PostMapping(value = "/mercadopago") @@ -72,8 +82,10 @@ else if (payload.containsKey("action") && !payload.containsKey("topic")) { } private void handlePaymentEvent(MercadoPagoActionEventDTO event) { + OrderGateway orderGateway = new OrderGateway(jpaOrderRepository); + MercadoPagoGateway mercadoPagoGateway = new MercadoPagoGateway(orderMapper); if (MercadoPagoAction.PAYMENT_CREATED.getValue().equals(event.getAction())) { - collectOrderPaymentMercadoPago.execute(event); + collectOrderPaymentMercadoPago.execute(orderGateway, mercadoPagoGateway, event); } else { LOG.warn("Ignoring unimplemented payment event", event); }