This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from 7SOATSquad30/feat/add-list-orders
feat: add list orders route
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/order/ListOrdersUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |