Skip to content

Commit

Permalink
refactor: 회원 탈퇴 로직 변경 (#139)
Browse files Browse the repository at this point in the history
* feat: 토큰 redis 저장을 위한 dto 및 config 추가

* feat: webConfig 파일 추가

* feat: redis 토큰 저장 서비스 및 테스트 코드 추가

* feat: 에러시 모든 토큰 제거 추가

* refactor: config update

* feat: config 추가

* refactor: code smell 제거

* feat: logout 기능 추가

* refactor: 사용자 nickname 생성 및 랜덤 삭제 ID부여 제공

* refacotr: @transaction제거, redis를 사용하기 때문에 트랜잭션 전파 불필요

* feat: 삭제 요청 추가

* refactor: member mapper 메서드 위치 변경 AuthMapper -> MemberMapper

* refacotr: 패키지 위치 변경 및 socialId long->String

* feat: 회원탈퇴 요청 기능 추가

* fix: restTemplate 요청 반환 값 변경

* feat: 회원 탈퇴 요청에 대한 api 추가

* test: 회원 삭제 테스트 추가

* test: 회원 탈퇴 테스트 코드 및 Auth테스트와 member테스트 분리

* feat: 회원 탈퇴 서비스 기능 구현 및 restTemplate요청 테스트 추가

* feat: 사용하지 않는 메서드 및 회원 조회 쿼리 생성

* test: 테스트 코드 수정 및 test config 변경

* feat: WebConfig path 수정

* feat: 삭제할 회원 조건 변경

* refacotr: 테스트 로그인 get 메서드 uri변경 및 AuthorizationMember -> AuthMember / CurrentMember -> Auth

* refactor: merge develop

* fix: findMemberWithNotManager 메서드 명 findMemberNotManager 변경

* refactor: 회원 탈퇴 로직 변경
  • Loading branch information
parksey authored Nov 23, 2023
1 parent 12275e0 commit da84226
Show file tree
Hide file tree
Showing 12 changed files with 4,500 additions and 1,162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponentsBuilder;
Expand All @@ -12,14 +13,14 @@
import com.moabam.api.application.auth.mapper.AuthorizationMapper;
import com.moabam.api.application.member.MemberService;
import com.moabam.api.domain.auth.repository.TokenRepository;
import com.moabam.api.domain.member.Member;
import com.moabam.api.dto.auth.AuthorizationCodeRequest;
import com.moabam.api.dto.auth.AuthorizationCodeResponse;
import com.moabam.api.dto.auth.AuthorizationTokenInfoResponse;
import com.moabam.api.dto.auth.AuthorizationTokenRequest;
import com.moabam.api.dto.auth.AuthorizationTokenResponse;
import com.moabam.api.dto.auth.LoginResponse;
import com.moabam.api.dto.auth.TokenSaveValue;
import com.moabam.api.dto.member.DeleteMemberResponse;
import com.moabam.global.auth.model.AuthMember;
import com.moabam.global.auth.model.PublicClaim;
import com.moabam.global.common.util.GlobalConstant;
Expand Down Expand Up @@ -119,16 +120,22 @@ public void removeToken(HttpServletRequest httpServletRequest, HttpServletRespon
});
}

public void unLinkMember(DeleteMemberResponse deleteMemberResponse) {
@Transactional
public void unLinkMember(AuthMember authMember) {
Member member = memberService.findMemberToDelete(authMember.id());
unlinkRequest(member.getSocialId());
memberService.delete(member);
}

private void unlinkRequest(String socialId) {
try {
oauth2AuthorizationServerRequestService.unlinkMemberRequest(
oAuthConfig.provider().unlink(),
oAuthConfig.client().adminKey(),
unlinkRequestParam(deleteMemberResponse.socialId()));
log.info("회원 탈퇴 성공 : [id={}, socialId={}]", deleteMemberResponse.id(), deleteMemberResponse.socialId());
unlinkRequestParam(socialId));
log.info("회원 탈퇴 성공 : [socialId={}]", socialId);
} catch (BadRequestException badRequestException) {
log.warn("회원 탈퇴요청 실패 : 카카오 연결 오류");
memberService.undoDelete(deleteMemberResponse);
throw new BadRequestException(ErrorMessage.UNLINK_REQUEST_FAIL_ROLLBACK_SUCCESS);
}
}
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/com/moabam/api/application/member/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import com.moabam.api.domain.member.repository.MemberSearchRepository;
import com.moabam.api.dto.auth.AuthorizationTokenInfoResponse;
import com.moabam.api.dto.auth.LoginResponse;
import com.moabam.api.dto.member.DeleteMemberResponse;
import com.moabam.global.auth.model.AuthMember;
import com.moabam.global.error.exception.ConflictException;
import com.moabam.global.common.util.ClockHolder;
import com.moabam.global.error.exception.NotFoundException;

