diff --git a/backend/user-service/src/main/java/com/tadak/userservice/domain/member/controller/MemberController.java b/backend/user-service/src/main/java/com/tadak/userservice/domain/member/controller/MemberController.java index 4c97520..f4273a9 100644 --- a/backend/user-service/src/main/java/com/tadak/userservice/domain/member/controller/MemberController.java +++ b/backend/user-service/src/main/java/com/tadak/userservice/domain/member/controller/MemberController.java @@ -2,11 +2,9 @@ import com.tadak.userservice.domain.member.dto.request.LoginRequestDto; import com.tadak.userservice.domain.member.dto.request.SignupRequestDto; -import com.tadak.userservice.domain.member.dto.response.CheckEmailResponseDto; -import com.tadak.userservice.domain.member.dto.response.DuplicateCheckResponseDto; -import com.tadak.userservice.domain.member.dto.response.SignupResponseDto; -import com.tadak.userservice.domain.member.dto.response.TokenResponseDto; +import com.tadak.userservice.domain.member.dto.response.*; import com.tadak.userservice.domain.member.service.MemberService; +import com.tadak.userservice.global.jwt.filter.JwtFilter; import jakarta.mail.MessagingException; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -78,4 +76,13 @@ public ResponseEntity checkEmail(@PathVariable("email") S CheckEmailResponseDto checkEmailResponseDto = memberService.existsEmail(email); return ResponseEntity.status(HttpStatus.OK).body(checkEmailResponseDto); } + + /** + * member 정보 조회 + */ + @GetMapping("/user-info") + public ResponseEntity userInfo(@RequestHeader(JwtFilter.ACCESS_AUTHORIZATION_HEADER) String token){ + MemberResponseDto member = memberService.findByMember(token); + return ResponseEntity.status(HttpStatus.OK).body(member); + } } diff --git a/backend/user-service/src/main/java/com/tadak/userservice/domain/member/dto/response/MemberResponseDto.java b/backend/user-service/src/main/java/com/tadak/userservice/domain/member/dto/response/MemberResponseDto.java new file mode 100644 index 0000000..1cab041 --- /dev/null +++ b/backend/user-service/src/main/java/com/tadak/userservice/domain/member/dto/response/MemberResponseDto.java @@ -0,0 +1,24 @@ +package com.tadak.userservice.domain.member.dto.response; + +import com.tadak.userservice.domain.member.entity.Member; +import com.tadak.userservice.domain.member.entity.Role; +import com.tadak.userservice.domain.member.entity.State; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class MemberResponseDto { + + private Long memberId; + private String email; + private String username; + + public static MemberResponseDto from(Member member){ + return MemberResponseDto.builder() + .memberId(member.getId()) + .email(member.getEmail()) + .username(member.getUsername()) + .build(); + } +} diff --git a/backend/user-service/src/main/java/com/tadak/userservice/domain/member/service/MemberService.java b/backend/user-service/src/main/java/com/tadak/userservice/domain/member/service/MemberService.java index a5f2aec..1599cfd 100644 --- a/backend/user-service/src/main/java/com/tadak/userservice/domain/member/service/MemberService.java +++ b/backend/user-service/src/main/java/com/tadak/userservice/domain/member/service/MemberService.java @@ -4,10 +4,7 @@ import com.tadak.userservice.domain.email.service.EmailService; import com.tadak.userservice.domain.member.dto.request.LoginRequestDto; import com.tadak.userservice.domain.member.dto.request.SignupRequestDto; -import com.tadak.userservice.domain.member.dto.response.CheckEmailResponseDto; -import com.tadak.userservice.domain.member.dto.response.DuplicateCheckResponseDto; -import com.tadak.userservice.domain.member.dto.response.SignupResponseDto; -import com.tadak.userservice.domain.member.dto.response.TokenResponseDto; +import com.tadak.userservice.domain.member.dto.response.*; import com.tadak.userservice.domain.member.entity.Member; import com.tadak.userservice.domain.member.entity.Role; import com.tadak.userservice.domain.member.entity.State; @@ -31,6 +28,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; import java.time.LocalDateTime; @@ -185,4 +183,21 @@ private static RefreshToken getRefreshToken(String email, String refreshToken) { .email(email) .build(); } + + public MemberResponseDto findByMember(String token) { + + if (StringUtils.hasText(token) && token.startsWith("Bearer ")) { + token = token.substring(7); + } + + Authentication authentication = tokenProvider.getAuthentication(token); + Member member = memberRepository.findByEmail(authentication.getName()) + .orElseThrow(() -> new NotFoundMemberException(ErrorCode.NOT_FOUND_MEMBER_ERROR)); + + log.info("member id = {}", member.getId()); + log.info("member email = {}", member.getEmail()); + log.info("member username = {}", member.getUsername()); + + return MemberResponseDto.from(member); + } }