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

[feat #82] 유저 정보 API #83

Merged
merged 6 commits into from
Aug 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.dnd.gongmuin.member.dto.response.AnsweredQuestionPostsResponse;
import com.dnd.gongmuin.member.dto.response.BookmarksResponse;
import com.dnd.gongmuin.member.dto.response.CreditHistoryResponse;
import com.dnd.gongmuin.member.dto.response.MemberInformationResponse;
import com.dnd.gongmuin.member.dto.response.MemberProfileResponse;
import com.dnd.gongmuin.member.dto.response.QuestionPostsResponse;
import com.dnd.gongmuin.member.service.MemberService;
Expand Down Expand Up @@ -102,4 +103,12 @@ public ResponseEntity<PageResponse<CreditHistoryResponse>> getCreditHistoryByMem
return ResponseEntity.ok(response);
}

@Operation(summary = "회원 정보 전체 조회 API", description = "회원 정보를 전체 조회한다.")
@ApiResponse(useReturnTypeSchema = true)
@GetMapping("/information")
public ResponseEntity<MemberInformationResponse> getMemberInformation(@AuthenticationPrincipal Member member) {
MemberInformationResponse response = memberService.getMemberInformation(member);

return ResponseEntity.ok(response);
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/dnd/gongmuin/member/dto/MemberMapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.gongmuin.member.dto;

import com.dnd.gongmuin.member.domain.Member;
import com.dnd.gongmuin.member.dto.response.MemberInformationResponse;
import com.dnd.gongmuin.member.dto.response.MemberProfileResponse;

import lombok.AccessLevel;
Expand All @@ -19,4 +20,18 @@ public static MemberProfileResponse toMemberProfileResponse(Member member) {
member.getProfileImageNo()
);
}

public static MemberInformationResponse toMemberInformationResponse(Member member) {
return new MemberInformationResponse(
member.getId(),
member.getNickname(),
member.getSocialName(),
member.getOfficialEmail(),
member.getSocialEmail(),
member.getJobGroup().getLabel(),
member.getJobCategory().getLabel(),
member.getCredit(),
member.getProfileImageNo()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dnd.gongmuin.member.dto.response;

public record MemberInformationResponse(
Long memberId,
String nickname,
String socialName,
String officialEmail,
String socialEmail,
String jobGroup,
String jobCategory,
int credit,
int profileImageNo
) {
}
10 changes: 10 additions & 0 deletions src/main/java/com/dnd/gongmuin/member/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.dnd.gongmuin.member.dto.response.AnsweredQuestionPostsResponse;
import com.dnd.gongmuin.member.dto.response.BookmarksResponse;
import com.dnd.gongmuin.member.dto.response.CreditHistoryResponse;
import com.dnd.gongmuin.member.dto.response.MemberInformationResponse;
import com.dnd.gongmuin.member.dto.response.MemberProfileResponse;
import com.dnd.gongmuin.member.dto.response.QuestionPostsResponse;
import com.dnd.gongmuin.member.exception.MemberErrorCode;
Expand Down Expand Up @@ -139,4 +140,13 @@ public PageResponse<CreditHistoryResponse> getCreditHistoryByMember(String type,
}

}

public MemberInformationResponse getMemberInformation(Member member) {
try {
Member findMember = memberRepository.findByOfficialEmail(member.getOfficialEmail());
return MemberMapper.toMemberInformationResponse(findMember);
} catch (Exception e) {
throw new NotFoundException(MemberErrorCode.NOT_FOUND_MEMBER);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,23 @@ void getCreditHistoryByMemberInDeposit() throws Exception {
.andExpect(jsonPath("$.content[0].detail").value(ch4.getDetail()))
.andExpect(jsonPath("$.content[0].amount").value(ch4.getAmount()));
}

@DisplayName("로그인 된 사용자 프로필 정보를 조회한다.")
@Test
void getMemberInformation() throws Exception {
// when // then
mockMvc.perform(get("/api/members/information")
.cookie(accessToken)
)
.andExpect(status().isOk())
.andExpect(jsonPath("memberId").value(loginMember.getId()))
.andExpect(jsonPath("nickname").value(loginMember.getNickname()))
.andExpect(jsonPath("socialName").value(loginMember.getSocialName()))
.andExpect(jsonPath("officialEmail").value(loginMember.getOfficialEmail()))
.andExpect(jsonPath("socialEmail").value(loginMember.getSocialEmail()))
.andExpect(jsonPath("jobGroup").value(loginMember.getJobGroup().getLabel()))
.andExpect(jsonPath("jobCategory").value(loginMember.getJobCategory().getLabel()))
.andExpect(jsonPath("profileImageNo").value(loginMember.getProfileImageNo()))
.andExpect(jsonPath("credit").value(10000));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.dnd.gongmuin.common.fixture.MemberFixture;
import com.dnd.gongmuin.member.domain.Member;
import com.dnd.gongmuin.member.dto.request.UpdateMemberProfileRequest;
import com.dnd.gongmuin.member.dto.response.MemberInformationResponse;
import com.dnd.gongmuin.member.dto.response.MemberProfileResponse;
import com.dnd.gongmuin.member.repository.MemberRepository;

Expand Down Expand Up @@ -136,6 +137,39 @@ void updateMemberProfileThrowException() {

// when // then
assertThrows(ValidationException.class, () -> memberService.updateMemberProfile(request, member));
}

@DisplayName("회원 정보를 전체 조회한다.")
@Test
void getMemberInformation() {
// given
Member member = MemberFixture.member();
given(memberRepository.findByOfficialEmail(anyString())).willReturn(member);

// when
MemberInformationResponse memberInformation = memberService.getMemberInformation(member);

// then
assertAll(
() -> assertThat(memberInformation.memberId()).isEqualTo(member.getId()),
() -> assertThat(memberInformation.nickname()).isEqualTo(member.getNickname()),
() -> assertThat(memberInformation.socialName()).isEqualTo(member.getSocialName()),
() -> assertThat(memberInformation.officialEmail()).isEqualTo(member.getOfficialEmail()),
() -> assertThat(memberInformation.socialEmail()).isEqualTo(member.getSocialEmail()),
() -> assertThat(memberInformation.jobGroup()).isEqualTo(member.getJobGroup().getLabel()),
() -> assertThat(memberInformation.jobCategory()).isEqualTo(member.getJobCategory().getLabel()),
() -> assertThat(memberInformation.credit()).isEqualTo(member.getCredit()),
() -> assertThat(memberInformation.profileImageNo()).isEqualTo(member.getProfileImageNo())
);
}

@DisplayName("회원 정보를 전체 조회 시 회원을 찾을 수 없으면 예외가 발생한다.")
@Test
void getMemberInformationThrowException() {
// given
Member member = MemberFixture.member();

// when // then
assertThrows(NotFoundException.class, () -> memberService.getMemberInformation(member));
}
}
Loading