import lombok.RequiredArgsConstructor;
Expand All @@ -28,6 +26,7 @@ public class MemberService {

private final MemberRepository memberRepository;
private final MemberSearchRepository memberSearchRepository;
private final ClockHolder clockHolder;

public Member getById(Long memberId) {
return memberRepository.findById(memberId)
Expand All @@ -47,22 +46,16 @@ public List<Member> getRoomMembers(List<Long> memberIds) {
}

@Transactional
public DeleteMemberResponse deleteMember(AuthMember authMember) {
Member member = memberSearchRepository.findMemberNotManager(authMember.id())
.orElseThrow(() -> new ConflictException(MEMBER_NOT_FOUND));

String socialId = member.getSocialId();
member.delete();

return MemberMapper.toDeleteMemberResponse(member.getId(), socialId);
public Member findMemberToDelete(Long memberId) {
return memberSearchRepository.findMemberNotManager(memberId)
.orElseThrow(() -> new NotFoundException(MEMBER_NOT_FOUND));
}

@Transactional
public void undoDelete(DeleteMemberResponse deleteMemberResponse) {
Member member = memberSearchRepository.findMember(deleteMemberResponse.id(), false)
.orElseThrow(() -> new NotFoundException(MEMBER_NOT_FOUND));

member.undoDelete(deleteMemberResponse.socialId());
public void delete(Member member) {
member.delete(clockHolder.times());
memberRepository.flush();
memberRepository.delete(member);
}

private Member signUp(Long socialId) {
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/moabam/api/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,8 @@ public void increaseTotalCertifyCount() {
this.totalCertifyCount++;
}

public void delete() {
deletedAt = LocalDateTime.now();
socialId = deleteSocialId(deletedAt);
}

public void undoDelete(String socialId) {
this.socialId = socialId;
deletedAt = null;
public void delete(LocalDateTime now) {
socialId = deleteSocialId(now);
}

public void changeNickName(String nickname) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.moabam.api.domain.member.repository;

import static com.moabam.api.domain.member.QMember.*;
import static com.moabam.api.domain.room.QRoom.*;
import static com.moabam.api.domain.room.QParticipant.*;

import java.util.Optional;

import org.springframework.stereotype.Repository;

import com.moabam.api.domain.member.Member;
import com.moabam.global.common.util.DynamicQuery;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -37,14 +36,10 @@ public Optional<Member> findMember(Long memberId, boolean isNotDeleted) {
public Optional<Member> findMemberNotManager(Long memberId) {
return Optional.ofNullable(jpaQueryFactory
.selectFrom(member)
.leftJoin(participant).on(member.id.eq(participant.memberId))
.where(
member.id.eq(memberId),
JPAExpressions.selectOne()
.from(room)
.where(
member.nickname.eq(room.managerNickname)
)
.notExists()
participant.isManager.isNull().or(participant.isManager.isFalse())
)
.fetchFirst());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.moabam.api.dto.auth.AuthorizationTokenInfoResponse;
import com.moabam.api.dto.auth.AuthorizationTokenResponse;
import com.moabam.api.dto.auth.LoginResponse;
import com.moabam.api.dto.member.DeleteMemberResponse;
import com.moabam.global.auth.annotation.Auth;
import com.moabam.global.auth.model.AuthMember;

Expand Down Expand Up @@ -57,7 +56,6 @@ public void logout(@Auth AuthMember authMember, HttpServletRequest httpServletRe
@DeleteMapping
@ResponseStatus(HttpStatus.OK)
public void deleteMember(@Auth AuthMember authMember) {
DeleteMemberResponse deleteMemberResponse = memberService.deleteMember(authMember);
authorizationService.unLinkMember(deleteMemberResponse);
authorizationService.unLinkMember(authMember);
}
}
Loading

0 comments on commit da84226

Please sign in to comment.