From c1f9204a1f419af890ac241fbd9bf639c6446102 Mon Sep 17 00:00:00 2001 From: gitjiho Date: Thu, 14 Nov 2024 12:58:45 +0900 Subject: [PATCH] feat: add memberInfo response logic --- .../gdg/kkia/member/controller/MemberController.java | 10 +++++++++- .../com/gdg/kkia/member/dto/MemberInfoResponse.java | 7 +++++++ .../com/gdg/kkia/member/service/MemberService.java | 11 +++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/gdg/kkia/member/dto/MemberInfoResponse.java diff --git a/src/main/java/com/gdg/kkia/member/controller/MemberController.java b/src/main/java/com/gdg/kkia/member/controller/MemberController.java index 9e5559b..e766fae 100644 --- a/src/main/java/com/gdg/kkia/member/controller/MemberController.java +++ b/src/main/java/com/gdg/kkia/member/controller/MemberController.java @@ -2,6 +2,7 @@ import com.gdg.kkia.auth.dto.TokenResponse; import com.gdg.kkia.member.dto.LoginRequest; +import com.gdg.kkia.member.dto.MemberInfoResponse; import com.gdg.kkia.member.service.MemberService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -14,7 +15,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api") -@Tag(name = "회원 관리", description = "회원 관리 관련 API") +@Tag(name = "회원 정보", description = "회원 정보 관련 API") public class MemberController { private final MemberService memberService; @@ -26,6 +27,13 @@ public ResponseEntity tempLogin(@RequestBody LoginRequest request return ResponseEntity.status(HttpStatus.CREATED).body(registerResponse); } + @Operation(summary = "멤버 정보조회", description = "로그인한 사용자의 이름, 이메일을 조회합니다.") + @GetMapping("/members") + public ResponseEntity getMemberInfo(@RequestAttribute("memberId") Long memberId) { + MemberInfoResponse memberInfoResponse = memberService.readMemberInfo(memberId); + return ResponseEntity.ok().body(memberInfoResponse); + } + @Operation(summary = "멤버 회원탈퇴", description = "회원 정보를 삭제합니다.") @DeleteMapping("/members/withdrawal") public ResponseEntity deleteMember(@RequestAttribute("memberId") Long memberId) { diff --git a/src/main/java/com/gdg/kkia/member/dto/MemberInfoResponse.java b/src/main/java/com/gdg/kkia/member/dto/MemberInfoResponse.java new file mode 100644 index 0000000..f079b81 --- /dev/null +++ b/src/main/java/com/gdg/kkia/member/dto/MemberInfoResponse.java @@ -0,0 +1,7 @@ +package com.gdg.kkia.member.dto; + +public record MemberInfoResponse( + String name, + String email +) { +} diff --git a/src/main/java/com/gdg/kkia/member/service/MemberService.java b/src/main/java/com/gdg/kkia/member/service/MemberService.java index f0b2385..88cdddc 100644 --- a/src/main/java/com/gdg/kkia/member/service/MemberService.java +++ b/src/main/java/com/gdg/kkia/member/service/MemberService.java @@ -9,6 +9,7 @@ import com.gdg.kkia.common.exception.ConflictException; import com.gdg.kkia.common.exception.NotFoundException; import com.gdg.kkia.member.dto.LoginRequest; +import com.gdg.kkia.member.dto.MemberInfoResponse; import com.gdg.kkia.member.entity.Member; import com.gdg.kkia.member.repository.MemberRepository; import com.gdg.kkia.point.service.PointLogService; @@ -53,6 +54,7 @@ public TokenResponse kakaoLogin(String authorizationCode) { return new TokenResponse(accessToken, refreshToken); } + @Transactional public void registerNewMember(String name, String email) { if (memberRepository.existsByEmail(email)) { @@ -63,6 +65,15 @@ public void registerNewMember(String name, String email) { memberRepository.save(newMember); } + @Transactional(readOnly = true) + public MemberInfoResponse readMemberInfo(Long memberId) { + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new NotFoundException("id에 해당하는 멤버가 없습니다.")); + + return new MemberInfoResponse(member.getName(), member.getEmail()); + } + + @Transactional public void deleteMember(Long memberId) { if (!memberRepository.existsById(memberId)) { throw new NotFoundException("id에 해당하는 멤버가 없습니다.");