diff --git a/src/main/java/com/dnd/gongmuin/member/controller/MemberController.java b/src/main/java/com/dnd/gongmuin/member/controller/MemberController.java index f916ba4a..d5ae0cfd 100644 --- a/src/main/java/com/dnd/gongmuin/member/controller/MemberController.java +++ b/src/main/java/com/dnd/gongmuin/member/controller/MemberController.java @@ -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; @@ -102,4 +103,12 @@ public ResponseEntity> getCreditHistoryByMem return ResponseEntity.ok(response); } + @Operation(summary = "회원 정보 전체 조회 API", description = "회원 정보를 전체 조회한다.") + @ApiResponse(useReturnTypeSchema = true) + @GetMapping("/information") + public ResponseEntity getMemberInformation(@AuthenticationPrincipal Member member) { + MemberInformationResponse response = memberService.getMemberInformation(member); + + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/dnd/gongmuin/member/dto/MemberMapper.java b/src/main/java/com/dnd/gongmuin/member/dto/MemberMapper.java index f8d4a75a..1d5079db 100644 --- a/src/main/java/com/dnd/gongmuin/member/dto/MemberMapper.java +++ b/src/main/java/com/dnd/gongmuin/member/dto/MemberMapper.java @@ -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; @@ -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() + ); + } } diff --git a/src/main/java/com/dnd/gongmuin/member/dto/response/MemberInformationResponse.java b/src/main/java/com/dnd/gongmuin/member/dto/response/MemberInformationResponse.java new file mode 100644 index 00000000..de100dec --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/member/dto/response/MemberInformationResponse.java @@ -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 +) { +} diff --git a/src/main/java/com/dnd/gongmuin/member/service/MemberService.java b/src/main/java/com/dnd/gongmuin/member/service/MemberService.java index 9424ca47..0a10d40c 100644 --- a/src/main/java/com/dnd/gongmuin/member/service/MemberService.java +++ b/src/main/java/com/dnd/gongmuin/member/service/MemberService.java @@ -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; @@ -139,4 +140,13 @@ public PageResponse 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); + } + } } \ No newline at end of file diff --git a/src/test/java/com/dnd/gongmuin/member/controller/MemberControllerTest.java b/src/test/java/com/dnd/gongmuin/member/controller/MemberControllerTest.java index 3b4b126e..3c3aa5cb 100644 --- a/src/test/java/com/dnd/gongmuin/member/controller/MemberControllerTest.java +++ b/src/test/java/com/dnd/gongmuin/member/controller/MemberControllerTest.java @@ -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)); + } } diff --git a/src/test/java/com/dnd/gongmuin/member/service/MemberServiceTest.java b/src/test/java/com/dnd/gongmuin/member/service/MemberServiceTest.java index e1c36c25..a8a06c08 100644 --- a/src/test/java/com/dnd/gongmuin/member/service/MemberServiceTest.java +++ b/src/test/java/com/dnd/gongmuin/member/service/MemberServiceTest.java @@ -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; @@ -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)); } } \ No newline at end of file