diff --git a/backend/src/main/java/codesquard/app/api/item/ItemService.java b/backend/src/main/java/codesquard/app/api/item/ItemService.java index da98eaf6c..61e719220 100644 --- a/backend/src/main/java/codesquard/app/api/item/ItemService.java +++ b/backend/src/main/java/codesquard/app/api/item/ItemService.java @@ -108,11 +108,11 @@ public ItemDetailResponse findDetailItemBy(Long itemId, Principal principal) { boolean isInWishList = wishRepository.existsByMemberIdAndItemId(principal.getMemberId(), itemId); if (item.isSeller(principal.getMemberId())) { - Long chatRoomId = chatRoomRepository.findByItemIdAndMemberId(itemId, principal.getMemberId()) - .orElse(null); - return ItemDetailResponse.toSeller(item, principal.getMemberId(), imageUrls, isInWishList, chatRoomId); + return ItemDetailResponse.toSeller(item, principal.getMemberId(), imageUrls, isInWishList); } - return ItemDetailResponse.toBuyer(item, principal.getMemberId(), imageUrls, isInWishList); + Long chatRoomId = chatRoomRepository.findByItemIdAndMemberId(itemId, principal.getMemberId()) + .orElse(null); + return ItemDetailResponse.toBuyer(item, principal.getMemberId(), imageUrls, isInWishList, chatRoomId); } @Transactional diff --git a/backend/src/main/java/codesquard/app/api/item/response/ItemDetailResponse.java b/backend/src/main/java/codesquard/app/api/item/response/ItemDetailResponse.java index 11853af29..c5a1a0979 100644 --- a/backend/src/main/java/codesquard/app/api/item/response/ItemDetailResponse.java +++ b/backend/src/main/java/codesquard/app/api/item/response/ItemDetailResponse.java @@ -51,7 +51,7 @@ private ItemDetailResponse(boolean isSeller, List imageUrls, String sell } public static ItemDetailResponse toBuyer(Item item, Long loginMemberId, List imageUrls, - boolean isInWishList) { + boolean isInWishList, Long chatRoomId) { Member seller = item.getMember(); boolean isSeller = seller.equalId(loginMemberId); return ItemDetailResponse.builder() @@ -68,11 +68,12 @@ public static ItemDetailResponse toBuyer(Item item, Long loginMemberId, List imageUrls, - boolean isInWishList, Long chatRoomId) { + boolean isInWishList) { Member seller = item.getMember(); boolean isSeller = seller.equalId(loginMemberId); return ItemDetailResponse.builder() @@ -89,7 +90,6 @@ public static ItemDetailResponse toSeller(Item item, Long loginMemberId, List imageUrls = List.of("imageUrlValue1", "imageUrlValue2"); - ItemDetailResponse response = ItemDetailResponse.toBuyer(item, seller.getId(), imageUrls, false); + ItemDetailResponse response = ItemDetailResponse.toBuyer(item, seller.getId(), imageUrls, false, null); given(itemService.findDetailItemBy(any(), any())).willReturn(response); + // when & then mockMvc.perform(get("/api/items/1")) .andExpect(status().isOk()) @@ -102,7 +103,7 @@ public void findDetailItemByBuyer() throws Exception { Long loginMemberId = 9999L; List imageUrls = List.of("imageUrlValue1", "imageUrlValue2"); - ItemDetailResponse response = ItemDetailResponse.toSeller(item, loginMemberId, imageUrls, false, 1L); + ItemDetailResponse response = ItemDetailResponse.toSeller(item, loginMemberId, imageUrls, false); given(itemService.findDetailItemBy(any(), any())).willReturn(response); // when & then mockMvc.perform(get("/api/items/1"))