Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] Refactor/#547 로그인 회원 프로필 조회 API 명세 변경 #561

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/src/docs/asciidoc/member.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

operation::member-controller-test/find-all-member[snippets='http-request,http-response']

=== 회원 단일 조회
=== 회원의 나의 프로필 조회

operation::member-controller-test/find-member-by-id[snippets='http-request,http-response']
operation::member-controller-test/find-my-profile[snippets='http-request,http-response']

=== 회원의 나의 지도 목록 조회

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse;
import com.mapbefine.mapbefine.member.dto.response.MemberResponse;
import com.mapbefine.mapbefine.member.exception.MemberErrorCode;
import com.mapbefine.mapbefine.member.exception.MemberException.MemberForbiddenException;
import com.mapbefine.mapbefine.member.exception.MemberException.MemberNotFoundException;
import com.mapbefine.mapbefine.pin.dto.response.PinResponse;
import com.mapbefine.mapbefine.topic.domain.Topic;
Expand Down Expand Up @@ -41,12 +40,10 @@ public MemberQueryService(
this.topicRepository = topicRepository;
}

public MemberDetailResponse findById(AuthMember authMember, Long id) {
if (authMember.isSameMember(id)) {
Member member = findMemberById(id);
return MemberDetailResponse.from(member);
}
throw new MemberForbiddenException(MemberErrorCode.FORBIDDEN_ACCESS, id);
public MemberDetailResponse findMemberDetail(AuthMember authMember) {
Member member = findMemberById(authMember.getMemberId());

return MemberDetailResponse.from(member);
Comment on lines +43 to +46
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

private Member findMemberById(Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -39,9 +38,9 @@ public ResponseEntity<List<MemberResponse>> findAllMember() {
}

@LoginRequired
@GetMapping("/{memberId}")
public ResponseEntity<MemberDetailResponse> findMemberById(AuthMember authMember, @PathVariable Long memberId) {
MemberDetailResponse response = memberQueryService.findById(authMember, memberId);
@GetMapping("/my/profiles")
public ResponseEntity<MemberDetailResponse> findMyProfile(AuthMember authMember) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 Controller 의 메서드 명이 findMyProfile 이라서 Service Method 명은 다르게 하신건가??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 컨트롤러 메서드는 API 의미에 가깝게 하는 걸 선호해서 그렇게 하고, 서비스메서드는 다르게 했는데
오히려 좀 헷갈렸을 것 같네요!
서비스 메서드명은 개발 로직에 더 가깝게 findMemberDetail로 하겠습니당

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니당!

MemberDetailResponse response = memberQueryService.findMemberDetail(authMember);

return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ void findAllMember() {
}

@Test
@DisplayName("회원을 단일 조회한다.")
void findMemberById() {
@DisplayName("로그인 회원의 상세 정보를 단일 조회한다.")
void findMyProfile() {
// given, when
ExtractableResponse<Response> response = given().log().all()
.header(AUTHORIZATION, user1AuthHeader)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.when().get("/members/" + user1.getId())
.when().get("/members/my/profiles")
.then().log().all()
.extract();

Expand Down Expand Up @@ -192,5 +192,5 @@ void updateMemberInfo_Success() {
// then
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mapbefine.mapbefine.atlas.domain.AtlasRepository;
import com.mapbefine.mapbefine.auth.domain.AuthMember;
import com.mapbefine.mapbefine.auth.domain.member.Admin;
import com.mapbefine.mapbefine.auth.domain.member.User;
import com.mapbefine.mapbefine.bookmark.domain.Bookmark;
import com.mapbefine.mapbefine.bookmark.domain.BookmarkRepository;
import com.mapbefine.mapbefine.common.annotation.ServiceTest;
Expand All @@ -20,7 +21,7 @@
import com.mapbefine.mapbefine.member.domain.Role;
import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse;
import com.mapbefine.mapbefine.member.dto.response.MemberResponse;
import com.mapbefine.mapbefine.member.exception.MemberException.MemberForbiddenException;
import com.mapbefine.mapbefine.member.exception.MemberException.MemberNotFoundException;
import com.mapbefine.mapbefine.pin.PinFixture;
import com.mapbefine.mapbefine.pin.domain.Pin;
import com.mapbefine.mapbefine.pin.domain.PinRepository;
Expand All @@ -29,6 +30,7 @@
import com.mapbefine.mapbefine.topic.domain.Topic;
import com.mapbefine.mapbefine.topic.domain.TopicRepository;
import com.mapbefine.mapbefine.topic.dto.response.TopicResponse;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -101,31 +103,26 @@ void findAllMember() {
}

@Test
@DisplayName("회원을 단일 조회한다.")
void findMemberById() {
@DisplayName("로그인 회원의 상세 정보를 조회한다.")
void findMyProfile() {
// given
// when
MemberDetailResponse response = memberQueryService.findById(authMember, member.getId());
MemberDetailResponse response = memberQueryService.findMemberDetail(authMember);

// then
assertThat(response).usingRecursiveComparison()
.isEqualTo(MemberDetailResponse.from(member));
}

@Test
@DisplayName("조회하려는 회원이 없는 경우 본인이 아니므로 예외를 반환한다.")
void findMemberById_whenNoneExists_thenFail() {
// given when then
assertThatThrownBy(() -> memberQueryService.findById(authMember, Long.MAX_VALUE))
.isInstanceOf(MemberForbiddenException.class);
}
@DisplayName("로그인한 식별값(ID)에 해당하는 회원 정보를 찾을 수 없는 경우 예외를 반환한다.")
void findMyProfile_whenNoneExists_thenFail() {
// given
AuthMember otherAuthMember = new User(Long.MAX_VALUE, Collections.emptyList(), Collections.emptyList());

@Test
@DisplayName("조회하려는 회원이 본인이 아닌 경우 예외를 반환한다.")
void findMemberById_whenNotSameMember_thenFail() {
// given when then
assertThatThrownBy(() -> memberQueryService.findById(authMember, Long.MAX_VALUE))
.isInstanceOf(MemberForbiddenException.class);
// when then
assertThatThrownBy(() -> memberQueryService.findMemberDetail(otherAuthMember))
.isInstanceOf(MemberNotFoundException.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ void findAllMember() throws Exception {
}

@Test
@DisplayName("회원 단일 조회")
void findMemberById() throws Exception {
@DisplayName("회원 상세 정보 조회")
void findMyProfile() throws Exception {
MemberDetailResponse memberDetailResponse = new MemberDetailResponse(
1L,
"member",
Expand All @@ -58,10 +58,10 @@ void findMemberById() throws Exception {
LocalDateTime.now()
);

given(memberQueryService.findById(any(), any())).willReturn(memberDetailResponse);
given(memberQueryService.findMemberDetail(any())).willReturn(memberDetailResponse);

mockMvc.perform(
MockMvcRequestBuilders.get("/members/1")
MockMvcRequestBuilders.get("/members/my/profiles")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
}
Expand Down