From 1d606073d4a213f99689abfa5d5ad3ba20ee0cea Mon Sep 17 00:00:00 2001 From: "yh20studio(tiki)" Date: Tue, 26 Jul 2022 15:10:45 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20InventoryProduct=EC=97=90=20Mem?= =?UTF-8?q?ber=20=EC=A7=81=EC=A0=91=20=EC=B0=B8=EC=A1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: hamcheeseburger --- .../f12/application/review/ReviewService.java | 8 ++--- .../inventoryproduct/InventoryProduct.java | 10 +++--- .../InventoryProductRepository.java | 3 +- .../InventoryProductAcceptanceTest.java | 22 ++++++------- .../InventoryProductServiceTest.java | 10 ++++-- .../application/review/ReviewServiceTest.java | 6 ++-- .../InventoryProductDocumentation.java | 8 +++-- .../InventoryProductRepositoryTest.java | 33 ++++++++++++------- .../product/KeyboardRepositoryTest.java | 6 ++-- .../domain/review/ReviewRepositoryTest.java | 6 ++-- .../InventoryProductControllerTest.java | 8 +++-- .../f12/support/InventoryProductFixtures.java | 9 ++--- 12 files changed, 77 insertions(+), 52 deletions(-) diff --git a/backend/src/main/java/com/woowacourse/f12/application/review/ReviewService.java b/backend/src/main/java/com/woowacourse/f12/application/review/ReviewService.java index 2eca4a23..6c561209 100644 --- a/backend/src/main/java/com/woowacourse/f12/application/review/ReviewService.java +++ b/backend/src/main/java/com/woowacourse/f12/application/review/ReviewService.java @@ -47,7 +47,7 @@ public Long saveReviewAndInventoryProduct(final Long productId, final Long membe final Keyboard keyboard = keyboardRepository.findById(productId) .orElseThrow(KeyboardNotFoundException::new); final Long reviewId = saveReview(reviewRequest, member, keyboard); - saveInventoryProduct(memberId, keyboard); + saveInventoryProduct(member, keyboard); return reviewId; } @@ -64,12 +64,12 @@ private void validateNotWritten(final Member member, final Keyboard keyboard) { } } - private void saveInventoryProduct(final Long memberId, final Keyboard keyboard) { - if (inventoryProductRepository.existsByMemberIdAndKeyboard(memberId, keyboard)) { + private void saveInventoryProduct(final Member member, final Keyboard keyboard) { + if (inventoryProductRepository.existsByMemberAndKeyboard(member, keyboard)) { return; } final InventoryProduct inventoryProduct = InventoryProduct.builder() - .memberId(memberId) + .member(member) .keyboard(keyboard) .build(); inventoryProductRepository.save(inventoryProduct); diff --git a/backend/src/main/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProduct.java b/backend/src/main/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProduct.java index c9a502ad..b07a553f 100644 --- a/backend/src/main/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProduct.java +++ b/backend/src/main/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProduct.java @@ -1,5 +1,6 @@ package com.woowacourse.f12.domain.inventoryproduct; +import com.woowacourse.f12.domain.member.Member; import com.woowacourse.f12.domain.product.Keyboard; import java.util.Objects; import javax.persistence.Column; @@ -26,8 +27,9 @@ public class InventoryProduct { @Column(name = "selected") private boolean selected; - @Column(name = "member_id") - private Long memberId; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "keyboard_id") @@ -37,10 +39,10 @@ protected InventoryProduct() { } @Builder - private InventoryProduct(final Long id, final boolean selected, final Long memberId, final Keyboard keyboard) { + private InventoryProduct(final Long id, final boolean selected, final Member member, final Keyboard keyboard) { this.id = id; this.selected = selected; - this.memberId = memberId; + this.member = member; this.keyboard = keyboard; } diff --git a/backend/src/main/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProductRepository.java b/backend/src/main/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProductRepository.java index a2b391c9..b584cd80 100644 --- a/backend/src/main/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProductRepository.java +++ b/backend/src/main/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProductRepository.java @@ -1,5 +1,6 @@ package com.woowacourse.f12.domain.inventoryproduct; +import com.woowacourse.f12.domain.member.Member; import com.woowacourse.f12.domain.product.Keyboard; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; @@ -8,5 +9,5 @@ public interface InventoryProductRepository extends JpaRepository findByMemberId(Long memberId); - boolean existsByMemberIdAndKeyboard(Long memberId, Keyboard keyboard); + boolean existsByMemberAndKeyboard(Member member, Keyboard keyboard); } diff --git a/backend/src/test/java/com/woowacourse/f12/acceptance/InventoryProductAcceptanceTest.java b/backend/src/test/java/com/woowacourse/f12/acceptance/InventoryProductAcceptanceTest.java index 2ad6825b..34dad708 100644 --- a/backend/src/test/java/com/woowacourse/f12/acceptance/InventoryProductAcceptanceTest.java +++ b/backend/src/test/java/com/woowacourse/f12/acceptance/InventoryProductAcceptanceTest.java @@ -13,6 +13,7 @@ import com.woowacourse.f12.domain.inventoryproduct.InventoryProduct; import com.woowacourse.f12.domain.inventoryproduct.InventoryProductRepository; +import com.woowacourse.f12.domain.member.Member; import com.woowacourse.f12.domain.product.Keyboard; import com.woowacourse.f12.domain.product.KeyboardRepository; import com.woowacourse.f12.dto.request.inventoryproduct.ProfileProductRequest; @@ -58,9 +59,8 @@ class InventoryProductAcceptanceTest extends AcceptanceTest { Keyboard keyboard = 키보드를_저장한다(KEYBOARD_1.생성()); LoginResponse loginResponse = 로그인을_한다("1"); String token = loginResponse.getToken(); - Long memberId = loginResponse.getMember().getId(); - - InventoryProduct inventoryProduct = UNSELECTED_INVENTORY_PRODUCT.생성(memberId, keyboard); + Member member = loginResponse.getMember().toMember(); + InventoryProduct inventoryProduct = UNSELECTED_INVENTORY_PRODUCT.생성(member, keyboard); InventoryProduct savedInventoryProduct = 인벤토리에_장비를_추가한다(inventoryProduct); // when @@ -86,11 +86,10 @@ class InventoryProductAcceptanceTest extends AcceptanceTest { Keyboard keyboard = 키보드를_저장한다(KEYBOARD_1.생성()); LoginResponse response = 로그인을_한다("1"); String token = response.getToken(); - Long memberId = response.getMember() - .getId(); - InventoryProduct selectedInventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(memberId, keyboard); + Member member = response.getMember().toMember(); + InventoryProduct selectedInventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(member, keyboard); InventoryProduct savedSelectedInventoryProduct = 인벤토리에_장비를_추가한다(selectedInventoryProduct); - InventoryProduct unselectedInventoryProduct = UNSELECTED_INVENTORY_PRODUCT.생성(memberId, keyboard); + InventoryProduct unselectedInventoryProduct = UNSELECTED_INVENTORY_PRODUCT.생성(member, keyboard); InventoryProduct savedUnselectedInventoryProduct = 인벤토리에_장비를_추가한다(unselectedInventoryProduct); // when @@ -111,17 +110,16 @@ class InventoryProductAcceptanceTest extends AcceptanceTest { void 다른_회원의_아이디로_등록된_장비를_조회한다() { // given LoginResponse response = 로그인을_한다("1"); - Long memberId = response.getMember() - .getId(); + Member member = response.getMember().toMember(); Keyboard keyboard = 키보드를_저장한다(KEYBOARD_1.생성()); - InventoryProduct selectedInventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(memberId, keyboard); + InventoryProduct selectedInventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(member, keyboard); InventoryProduct savedSelectedInventoryProduct = 인벤토리에_장비를_추가한다(selectedInventoryProduct); - InventoryProduct unselectedInventoryProduct = UNSELECTED_INVENTORY_PRODUCT.생성(memberId, keyboard); + InventoryProduct unselectedInventoryProduct = UNSELECTED_INVENTORY_PRODUCT.생성(member, keyboard); InventoryProduct savedUnselectedInventoryProduct = 인벤토리에_장비를_추가한다(unselectedInventoryProduct); // when ExtractableResponse profileProductResponse = GET_요청을_보낸다( - "/api/v1/members/" + memberId + "/inventoryProducts"); + "/api/v1/members/" + member.getId() + "/inventoryProducts"); // then assertAll( diff --git a/backend/src/test/java/com/woowacourse/f12/application/inventoryproduct/InventoryProductServiceTest.java b/backend/src/test/java/com/woowacourse/f12/application/inventoryproduct/InventoryProductServiceTest.java index c503d4c5..e098dcb6 100644 --- a/backend/src/test/java/com/woowacourse/f12/application/inventoryproduct/InventoryProductServiceTest.java +++ b/backend/src/test/java/com/woowacourse/f12/application/inventoryproduct/InventoryProductServiceTest.java @@ -12,11 +12,13 @@ import com.woowacourse.f12.domain.inventoryproduct.InventoryProduct; import com.woowacourse.f12.domain.inventoryproduct.InventoryProductRepository; +import com.woowacourse.f12.domain.member.Member; import com.woowacourse.f12.domain.member.MemberRepository; import com.woowacourse.f12.dto.request.inventoryproduct.ProfileProductRequest; import com.woowacourse.f12.dto.response.inventoryproduct.InventoryProductResponse; import com.woowacourse.f12.dto.response.inventoryproduct.InventoryProductsResponse; import com.woowacourse.f12.exception.badrequest.InvalidProfileProductException; +import com.woowacourse.f12.support.MemberFixtures; import java.util.List; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -41,8 +43,9 @@ class InventoryProductServiceTest { void 대표_장비를_등록한다() { // given ProfileProductRequest profileProductRequest = new ProfileProductRequest(1L, 2L); - InventoryProduct inventoryProduct1 = UNSELECTED_INVENTORY_PRODUCT.생성(1L, 1L, KEYBOARD_1.생성()); - InventoryProduct inventoryProduct2 = SELECTED_INVENTORY_PRODUCT.생성(2L, 1L, KEYBOARD_2.생성()); + Member member = MemberFixtures.CORINNE.생성(1L); + InventoryProduct inventoryProduct1 = UNSELECTED_INVENTORY_PRODUCT.생성(1L, member, KEYBOARD_1.생성()); + InventoryProduct inventoryProduct2 = SELECTED_INVENTORY_PRODUCT.생성(2L, member, KEYBOARD_2.생성()); given(memberRepository.existsById(1L)) .willReturn(true); given(inventoryProductRepository.findById(1L)) @@ -80,7 +83,8 @@ class InventoryProductServiceTest { void 등록된_장비를_멤버_id로_조회한다() { // given Long memberId = 1L; - InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, memberId, KEYBOARD_1.생성(1L)); + Member member = MemberFixtures.CORINNE.생성(memberId); + InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, member, KEYBOARD_1.생성(1L)); given(memberRepository.existsById(1L)) .willReturn(true); given(inventoryProductRepository.findByMemberId(memberId)) diff --git a/backend/src/test/java/com/woowacourse/f12/application/review/ReviewServiceTest.java b/backend/src/test/java/com/woowacourse/f12/application/review/ReviewServiceTest.java index 9909322b..c54d81ed 100644 --- a/backend/src/test/java/com/woowacourse/f12/application/review/ReviewServiceTest.java +++ b/backend/src/test/java/com/woowacourse/f12/application/review/ReviewServiceTest.java @@ -73,12 +73,12 @@ class ReviewServiceTest { Keyboard keyboard = KEYBOARD_1.생성(productId); Long memberId = 1L; Member member = CORINNE.생성(memberId); - InventoryProduct inventoryProduct = UNSELECTED_INVENTORY_PRODUCT.생성(memberId, keyboard); + InventoryProduct inventoryProduct = UNSELECTED_INVENTORY_PRODUCT.생성(member, keyboard); given(memberRepository.findById(1L)) .willReturn(Optional.of(member)); given(keyboardRepository.findById(productId)) .willReturn(Optional.of(keyboard)); - given(inventoryProductRepository.existsByMemberIdAndKeyboard(memberId, keyboard)) + given(inventoryProductRepository.existsByMemberAndKeyboard(member, keyboard)) .willReturn(false); given(inventoryProductRepository.save(inventoryProduct)) .willReturn(inventoryProduct); @@ -94,7 +94,7 @@ class ReviewServiceTest { () -> verify(keyboardRepository).findById(productId), () -> verify(memberRepository).findById(memberId), () -> verify(reviewRepository).save(any(Review.class)), - () -> verify(inventoryProductRepository).existsByMemberIdAndKeyboard(memberId, keyboard), + () -> verify(inventoryProductRepository).existsByMemberAndKeyboard(member, keyboard), () -> verify(inventoryProductRepository).save(inventoryProduct) ); } diff --git a/backend/src/test/java/com/woowacourse/f12/documentation/inventoryproduct/InventoryProductDocumentation.java b/backend/src/test/java/com/woowacourse/f12/documentation/inventoryproduct/InventoryProductDocumentation.java index 7a7ad2df..174785b5 100644 --- a/backend/src/test/java/com/woowacourse/f12/documentation/inventoryproduct/InventoryProductDocumentation.java +++ b/backend/src/test/java/com/woowacourse/f12/documentation/inventoryproduct/InventoryProductDocumentation.java @@ -15,9 +15,11 @@ import com.woowacourse.f12.application.inventoryproduct.InventoryProductService; import com.woowacourse.f12.documentation.Documentation; import com.woowacourse.f12.domain.inventoryproduct.InventoryProduct; +import com.woowacourse.f12.domain.member.Member; import com.woowacourse.f12.dto.request.inventoryproduct.ProfileProductRequest; import com.woowacourse.f12.dto.response.inventoryproduct.InventoryProductsResponse; import com.woowacourse.f12.presentation.inventoryproduct.InventoryProductController; +import com.woowacourse.f12.support.MemberFixtures; import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -74,7 +76,8 @@ class InventoryProductDocumentation extends Documentation { void 멤버_id_로_인벤토리_상품_조회하는_API_문서화() throws Exception { // given Long memberId = 1L; - InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, memberId, KEYBOARD_1.생성(1L)); + Member member = MemberFixtures.CORINNE.생성(memberId); + InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, member, KEYBOARD_1.생성(1L)); String authorizationHeader = "Bearer Token"; given(jwtProvider.validateToken(authorizationHeader)) .willReturn(true); @@ -99,7 +102,8 @@ class InventoryProductDocumentation extends Documentation { void 다른_멤버_id_로_인벤토리_상품_조회하는_API_문서화() throws Exception { // given Long memberId = 1L; - InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, memberId, KEYBOARD_1.생성(1L)); + Member member = MemberFixtures.CORINNE.생성(memberId); + InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, member, KEYBOARD_1.생성(1L)); given(inventoryProductService.findByMemberId(memberId)) .willReturn(InventoryProductsResponse.from(List.of(inventoryProduct))); diff --git a/backend/src/test/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProductRepositoryTest.java b/backend/src/test/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProductRepositoryTest.java index 7a011727..4b7bc1b6 100644 --- a/backend/src/test/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProductRepositoryTest.java +++ b/backend/src/test/java/com/woowacourse/f12/domain/inventoryproduct/InventoryProductRepositoryTest.java @@ -3,9 +3,13 @@ import static com.woowacourse.f12.support.InventoryProductFixtures.SELECTED_INVENTORY_PRODUCT; import static com.woowacourse.f12.support.KeyboardFixtures.KEYBOARD_1; import static com.woowacourse.f12.support.KeyboardFixtures.KEYBOARD_2; +import static com.woowacourse.f12.support.MemberFixtures.CORINNE; +import static com.woowacourse.f12.support.MemberFixtures.MINCHO; import static org.assertj.core.api.Assertions.assertThat; import com.woowacourse.f12.config.JpaConfig; +import com.woowacourse.f12.domain.member.Member; +import com.woowacourse.f12.domain.member.MemberRepository; import com.woowacourse.f12.domain.product.Keyboard; import com.woowacourse.f12.domain.product.KeyboardRepository; import java.util.List; @@ -24,19 +28,22 @@ class InventoryProductRepositoryTest { @Autowired private KeyboardRepository keyboardRepository; + @Autowired + private MemberRepository memberRepository; + @Test void 멤버_아이디로_인벤토리_상품_목록을_조회한다() { // given - Long myMemberId = 1L; - Long otherMemberId = 2L; - Keyboard keyboard1 = 키보드를_저장한다(KEYBOARD_1.생성(1L)); - Keyboard keyboard2 = 키보드를_저장한다(KEYBOARD_2.생성(2L)); - InventoryProduct inventoryProduct1 = SELECTED_INVENTORY_PRODUCT.생성(myMemberId, keyboard1); - InventoryProduct inventoryProduct2 = SELECTED_INVENTORY_PRODUCT.생성(otherMemberId, keyboard2); + Member myMember = 회원을_저장한다(CORINNE.생성()); + Member otherMember = 회원을_저장한다(MINCHO.생성()); + Keyboard keyboard1 = 키보드를_저장한다(KEYBOARD_1.생성()); + Keyboard keyboard2 = 키보드를_저장한다(KEYBOARD_2.생성()); + InventoryProduct inventoryProduct1 = SELECTED_INVENTORY_PRODUCT.생성(myMember, keyboard1); + InventoryProduct inventoryProduct2 = SELECTED_INVENTORY_PRODUCT.생성(otherMember, keyboard2); inventoryProductRepository.saveAll(List.of(inventoryProduct1, inventoryProduct2)); // when - List inventoryProducts = inventoryProductRepository.findByMemberId(myMemberId); + List inventoryProducts = inventoryProductRepository.findByMemberId(myMember.getId()); // then assertThat(inventoryProducts).containsOnly(inventoryProduct1); @@ -45,13 +52,13 @@ class InventoryProductRepositoryTest { @Test void 멤버_아이디와_상품으로_인벤토리_상품_목록을_조회한다() { // given - Long memberId = 1L; - Keyboard keyboard = 키보드를_저장한다(KEYBOARD_1.생성(1L)); - InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(memberId, keyboard); + Member member = 회원을_저장한다(CORINNE.생성()); + Keyboard keyboard = 키보드를_저장한다(KEYBOARD_1.생성()); + InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(member, keyboard); inventoryProductRepository.save(inventoryProduct); // when - boolean actual = inventoryProductRepository.existsByMemberIdAndKeyboard(memberId, keyboard); + boolean actual = inventoryProductRepository.existsByMemberAndKeyboard(member, keyboard); // then assertThat(actual).isTrue(); @@ -60,4 +67,8 @@ class InventoryProductRepositoryTest { private Keyboard 키보드를_저장한다(Keyboard keyboard) { return keyboardRepository.save(keyboard); } + + private Member 회원을_저장한다(Member member) { + return memberRepository.save(member); + } } diff --git a/backend/src/test/java/com/woowacourse/f12/domain/product/KeyboardRepositoryTest.java b/backend/src/test/java/com/woowacourse/f12/domain/product/KeyboardRepositoryTest.java index 1131d627..374f574a 100644 --- a/backend/src/test/java/com/woowacourse/f12/domain/product/KeyboardRepositoryTest.java +++ b/backend/src/test/java/com/woowacourse/f12/domain/product/KeyboardRepositoryTest.java @@ -47,7 +47,7 @@ class KeyboardRepositoryTest { void 키보드를_단일_조회_한다() { // given Keyboard keyboard = 키보드_저장(KEYBOARD_1.생성()); - Member member = memberRepository.save(CORINNE.생성(1L)); + Member member = memberRepository.save(CORINNE.생성()); 리뷰_저장(REVIEW_RATING_4.작성(keyboard, member)); 리뷰_저장(REVIEW_RATING_5.작성(keyboard, member)); entityManager.flush(); @@ -86,7 +86,7 @@ class KeyboardRepositoryTest { // given Keyboard keyboard1 = 키보드_저장(KEYBOARD_1.생성()); Keyboard keyboard2 = 키보드_저장(KEYBOARD_2.생성()); - Member member = memberRepository.save(CORINNE.생성(1L)); + Member member = memberRepository.save(CORINNE.생성()); 리뷰_저장(REVIEW_RATING_5.작성(keyboard1, member)); 리뷰_저장(REVIEW_RATING_5.작성(keyboard2, member)); @@ -109,7 +109,7 @@ class KeyboardRepositoryTest { // given Keyboard keyboard2 = 키보드_저장(KEYBOARD_1.생성()); Keyboard keyboard1 = 키보드_저장(KEYBOARD_2.생성()); - Member member = memberRepository.save(CORINNE.생성(1L)); + Member member = memberRepository.save(CORINNE.생성()); 리뷰_저장(REVIEW_RATING_2.작성(keyboard1, member)); 리뷰_저장(REVIEW_RATING_1.작성(keyboard1, member)); diff --git a/backend/src/test/java/com/woowacourse/f12/domain/review/ReviewRepositoryTest.java b/backend/src/test/java/com/woowacourse/f12/domain/review/ReviewRepositoryTest.java index d530e198..4c620c08 100644 --- a/backend/src/test/java/com/woowacourse/f12/domain/review/ReviewRepositoryTest.java +++ b/backend/src/test/java/com/woowacourse/f12/domain/review/ReviewRepositoryTest.java @@ -45,7 +45,7 @@ class ReviewRepositoryTest { void 특정_제품의_리뷰_목록을_최신순으로_페이징하여_조회한다() { // given Keyboard keyboard = keyboardRepository.save(KEYBOARD_1.생성()); - Member member = memberRepository.save(CORINNE.생성(1L)); + Member member = memberRepository.save(CORINNE.생성()); Pageable pageable = PageRequest.of(0, 1, Sort.by(desc("createdAt"))); 리뷰_저장(REVIEW_RATING_5.작성(keyboard, member)); Review review = 리뷰_저장(REVIEW_RATING_5.작성(keyboard, member)); @@ -66,7 +66,7 @@ class ReviewRepositoryTest { void 특정_제품의_리뷰_목록을_평점순으로_페이징하여_조회한다() { // given Keyboard keyboard = keyboardRepository.save(KEYBOARD_1.생성()); - Member member = memberRepository.save(CORINNE.생성(1L)); + Member member = memberRepository.save(CORINNE.생성()); Pageable pageable = PageRequest.of(0, 1, Sort.by(desc("rating"))); Review review = 리뷰_저장(REVIEW_RATING_5.작성(keyboard, member)); 리뷰_저장(REVIEW_RATING_4.작성(keyboard, member)); @@ -88,7 +88,7 @@ class ReviewRepositoryTest { // given Keyboard keyboard1 = keyboardRepository.save(KEYBOARD_1.생성()); Keyboard keyboard2 = keyboardRepository.save(KEYBOARD_2.생성()); - Member member = memberRepository.save(CORINNE.생성(1L)); + Member member = memberRepository.save(CORINNE.생성()); Pageable pageable = PageRequest.of(0, 1, Sort.by(desc("createdAt"))); 리뷰_저장(REVIEW_RATING_5.작성(keyboard1, member)); Review review = 리뷰_저장(REVIEW_RATING_5.작성(keyboard2, member)); diff --git a/backend/src/test/java/com/woowacourse/f12/presentation/inventoryproduct/InventoryProductControllerTest.java b/backend/src/test/java/com/woowacourse/f12/presentation/inventoryproduct/InventoryProductControllerTest.java index dd13c011..4232bf14 100644 --- a/backend/src/test/java/com/woowacourse/f12/presentation/inventoryproduct/InventoryProductControllerTest.java +++ b/backend/src/test/java/com/woowacourse/f12/presentation/inventoryproduct/InventoryProductControllerTest.java @@ -18,10 +18,12 @@ import com.woowacourse.f12.application.auth.JwtProvider; import com.woowacourse.f12.application.inventoryproduct.InventoryProductService; import com.woowacourse.f12.domain.inventoryproduct.InventoryProduct; +import com.woowacourse.f12.domain.member.Member; import com.woowacourse.f12.dto.request.inventoryproduct.ProfileProductRequest; import com.woowacourse.f12.dto.response.inventoryproduct.InventoryProductsResponse; import com.woowacourse.f12.exception.badrequest.InvalidProfileProductException; import com.woowacourse.f12.exception.notfound.InventoryItemNotFoundException; +import com.woowacourse.f12.support.MemberFixtures; import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -138,7 +140,8 @@ class InventoryProductControllerTest { void 멤버_id_로_조회한다() throws Exception { // given Long memberId = 1L; - InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, memberId, KEYBOARD_1.생성(1L)); + Member member = MemberFixtures.CORINNE.생성(memberId); + InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, member, KEYBOARD_1.생성(1L)); String authorizationHeader = "Bearer Token"; given(jwtProvider.validateToken(authorizationHeader)) .willReturn(true); @@ -168,7 +171,8 @@ class InventoryProductControllerTest { void 다른_멤버_id_로_조회한다() throws Exception { // given Long memberId = 1L; - InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, memberId, KEYBOARD_1.생성(1L)); + Member member = MemberFixtures.CORINNE.생성(memberId); + InventoryProduct inventoryProduct = SELECTED_INVENTORY_PRODUCT.생성(1L, member, KEYBOARD_1.생성(1L)); given(inventoryProductService.findByMemberId(memberId)) .willReturn(InventoryProductsResponse.from(List.of(inventoryProduct))); diff --git a/backend/src/test/java/com/woowacourse/f12/support/InventoryProductFixtures.java b/backend/src/test/java/com/woowacourse/f12/support/InventoryProductFixtures.java index ddd8a65c..3d831c81 100644 --- a/backend/src/test/java/com/woowacourse/f12/support/InventoryProductFixtures.java +++ b/backend/src/test/java/com/woowacourse/f12/support/InventoryProductFixtures.java @@ -1,6 +1,7 @@ package com.woowacourse.f12.support; import com.woowacourse.f12.domain.inventoryproduct.InventoryProduct; +import com.woowacourse.f12.domain.member.Member; import com.woowacourse.f12.domain.product.Keyboard; public enum InventoryProductFixtures { @@ -15,15 +16,15 @@ public enum InventoryProductFixtures { this.selected = selected; } - public InventoryProduct 생성(final Long memberId, final Keyboard keyboard) { - return 생성(null, memberId, keyboard); + public InventoryProduct 생성(final Member member, final Keyboard keyboard) { + return 생성(null, member, keyboard); } - public InventoryProduct 생성(final Long id, final Long memberId, final Keyboard keyboard) { + public InventoryProduct 생성(final Long id, final Member member, final Keyboard keyboard) { return InventoryProduct.builder() .id(id) .selected(this.selected) - .memberId(memberId) + .member(member) .keyboard(keyboard) .build(); } From 6a1b793bbffc5ac745295163f320126ef88b1761 Mon Sep 17 00:00:00 2001 From: "yh20studio(tiki)" Date: Tue, 26 Jul 2022 15:37:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20Member=EC=97=90=20InventoryProd?= =?UTF-8?q?uct=20=EC=A7=81=EC=A0=91=20=EC=B0=B8=EC=A1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: hamcheeseburger --- .../java/com/woowacourse/f12/domain/member/Member.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/src/main/java/com/woowacourse/f12/domain/member/Member.java b/backend/src/main/java/com/woowacourse/f12/domain/member/Member.java index d913da5c..562aec93 100644 --- a/backend/src/main/java/com/woowacourse/f12/domain/member/Member.java +++ b/backend/src/main/java/com/woowacourse/f12/domain/member/Member.java @@ -1,5 +1,8 @@ package com.woowacourse.f12.domain.member; +import com.woowacourse.f12.domain.inventoryproduct.InventoryProduct; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; @@ -9,6 +12,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.OneToMany; import javax.persistence.Table; import lombok.Builder; import lombok.Getter; @@ -41,6 +45,9 @@ public class Member { @Enumerated(EnumType.STRING) private JobType jobType; + @OneToMany(mappedBy = "member") + private List inventoryProducts = new ArrayList<>(); + protected Member() { }