diff --git a/src/main/java/org/hankki/hankkiserver/api/menu/service/MenuCommandService.java b/src/main/java/org/hankki/hankkiserver/api/menu/service/MenuCommandService.java index 134d027a..96325c8e 100644 --- a/src/main/java/org/hankki/hankkiserver/api/menu/service/MenuCommandService.java +++ b/src/main/java/org/hankki/hankkiserver/api/menu/service/MenuCommandService.java @@ -49,8 +49,9 @@ public void modifyMenu(final MenuPatchCommand command) { @Transactional public MenusPostResponse createMenus(final MenusPostCommand command) { Store findStore = storeFinder.findByIdWhereDeletedIsFalse(command.storeId()); + List allMenus = menuFinder.findAllByStore(findStore); List menus = command.menu().stream() - .filter(c -> !validateMenuConflict(findStore, c.name())) + .filter(c -> !validateMenuConflict(allMenus, c.name())) .map(c -> Menu.create(findStore, c.name(), c.price())) .toList(); menuUpdater.saveAll(menus); @@ -69,8 +70,8 @@ private void updateLowestPriceInStore(final Store findStore) { findStore.updateLowestPrice(menuFinder.findLowestPriceByStore(findStore)); } - private boolean validateMenuConflict(final Store store, final String menuName) { - return menuFinder.existsByStoreAndName(store, menuName); + private boolean validateMenuConflict(final List menus, final String menuName) { + return menus.stream().anyMatch(menu -> menu.getName().equals(menuName)); } private void checkNoMenuInStore(final Store store, final long userId) {