Skip to content

Commit

Permalink
fix: menu mapper feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Jul 29, 2024
1 parent f2f4e8a commit 4638ce7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.likelion.apimodule.store.dto.MenuDetailDTO;
import com.likelion.apimodule.store.dto.StoreInfo;
import com.likelion.apimodule.store.dto.StoreResponse;
import com.likelion.apimodule.store.mapper.MenuMapper;
import com.likelion.coremodule.cart.domain.Cart;
import com.likelion.coremodule.cart.service.CartQueryService;
import com.likelion.coremodule.menu.domain.Menu;
Expand All @@ -22,7 +23,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -60,22 +60,10 @@ public List<StoreInfo> findStoreInfo() {
return storeInfoList;
}

public StoreInfo findStoreInfoByMenuId(Long menuId) {
public MenuDetailDTO findMenuById(Long menuId) {

Menu menu = menuQueryService.findMenuById(menuId);
Store store = menu.getStore();

List<Menu> menus = menuQueryService.findMenusByStoreId(store.getId());
List<MenuDetailDTO> menuDetails = menus.stream()
.map(m -> new MenuDetailDTO(
m.getId(),
m.getName(),
m.getPrice(),
m.getContent(),
m.getImageUrl()))
.collect(Collectors.toList());

List<Review> reviews = reviewQueryService.findReviewsByStoreId(store.getId());
return getStoreInfo(store, reviews, menuDetails);
return MenuMapper.toInfoDTO(menu);
}

private StoreInfo getStoreInfo(Store store, List<Review> reviews, List<MenuDetailDTO> menuDetails) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.likelion.apimodule.store.mapper;

import com.likelion.apimodule.store.dto.MenuDetailDTO;
import com.likelion.coremodule.menu.domain.Menu;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MenuMapper {

public static MenuDetailDTO toInfoDTO(Menu menu) {
return new MenuDetailDTO(
menu.getId(),
menu.getName(),
menu.getPrice(),
menu.getContent(),
menu.getImageUrl()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.likelion.apimodule.store.presentation;

import com.likelion.apimodule.store.application.StoreInfoUseCase;
import com.likelion.apimodule.store.dto.MenuDetailDTO;
import com.likelion.apimodule.store.dto.StoreInfo;
import com.likelion.commonmodule.exception.common.ApplicationResponse;
import com.likelion.commonmodule.security.util.AuthConsts;
Expand Down Expand Up @@ -52,9 +53,9 @@ public ApplicationResponse<List<StoreInfo>> getStoreInfo() {
}
)
@Operation(summary = "가게 메뉴 정보 확인 API", description = "가게 메뉴 정보 확인 API 입니다.")
public ApplicationResponse<StoreInfo> getStoreInfoByMenuId(@PathVariable Long menuId) {
public ApplicationResponse<MenuDetailDTO> getMenuInfoById(@PathVariable Long menuId) {

StoreInfo info = storeInfoUseCase.findStoreInfoByMenuId(menuId);
MenuDetailDTO info = storeInfoUseCase.findMenuById(menuId);
return ApplicationResponse.ok(info);
}

Expand Down

0 comments on commit 4638ce7

Please sign in to comment.