Skip to content

Commit

Permalink
Merge pull request #21 from GDG-Hackathon-77ia/feat/userinfo
Browse files Browse the repository at this point in the history
feat: add memberInfo response logic
  • Loading branch information
GitJIHO authored Nov 14, 2024
2 parents 287c2cc + c1f9204 commit 79e5300
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +15,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
@Tag(name = "회원 관리", description = "회원 관리 관련 API")
@Tag(name = "회원 정보", description = "회원 정보 관련 API")
public class MemberController {

private final MemberService memberService;
Expand All @@ -26,6 +27,13 @@ public ResponseEntity<TokenResponse> tempLogin(@RequestBody LoginRequest request
return ResponseEntity.status(HttpStatus.CREATED).body(registerResponse);
}

@Operation(summary = "멤버 정보조회", description = "로그인한 사용자의 이름, 이메일을 조회합니다.")
@GetMapping("/members")
public ResponseEntity<MemberInfoResponse> getMemberInfo(@RequestAttribute("memberId") Long memberId) {
MemberInfoResponse memberInfoResponse = memberService.readMemberInfo(memberId);
return ResponseEntity.ok().body(memberInfoResponse);
}

@Operation(summary = "멤버 회원탈퇴", description = "회원 정보를 삭제합니다.")
@DeleteMapping("/members/withdrawal")
public ResponseEntity<Void> deleteMember(@RequestAttribute("memberId") Long memberId) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/gdg/kkia/member/dto/MemberInfoResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.gdg.kkia.member.dto;

public record MemberInfoResponse(
String name,
String email
) {
}
11 changes: 11 additions & 0 deletions src/main/java/com/gdg/kkia/member/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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에 해당하는 멤버가 없습니다.");
Expand Down

0 comments on commit 79e5300

Please sign in to comment.