Skip to content

Commit

Permalink
[MERGE/#115] 온보딩 시 이탈한 회원 DB를 삭제하는 스케줄링 로직 구현
Browse files Browse the repository at this point in the history
[FEAT] #115 - 온보딩 시 이탈한 회원 DB를 삭제하는 스케줄링 로직 구현
  • Loading branch information
ckkim817 authored Jul 18, 2024
2 parents 0df6866 + 1602312 commit 07d9434
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class SeonyakServerApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.seonyakServer.domain.member.repository;

import java.time.LocalDateTime;
import java.util.Optional;
import org.sopt.seonyakServer.domain.member.model.Member;
import org.sopt.seonyakServer.domain.member.model.SocialType;
Expand All @@ -21,4 +22,7 @@ default Member findMemberByIdOrThrow(Long id) {
return findMemberById(id)
.orElseThrow(() -> new CustomException(ErrorType.NOT_FOUND_MEMBER_ERROR));
}

// phoneNumber가 null이고 updatedAt 시간이 time만큼 보다 더 이전인 모든 Member 엔티티를 삭제
void deleteByPhoneNumberIsNullAndUpdatedAtBefore(LocalDateTime time);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.seonyakServer.domain.member.service;

import jakarta.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.util.Random;
import lombok.RequiredArgsConstructor;
import net.nurigo.sdk.NurigoApp;
Expand Down Expand Up @@ -28,6 +29,7 @@
import org.sopt.seonyakServer.global.exception.model.CustomException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -61,6 +63,7 @@ public void init() {
}

// JWT Access Token 생성
@Transactional
public LoginSuccessResponse create(
final String authorizationCode,
final MemberLoginRequest loginRequest
Expand All @@ -71,7 +74,7 @@ public LoginSuccessResponse create(
}

// 소셜 플랫폼으로부터 해당 유저 정보를 받아옴
public MemberInfoResponse getMemberInfoResponse(
private MemberInfoResponse getMemberInfoResponse(
final String authorizationCode,
final MemberLoginRequest loginRequest
) {
Expand Down Expand Up @@ -104,14 +107,14 @@ private LoginSuccessResponse getTokenDto(final MemberInfoResponse memberInfoResp
}
}

public boolean isExistingMember(
private boolean isExistingMember(
final SocialType socialType,
final String socialId
) {
return memberRepository.findBySocialTypeAndSocialId(socialType, socialId).isPresent();
}

public Long getMemberIdBySocialId(
private Long getMemberIdBySocialId(
final SocialType socialType,
final String socialId
) {
Expand All @@ -122,13 +125,14 @@ public Long getMemberIdBySocialId(
return member.getId();
}

public LoginSuccessResponse getTokenByMemberId(final Long id) {
private LoginSuccessResponse getTokenByMemberId(final Long id) {
MemberAuthentication memberAuthentication = new MemberAuthentication(id, null, null);

return LoginSuccessResponse.of(jwtTokenProvider.issueAccessToken(memberAuthentication));
}

// 닉네임 유효성 검증
@Transactional(readOnly = true)
public void validNickname(final NicknameRequest nicknameRequest) {
if (!nicknameRequest.nickname().matches(NICKNAME_PATTERN)) { // 형식 체크
throw new CustomException(ErrorType.INVALID_NICKNAME_ERROR);
Expand Down Expand Up @@ -166,6 +170,7 @@ public MemberJoinResponse patchMemberJoin(MemberJoinRequest memberJoinRequest) {
);
}

@Transactional
public void sendMessage(SendCodeRequest sendCodeRequest) {
Message message = new Message();

Expand Down Expand Up @@ -196,6 +201,7 @@ private String generateRandomNumber(int digitCount) {
}

// 인증번호 일치 여부 확인
@Transactional
public void verifyCode(VerifyCodeRequest verifyCodeRequest) {
String number = verifyCodeRequest.phoneNumber().replaceAll("-", "");

Expand All @@ -214,4 +220,11 @@ private void validPhoneNumberDuplication(String phoneNumber) {
throw new CustomException(ErrorType.PHONE_NUMBER_DUP_ERROR);
}
}

@Scheduled(fixedRate = 43200000) // 12시간마다 실행 (43200000 밀리초)
@Transactional
public void deleteMembersWithNullPhoneNumber() {
LocalDateTime oneHourAgo = LocalDateTime.now().minusMinutes(60);
memberRepository.deleteByPhoneNumberIsNullAndUpdatedAtBefore(oneHourAgo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class CodeService {

private final CodeRepository codeRepository;

@Transactional
public void saveVerificationCode(
final String phoneNumber,
final String verificationCode
Expand All @@ -27,7 +26,6 @@ public void saveVerificationCode(
);
}

@Transactional(readOnly = true)
public String findCodeByPhoneNumber(final String phoneNumber) {
Code code = codeRepository.findByPhoneNumber(phoneNumber).orElseThrow(
() -> new CustomException(ErrorType.NO_VERIFICATION_REQUEST_HISTORY)
Expand Down

0 comments on commit 07d9434

Please sign in to comment.