From b448b1950f59f984072563d791a375d0094c9039 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Sun, 5 Nov 2023 16:05:57 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20MemberActivityRepository=20N+1?= =?UTF-8?q?=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #819 --- .../emmsale/member/domain/MemberActivityRepository.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/domain/MemberActivityRepository.java b/backend/emm-sale/src/main/java/com/emmsale/member/domain/MemberActivityRepository.java index c0c855fd0..50e141218 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/domain/MemberActivityRepository.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/domain/MemberActivityRepository.java @@ -7,8 +7,13 @@ public interface MemberActivityRepository extends JpaRepository { - @Query("select mc from MemberActivity mc where mc.member = :member") - List findAllByMember(@Param("member") final Member member); + @Query("select mc from MemberActivity mc " + + "join fetch Activity a " + + "on a = mc.activity " + + "where mc.member = :member ") + List findAllByMember( + @Param("member") final Member member + ); @Query("select mc from MemberActivity mc " + "where mc.member = :member " From 75cd54270b10da4b8e9b84a30f6f6826d7ea235f Mon Sep 17 00:00:00 2001 From: hong-sile Date: Sun, 5 Nov 2023 16:06:30 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20MemberDetailResponse=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #819 --- .../application/MemberQueryService.java | 7 ++-- .../application/dto/MemberDetailResponse.java | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberQueryService.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberQueryService.java index 37fae32fa..5fc1a93a7 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberQueryService.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberQueryService.java @@ -6,6 +6,7 @@ import com.emmsale.login.application.dto.MemberQueryResponse; import com.emmsale.member.application.dto.MemberProfileResponse; import com.emmsale.member.domain.Member; +import com.emmsale.member.domain.MemberActivityRepository; import com.emmsale.member.domain.MemberRepository; import com.emmsale.member.exception.MemberException; import lombok.RequiredArgsConstructor; @@ -18,6 +19,7 @@ public class MemberQueryService { private final MemberRepository memberRepository; + private final MemberActivityRepository memberActivityRepository; public Member findById(final Long memberId) { return memberRepository.findById(memberId) @@ -34,9 +36,8 @@ public MemberQueryResponse findOrCreateMember( return new MemberQueryResponse(member.getId(), member.isOnboarded()); } - public MemberProfileResponse findProfile(Long memberId) { - final Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberException(NOT_FOUND_MEMBER)); + public MemberProfileResponse findProfile(final Long memberId) { + final Member member = memberRepository.getByIdOrElseThrow(memberId); return MemberProfileResponse.from(member); } diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java new file mode 100644 index 000000000..f5c9e82ae --- /dev/null +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java @@ -0,0 +1,41 @@ +package com.emmsale.member.application.dto; + +import static java.util.stream.Collectors.toUnmodifiableList; + +import com.emmsale.member.domain.Member; +import com.emmsale.member.domain.MemberActivity; +import java.util.List; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public class MemberDetailResponse { + + private static final String GITHUB_URL_PREFIX = "https://github.com/"; + + private final Long id; + private final String name; + private final String description; + private final String imageUrl; + private final String githubUrl; + private final List activities; + + public static MemberDetailResponse from( + final Member member, + final List activities + ) { + final List memberActivityResponses = activities.stream() + .map(MemberActivityResponse::from) + .collect(toUnmodifiableList()); + + return new MemberDetailResponse( + member.getId(), + member.getName(), + member.getDescription(), + member.getImageUrl(), + GITHUB_URL_PREFIX + member.getGithubUsername(), + memberActivityResponses + ); + } +} From 59198e68a6fd3a257113978292cacd3a5851a9d3 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Sun, 5 Nov 2023 16:20:01 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20MemberDetailResponse=EB=A5=BC?= =?UTF-8?q?=20=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #819 --- .../java/com/emmsale/MemberApiTest.java | 16 ++++++++++++---- .../com/emmsale/member/api/MemberApi.java | 3 ++- .../application/MemberQueryService.java | 9 ++++++--- .../dto/MemberActivityResponse.java | 9 +++++++++ .../application/dto/MemberDetailResponse.java | 4 +++- .../application/MemberQueryServiceTest.java | 19 +++++++++++++------ 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/backend/emm-sale/src/documentTest/java/com/emmsale/MemberApiTest.java b/backend/emm-sale/src/documentTest/java/com/emmsale/MemberApiTest.java index f2cbe32bd..74ee8554c 100644 --- a/backend/emm-sale/src/documentTest/java/com/emmsale/MemberApiTest.java +++ b/backend/emm-sale/src/documentTest/java/com/emmsale/MemberApiTest.java @@ -21,8 +21,8 @@ import com.emmsale.member.application.dto.MemberActivityAddRequest; import com.emmsale.member.application.dto.MemberActivityInitialRequest; import com.emmsale.member.application.dto.MemberActivityResponse; +import com.emmsale.member.application.dto.MemberDetailResponse; import com.emmsale.member.application.dto.MemberImageResponse; -import com.emmsale.member.application.dto.MemberProfileResponse; import com.emmsale.member.domain.Member; import java.io.IOException; import java.util.List; @@ -52,7 +52,12 @@ class MemberApiTest extends MockMvcTestHelper { fieldWithPath("name").type(JsonFieldType.STRING).description("사용자 이름"), fieldWithPath("description").type(JsonFieldType.STRING).description("사용자 한 줄 자기소개"), fieldWithPath("imageUrl").type(JsonFieldType.STRING).description("사용자 프로필 이미지 url"), - fieldWithPath("githubUrl").type(JsonFieldType.STRING).description("깃허브 URL") + fieldWithPath("githubUrl").type(JsonFieldType.STRING).description("깃허브 URL"), + fieldWithPath("activities[].id").type(JsonFieldType.NUMBER).description("MemberActivity Id"), + fieldWithPath("activities[].name").type(JsonFieldType.STRING) + .description("MemberActivity 이름"), + fieldWithPath("activities[].activityType").type(JsonFieldType.STRING) + .description("MemberActivity Type") ); private static final RequestFieldsSnippet MEMBER_ACTIVITY_REQUEST_FIELDS = requestFields( fieldWithPath("activityIds").description("활동 id들")); @@ -185,12 +190,15 @@ void test_updateDescription() throws Exception { @DisplayName("특정 사용자의 프로필 정보를 조회할 수 있다.") void test_findProfile() throws Exception { //given - final MemberProfileResponse memberProfileResponse = new MemberProfileResponse( + final MemberDetailResponse memberProfileResponse = new MemberDetailResponse( 1L, "김길동", "안녕하세요, 김길동입니다.", "https://image", - "https://github.com/amaran-th" + "https://github.com/amaran-th", + List.of( + new MemberActivityResponse(1L, "YAPP", "동아리") + ) ); when(memberQueryService.findProfile(any())) .thenReturn(memberProfileResponse); diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java b/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java index f3d72ec15..169c83404 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java @@ -8,6 +8,7 @@ import com.emmsale.member.application.dto.MemberActivityAddRequest; import com.emmsale.member.application.dto.MemberActivityInitialRequest; import com.emmsale.member.application.dto.MemberActivityResponse; +import com.emmsale.member.application.dto.MemberDetailResponse; import com.emmsale.member.application.dto.MemberImageResponse; import com.emmsale.member.application.dto.MemberProfileResponse; import com.emmsale.member.domain.Member; @@ -77,7 +78,7 @@ public ResponseEntity updateDescription( } @GetMapping("/members/{member-id}") - public ResponseEntity findProfile( + public ResponseEntity findProfile( @PathVariable("member-id") final Long memberId) { return ResponseEntity.ok(memberQueryService.findProfile(memberId)); } diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberQueryService.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberQueryService.java index 5fc1a93a7..03f09a408 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberQueryService.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberQueryService.java @@ -4,11 +4,13 @@ import com.emmsale.login.application.dto.GithubProfileResponse; import com.emmsale.login.application.dto.MemberQueryResponse; -import com.emmsale.member.application.dto.MemberProfileResponse; +import com.emmsale.member.application.dto.MemberDetailResponse; import com.emmsale.member.domain.Member; +import com.emmsale.member.domain.MemberActivity; import com.emmsale.member.domain.MemberActivityRepository; import com.emmsale.member.domain.MemberRepository; import com.emmsale.member.exception.MemberException; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,9 +38,10 @@ public MemberQueryResponse findOrCreateMember( return new MemberQueryResponse(member.getId(), member.isOnboarded()); } - public MemberProfileResponse findProfile(final Long memberId) { + public MemberDetailResponse findProfile(final Long memberId) { final Member member = memberRepository.getByIdOrElseThrow(memberId); + final List memberActivities = memberActivityRepository.findAllByMember(member); - return MemberProfileResponse.from(member); + return MemberDetailResponse.of(member,memberActivities); } } diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberActivityResponse.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberActivityResponse.java index a3e731412..531b1c54f 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberActivityResponse.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberActivityResponse.java @@ -20,4 +20,13 @@ public static MemberActivityResponse from(final MemberActivity memberActivity) { memberActivity.getActivity().getActivityType().getValue() ); } + + @Override + public String toString() { + return "MemberActivityResponse{" + + "id=" + id + + ", name='" + name + '\'' + + ", activityType='" + activityType + '\'' + + '}'; + } } diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java index f5c9e82ae..3c45006fe 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java @@ -7,9 +7,11 @@ import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; @RequiredArgsConstructor @Getter +@ToString public class MemberDetailResponse { private static final String GITHUB_URL_PREFIX = "https://github.com/"; @@ -21,7 +23,7 @@ public class MemberDetailResponse { private final String githubUrl; private final List activities; - public static MemberDetailResponse from( + public static MemberDetailResponse of( final Member member, final List activities ) { diff --git a/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberQueryServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberQueryServiceTest.java index b6a6e05db..de995f6c0 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberQueryServiceTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberQueryServiceTest.java @@ -6,9 +6,11 @@ import com.emmsale.helper.ServiceIntegrationTestHelper; import com.emmsale.login.application.dto.GithubProfileResponse; import com.emmsale.login.application.dto.MemberQueryResponse; -import com.emmsale.member.application.dto.MemberProfileResponse; +import com.emmsale.member.application.dto.MemberActivityResponse; +import com.emmsale.member.application.dto.MemberDetailResponse; import com.emmsale.member.exception.MemberException; import com.emmsale.member.exception.MemberExceptionType; +import java.util.List; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -67,22 +69,27 @@ class FindProfile { void findProfile_success() { //given final Long memberId = 1L; - final MemberProfileResponse expectResponse = new MemberProfileResponse( + final MemberDetailResponse expect = new MemberDetailResponse( memberId, null, "", "https://imageurl.com", - "https://github.com/amaran-th" + "https://github.com/amaran-th", + List.of( + new MemberActivityResponse(1L, "YAPP", "동아리"), + new MemberActivityResponse(2L, "DND", "동아리"), + new MemberActivityResponse(3L, "nexters", "동아리") + ) ); //when - final MemberProfileResponse actualResponse = memberQueryService.findProfile(memberId); + final MemberDetailResponse actual = memberQueryService.findProfile(memberId); //then - assertThat(actualResponse) + assertThat(actual) .usingRecursiveComparison() .ignoringFields("description") - .isEqualTo(expectResponse); + .isEqualTo(expect); } @Test From ed0e7a41266bbabec92a2b59989390fae04c5fc8 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Sun, 5 Nov 2023 16:21:03 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=ED=95=84=EC=9A=94=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #819 --- .../com/emmsale/member/api/MemberApi.java | 1 - .../dto/MemberActivityResponse.java | 9 ------ .../application/dto/MemberDetailResponse.java | 2 -- .../dto/MemberProfileResponse.java | 28 ------------------- 4 files changed, 40 deletions(-) delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberProfileResponse.java diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java b/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java index 169c83404..6bf9b1958 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java @@ -10,7 +10,6 @@ import com.emmsale.member.application.dto.MemberActivityResponse; import com.emmsale.member.application.dto.MemberDetailResponse; import com.emmsale.member.application.dto.MemberImageResponse; -import com.emmsale.member.application.dto.MemberProfileResponse; import com.emmsale.member.domain.Member; import java.util.List; import lombok.RequiredArgsConstructor; diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberActivityResponse.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberActivityResponse.java index 531b1c54f..a3e731412 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberActivityResponse.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberActivityResponse.java @@ -20,13 +20,4 @@ public static MemberActivityResponse from(final MemberActivity memberActivity) { memberActivity.getActivity().getActivityType().getValue() ); } - - @Override - public String toString() { - return "MemberActivityResponse{" + - "id=" + id + - ", name='" + name + '\'' + - ", activityType='" + activityType + '\'' + - '}'; - } } diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java index 3c45006fe..ba3d54e13 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberDetailResponse.java @@ -7,11 +7,9 @@ import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; -import lombok.ToString; @RequiredArgsConstructor @Getter -@ToString public class MemberDetailResponse { private static final String GITHUB_URL_PREFIX = "https://github.com/"; diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberProfileResponse.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberProfileResponse.java deleted file mode 100644 index e802bffb9..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/dto/MemberProfileResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.emmsale.member.application.dto; - -import com.emmsale.member.domain.Member; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class MemberProfileResponse { - - private static final String GITHUB_URL_PREFIX = "https://github.com/"; - - private final Long id; - private final String name; - private final String description; - private final String imageUrl; - private final String githubUrl; - - public static MemberProfileResponse from(final Member member) { - return new MemberProfileResponse( - member.getId(), - member.getName(), - member.getDescription(), - member.getImageUrl(), - GITHUB_URL_PREFIX + member.getGithubUsername() - ); - } -}