Skip to content

Commit

Permalink
Merge pull request #77 from 0702Yoon/main
Browse files Browse the repository at this point in the history
feat : 유저 자진 탈퇴 기능 추가
  • Loading branch information
0702Yoon authored Aug 14, 2024
2 parents e3c751e + 55ddfc6 commit 9087b95
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.example.bigbrotherbe.domain.member.dto.response.AffiliationCollegeResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse;
import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode;
import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto;
import com.example.bigbrotherbe.global.email.EmailRequest;
import com.example.bigbrotherbe.global.email.EmailVerificationResult;
Expand All @@ -19,6 +18,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
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.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -78,4 +78,9 @@ public interface MemberController {
@GetMapping("/refresh")
@Operation(summary = "refresh 토큰으로 토큰 재 생성 요청")
ResponseEntity<com.example.bigbrotherbe.global.exception.response.ApiResponse<TokenDto>> refreshToken(@RequestHeader("Authorization") String refreshToken);


@DeleteMapping
@Operation(summary = "유저 탈퇴")
ResponseEntity<com.example.bigbrotherbe.global.exception.response.ApiResponse<Void>> memberDeleteSelf();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.example.bigbrotherbe.domain.member.dto.response.AffiliationCollegeResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse;
import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode;
import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto;
import com.example.bigbrotherbe.global.email.EmailRequest;
import com.example.bigbrotherbe.global.email.EmailVerificationResult;
Expand All @@ -32,8 +31,6 @@
public class MemberControllerImpl implements MemberController {

private final MemberService memberService;
private final AuthUtil authUtil;
private final JwtTokenProvider jwtTokenProvider;

public ResponseEntity<ApiResponse<MemberResponse>> signUp(SignUpDto signUpDto) {
MemberResponse memberResponse = memberService.userSignUp(signUpDto);
Expand Down Expand Up @@ -86,4 +83,10 @@ public ResponseEntity<ApiResponse<List<AffiliationCollegeResponse>>> getColleges
public ResponseEntity<ApiResponse<TokenDto>> refreshToken(String refreshToken){
return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.refreshToken(refreshToken)));
}

@Override
public ResponseEntity<ApiResponse<Void>> memberDeleteSelf() {
memberService.deleteSelf();
return ResponseEntity.ok(ApiResponse.success(SUCCESS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public interface MemberService {
List<AffiliationCollegeResponse> getColleges();

TokenDto refreshToken(String refreshToken);

void deleteSelf();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.example.bigbrotherbe.domain.member.repository.AffiliationMemberRepository;
import com.example.bigbrotherbe.domain.member.repository.AffiliationRepository;
import com.example.bigbrotherbe.domain.member.util.MemberChecker;
import com.example.bigbrotherbe.domain.member.util.MemberDeleter;
import com.example.bigbrotherbe.domain.member.util.MemberLoader;
import com.example.bigbrotherbe.global.email.EmailVerificationResult;
import com.example.bigbrotherbe.global.email.MailService;
Expand All @@ -23,9 +24,7 @@
import com.example.bigbrotherbe.domain.member.entity.Member;


import com.example.bigbrotherbe.global.jwt.RefreshToken;
import com.example.bigbrotherbe.global.jwt.entity.TokenDto;
import jakarta.servlet.http.HttpServletRequest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.Duration;
Expand All @@ -36,7 +35,6 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.Authentication;
Expand All @@ -61,6 +59,8 @@ public class MemberServiceImpl implements MemberService {
private final AuthUtil authUtil;
private final MemberLoader memberLoader;
private final MemberChecker memberChecker;
private final MemberDeleter memberDeleter;

// @Value("${spring.mail.auth-code-expiration-millis}")
private final long authCodeExpirationMillis = 1800000;

Expand Down Expand Up @@ -218,6 +218,13 @@ public TokenDto refreshToken(String refreshToken) {
throw new BusinessException(ErrorCode.REFRESH_Token_Expired);
}

@Override
@Transactional()
public void deleteSelf() {
Member member = authUtil.getLoginMember();
memberDeleter.deleteMember(member);
}

public List<AffiliationCode> getDepartmentsByFaculty(AffiliationCode faculty) {
return AffiliationCode.getDepartmentsByCollege(faculty);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.bigbrotherbe.domain.member.util;


import com.example.bigbrotherbe.domain.member.entity.Member;
import com.example.bigbrotherbe.domain.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class MemberDeleter {
private final MemberRepository memberRepository;

public void deleteMember(Member member) {
memberRepository.delete(member);
}
}

0 comments on commit 9087b95

Please sign in to comment.