Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from 7SOATSquad30/feat/add-list-orders
Browse files Browse the repository at this point in the history
feat: add list orders route
  • Loading branch information
MuriloKakazu authored May 28, 2024
2 parents 063c91e + 868162d commit e396582
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import br.com.fiap.grupo30.fastfood.application.dto.OrderDTO;
import br.com.fiap.grupo30.fastfood.domain.usecases.order.AddProductToOrderUseCase;
import br.com.fiap.grupo30.fastfood.domain.usecases.order.GetOrderUseCase;
import br.com.fiap.grupo30.fastfood.domain.usecases.order.ListOrdersUseCase;
import br.com.fiap.grupo30.fastfood.domain.usecases.order.RemoveProductFromOrderUseCase;
import br.com.fiap.grupo30.fastfood.domain.usecases.order.StartNewOrderUseCase;
import br.com.fiap.grupo30.fastfood.domain.usecases.order.SubmitOrderUseCase;
Expand All @@ -25,19 +26,29 @@ public class OrderResource {
private final RemoveProductFromOrderUseCase removeProductFromOrderUseCase;
private final GetOrderUseCase getOrderUseCase;
private final SubmitOrderUseCase submitOrderUseCase;
private final ListOrdersUseCase listAllOrdersUseCase;

@Autowired
public OrderResource(
StartNewOrderUseCase startNewOrderUseCase,
AddProductToOrderUseCase addProductToOrderUseCase,
RemoveProductFromOrderUseCase removeProductFromOrderUseCase,
GetOrderUseCase getOrderUseCase,
SubmitOrderUseCase submitOrderUseCase) {
SubmitOrderUseCase submitOrderUseCase,
ListOrdersUseCase listAllOrdersUseCase) {
this.startNewOrderUseCase = startNewOrderUseCase;
this.addProductToOrderUseCase = addProductToOrderUseCase;
this.removeProductFromOrderUseCase = removeProductFromOrderUseCase;
this.getOrderUseCase = getOrderUseCase;
this.submitOrderUseCase = submitOrderUseCase;
this.listAllOrdersUseCase = listAllOrdersUseCase;
}

@GetMapping(value = "/")
@Operation(summary = "List all orders", description = "Return all orders")
public ResponseEntity<OrderDTO[]> listAllOrders() {
OrderDTO[] orders = this.listAllOrdersUseCase.execute();
return ResponseEntity.ok().body(orders);
}

@GetMapping(value = "/{orderId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package br.com.fiap.grupo30.fastfood.domain.usecases.order;

import br.com.fiap.grupo30.fastfood.application.dto.OrderDTO;
import br.com.fiap.grupo30.fastfood.infrastructure.out.persistence.jpa.entities.OrderEntity;
import br.com.fiap.grupo30.fastfood.infrastructure.out.persistence.jpa.repositories.OrderRepository;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ListOrdersUseCase {

private final OrderRepository orderRepository;

@Autowired
public ListOrdersUseCase(OrderRepository orderRepository) {
this.orderRepository = orderRepository;
}

public OrderDTO[] execute() {
List<OrderEntity> allOrders = this.orderRepository.findAll();

return allOrders.stream().map(order -> order.toDTO()).toArray(OrderDTO[]::new);
}
}

0 comments on commit e396582

Please sign in to comment.