Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 멤버 탈퇴 api 구현 #38

Merged
merged 18 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -23,4 +25,10 @@ public ResponseEntity<Page<MemberFindAllResponse>> getMembers(MemberQueryRequest
Page<MemberFindAllResponse> response = memberService.findAll(queryRequest, pageable);
return ResponseEntity.ok().body(response);
}

@DeleteMapping("/{memberId}")
public ResponseEntity<Void> withdrawMember(@PathVariable Long memberId) {
memberService.withdrawMember(memberId);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.gdschongik.gdsc.domain.member.application;

import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

import com.gdschongik.gdsc.domain.auth.dao.RefreshTokenRepository;
import com.gdschongik.gdsc.domain.member.dao.MemberRepository;
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest;
import com.gdschongik.gdsc.domain.member.dto.response.MemberFindAllResponse;
import com.gdschongik.gdsc.global.exception.CustomException;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -16,9 +20,16 @@
public class MemberService {

private final MemberRepository memberRepository;
private final RefreshTokenRepository refreshTokenRepository;

public Page<MemberFindAllResponse> findAll(MemberQueryRequest queryRequest, Pageable pageable) {
Page<Member> members = memberRepository.findAll(queryRequest, pageable);
return members.map(MemberFindAllResponse::of);
}

@Transactional
public void withdrawMember(Long memberId) {
Member member = memberRepository.findById(memberId).orElseThrow(() -> new CustomException(MEMBER_NOT_FOUND));
member.softDelete();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.gdschongik.gdsc.domain.member.domain;

import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

import com.gdschongik.gdsc.domain.common.model.BaseTimeEntity;
import com.gdschongik.gdsc.global.exception.CustomException;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down Expand Up @@ -86,4 +89,11 @@ public static Member createGuestMember(String oauthId) {
.status(MemberStatus.NORMAL)
.build();
}

public void softDelete() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void softDelete() {
public void withdraw() {

의미를 더 잘 드러낼 수 있는 메서드 이름을 써주면 좋을 것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 지적 감사합니다👍

if (this.status == MemberStatus.DELETED) {
throw new CustomException(MEMBER_ALREADY_SOFT_DELETED);
}
this.status = MemberStatus.DELETED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public enum ErrorCode {
EXPIRED_JWT_TOKEN(HttpStatus.UNAUTHORIZED, "만료된 JWT 토큰입니다."),

// Parameter
INVALID_QUERY_PARAMETER(HttpStatus.BAD_REQUEST, "잘못된 쿼리 파라미터입니다.");
INVALID_QUERY_PARAMETER(HttpStatus.BAD_REQUEST, "잘못된 쿼리 파라미터입니다."),

// Member
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다."),
MEMBER_ALREADY_SOFT_DELETED(HttpStatus.BAD_REQUEST, "이미 soft delete된 회원입니다.");

private final HttpStatus status;
private final String message;
Expand Down
Loading