Skip to content

Commit

Permalink
Merge pull request #95 from IT-Cotato/feature/mypage#3-member-info
Browse files Browse the repository at this point in the history
Feature: 마이페이지 개인 정보 반환 API 구현 (#86)
  • Loading branch information
gikhoon authored Feb 20, 2024
2 parents be73247 + fddd1ec commit d883147
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/cotato/csquiz/controller/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import cotato.csquiz.config.jwt.JwtUtil;
import cotato.csquiz.domain.dto.auth.MemberInfoResponse;
import cotato.csquiz.domain.dto.member.CheckPasswordRequest;
import cotato.csquiz.domain.dto.member.MemberMyPageInfoResponse;
import cotato.csquiz.domain.dto.member.UpdatePasswordRequest;
import cotato.csquiz.service.MemberService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
Expand Down Expand Up @@ -49,4 +51,10 @@ public ResponseEntity<?> updatePassword(@RequestHeader("Authorization") String a
memberService.updatePassword(accessToken, request.getPassword());
return ResponseEntity.ok().build();
}

@GetMapping("/{memberId}/mypage")
public ResponseEntity<?> findMyPageInfo(@PathVariable("memberId") Long memberId) {
MemberMyPageInfoResponse myPageInfo = memberService.findMyPageInfo(memberId);
return ResponseEntity.ok().body(myPageInfo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cotato.csquiz.domain.dto.member;

import cotato.csquiz.domain.entity.Member;
import cotato.csquiz.domain.enums.MemberPosition;

public record MemberMyPageInfoResponse(
Long memberId,
String email,
String name,
int generationNumber,
MemberPosition memberPosition,
String phoneNumber
) {
public static MemberMyPageInfoResponse from(Member member) {
return new MemberMyPageInfoResponse(
member.getId(),
member.getEmail(),
member.getName(),
member.getGeneration().getNumber(),
member.getPosition(),
member.getPhoneNumber()
);
}
}
7 changes: 7 additions & 0 deletions src/main/java/cotato/csquiz/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cotato.csquiz.config.jwt.JwtUtil;
import cotato.csquiz.domain.dto.auth.MemberInfoResponse;
import cotato.csquiz.domain.dto.member.MemberMyPageInfoResponse;
import cotato.csquiz.domain.entity.Member;
import cotato.csquiz.exception.AppException;
import cotato.csquiz.exception.ErrorCode;
Expand Down Expand Up @@ -57,4 +58,10 @@ private void validateSamePassword(String originPassword, String newPassword) {
throw new AppException(ErrorCode.SAME_PASSWORD);
}
}

public MemberMyPageInfoResponse findMyPageInfo(Long memberId) {
Member findMember = memberRepository.findById(memberId)
.orElseThrow(() -> new AppException(ErrorCode.MEMBER_NOT_FOUND));
return MemberMyPageInfoResponse.from(findMember);
}
}

0 comments on commit d883147

Please sign in to comment.