-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: smsRedisService -> Provider로 rename && 타입별 Service 분리
- Loading branch information
1 parent
e2c2d8f
commit fd00d56
Showing
25 changed files
with
428 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
src/main/java/com/kcy/fitapet/global/common/redis/sms/SmsCertificationServiceImpl.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
src/main/java/com/kcy/fitapet/global/common/redis/sms/dao/SmsCertificationRepository.java
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
src/main/java/com/kcy/fitapet/global/common/redis/sms/domain/SmsCertification.java
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
src/main/java/com/kcy/fitapet/global/common/redis/sms/provider/SmsOauthProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.kcy.fitapet.global.common.redis.sms.provider; | ||
|
||
import com.kcy.fitapet.domain.member.exception.SmsErrorCode; | ||
import com.kcy.fitapet.global.common.redis.sms.dao.*; | ||
import com.kcy.fitapet.global.common.redis.sms.domain.*; | ||
import com.kcy.fitapet.global.common.redis.sms.type.SmsPrefix; | ||
import com.kcy.fitapet.global.common.response.exception.GlobalErrorException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@Service | ||
@Primary | ||
@RequiredArgsConstructor | ||
public class SmsOauthProvider implements SmsRedisProvider { | ||
private final SmsOauthRepository smsOauthRepository; | ||
|
||
private final RedisTemplate<String, SmsOauth> redisTemplate; | ||
|
||
@Override | ||
public void saveSmsAuthToken(String phone, String code, SmsPrefix prefix) { | ||
smsOauthRepository.save(SmsOauth.of(phone, code)); | ||
} | ||
|
||
@Override | ||
public boolean isCorrectCode(String phoneNumber, String code, SmsPrefix prefix) { | ||
Optional<SmsOauth> smsOauth = smsOauthRepository.findById(phoneNumber); | ||
return smsOauth.map(oauth -> oauth.getCode().equals(code)).orElse(false); | ||
} | ||
|
||
@Override | ||
public boolean isExistsCode(String phoneNumber, SmsPrefix prefix) { | ||
return smsOauthRepository.existsById(phoneNumber); | ||
} | ||
|
||
@Override | ||
public void removeCode(String phoneNumber, SmsPrefix prefix) { | ||
smsOauthRepository.deleteById(phoneNumber); | ||
} | ||
|
||
@Override | ||
public LocalDateTime getExpiredTime(String phoneNumber, SmsPrefix prefix) { | ||
Long ttl = redisTemplate.getExpire(getTopic(phoneNumber, prefix)); | ||
log.info("ttl: {}", ttl); | ||
|
||
if (ttl == null || ttl < 0L) | ||
throw new GlobalErrorException(SmsErrorCode.EXPIRED_AUTH_CODE); | ||
|
||
return LocalDateTime.now().plusSeconds(ttl); | ||
} | ||
} |
Oops, something went wrong.