Skip to content

Commit

Permalink
merge: Member 반환값 변경
Browse files Browse the repository at this point in the history
Refactor/#819 member 반환값 변경
  • Loading branch information
hong-sile authored Nov 5, 2023
2 parents 2bf14c4 + ed0e7a4 commit a64396c
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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들"));
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,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.util.List;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -77,7 +77,7 @@ public ResponseEntity<Void> updateDescription(
}

@GetMapping("/members/{member-id}")
public ResponseEntity<MemberProfileResponse> findProfile(
public ResponseEntity<MemberDetailResponse> findProfile(
@PathVariable("member-id") final Long memberId) {
return ResponseEntity.ok(memberQueryService.findProfile(memberId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +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;
Expand All @@ -18,6 +21,7 @@
public class MemberQueryService {

private final MemberRepository memberRepository;
private final MemberActivityRepository memberActivityRepository;

public Member findById(final Long memberId) {
return memberRepository.findById(memberId)
Expand All @@ -34,10 +38,10 @@ 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 MemberDetailResponse findProfile(final Long memberId) {
final Member member = memberRepository.getByIdOrElseThrow(memberId);
final List<MemberActivity> memberActivities = memberActivityRepository.findAllByMember(member);

return MemberProfileResponse.from(member);
return MemberDetailResponse.of(member,memberActivities);
}
}
Original file line number Diff line number Diff line change
@@ -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<MemberActivityResponse> activities;

public static MemberDetailResponse of(
final Member member,
final List<MemberActivity> activities
) {
final List<MemberActivityResponse> 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
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

public interface MemberActivityRepository extends JpaRepository<MemberActivity, Long> {

@Query("select mc from MemberActivity mc where mc.member = :member")
List<MemberActivity> 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<MemberActivity> findAllByMember(
@Param("member") final Member member
);

@Query("select mc from MemberActivity mc "
+ "where mc.member = :member "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a64396c

Please sign in to comment.