Skip to content

Commit

Permalink
[refac] change to storage logic bulk operation
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed Oct 9, 2024
1 parent 5b48fdd commit 04f7cb9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.hankki.hankkiserver.api.menu.service.command.MenuDeleteCommand;
import org.hankki.hankkiserver.api.menu.service.command.MenuPatchCommand;
import org.hankki.hankkiserver.api.menu.service.command.MenusPostCommand;
import org.hankki.hankkiserver.api.menu.service.response.MenuPostResponse;
import org.hankki.hankkiserver.api.menu.service.response.MenusPostResponse;
import org.hankki.hankkiserver.api.store.service.StoreFinder;
import org.hankki.hankkiserver.domain.menu.model.Menu;
Expand Down Expand Up @@ -40,14 +39,11 @@ public void modifyMenu(final MenuPatchCommand command) {
@Transactional
public MenusPostResponse createMenus(final MenusPostCommand command) {
Store findStore = storeFinder.findByIdWhereDeletedIsFalse(command.storeId());
List<MenuPostResponse> menus = command.menu().stream()
List<Menu> menus = command.menu().stream()
.filter(c -> !validateMenuConflict(findStore, c.name()))
.map(c -> {
Menu menu = Menu.create(findStore, c.name(), c.price());
menuUpdater.save(menu);
return MenuPostResponse.of(menu);
})
.map(c -> Menu.create(findStore, c.name(), c.price()))
.toList();
menuUpdater.saveAll(menus);
updateLowestPriceInStore(findStore);
return MenusPostResponse.of(menus);
}
Expand All @@ -56,7 +52,6 @@ private void updateLowestPriceInStore(final Store findStore) {
findStore.updateLowestPrice(menuFinder.findLowestPriceByStore(findStore));
}


private boolean validateMenuConflict(Store store, String menuName) {
return menuFinder.existsByStoreAndName(store, menuName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package org.hankki.hankkiserver.api.menu.service.response;

import org.hankki.hankkiserver.domain.menu.model.Menu;

import java.util.List;

public record MenusPostResponse(
List<MenuPostResponse> menuList
) {
public static MenusPostResponse of(List<MenuPostResponse> menus) {
return new MenusPostResponse(menus);
public static MenusPostResponse of(List<Menu> menus) {
List<MenuPostResponse> menuResponses = menus.stream()
.map(MenuPostResponse::of)
.toList();
return new MenusPostResponse(menuResponses);
}
}

0 comments on commit 04f7cb9

Please sign in to comment.