-
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.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/net/skhu/tastyinventory_be/controller/menu/dto/response/MenuResponseDto.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,15 @@ | ||
package net.skhu.tastyinventory_be.controller.menu.dto.response; | ||
|
||
import net.skhu.tastyinventory_be.controller.inventory.dto.response.InventoryResponseDto; | ||
|
||
import java.util.List; | ||
|
||
public record MenuResponseDto( | ||
String name, | ||
String imageUrl, | ||
List<InventoryResponseDto> inventories | ||
) { | ||
public static MenuResponseDto of(String name, String imageUrl, List<InventoryResponseDto> inventories) { | ||
return new MenuResponseDto(name, imageUrl, inventories); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/net/skhu/tastyinventory_be/service/MenuService.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,38 @@ | ||
package net.skhu.tastyinventory_be.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.skhu.tastyinventory_be.controller.inventory.dto.response.InventoryResponseDto; | ||
import net.skhu.tastyinventory_be.controller.menu.dto.response.MenuResponseDto; | ||
import net.skhu.tastyinventory_be.domain.menu.Menu; | ||
import net.skhu.tastyinventory_be.domain.menu.MenuRepository; | ||
import net.skhu.tastyinventory_be.domain.recipe.RecipeRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Service | ||
public class MenuService { | ||
private final MenuRepository menuRepository; | ||
private final RecipeRepository recipeRepository; | ||
|
||
public List<MenuResponseDto> findAll() { | ||
List<Menu> menuList = menuRepository.findAll(); | ||
List<MenuResponseDto> result = new ArrayList<>(); | ||
for (Menu menu : menuList) { | ||
result.add(MenuResponseDto.of( | ||
menu.getName(), | ||
menu.getImageUrl(), | ||
recipeRepository.findAllByMenu(menu) | ||
.stream() | ||
.map(recipe -> InventoryResponseDto.from(recipe.getInventory())) | ||
.collect(Collectors.toList()) | ||
)); | ||
} | ||
return result; | ||
} | ||
} |