-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
정재욱
committed
Mar 28, 2024
1 parent
66fb324
commit 2185fba
Showing
7 changed files
with
115 additions
and
0 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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/ajou/hertz/common/config/ObjectMapperConfig.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,20 @@ | ||
package com.ajou.hertz.common.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
|
||
@Configuration | ||
public class ObjectMapperConfig { | ||
|
||
@Bean | ||
public ObjectMapper objectMapper() { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
JavaTimeModule javaTimeModule = new JavaTimeModule(); | ||
objectMapper.registerModules(javaTimeModule, new Jdk8Module()); | ||
return objectMapper; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/ajou/hertz/common/config/RedisTemplateConfig.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,27 @@ | ||
package com.ajou.hertz.common.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
import com.ajou.hertz.domain.user_auth_code.UserAuthCode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@Configuration | ||
public class RedisTemplateConfig { | ||
|
||
@Bean | ||
public RedisTemplate<String, UserAuthCode> redisTemplate( | ||
RedisConnectionFactory connectionFactory, | ||
ObjectMapper objectMapper | ||
) { | ||
RedisTemplate<String, UserAuthCode> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(connectionFactory); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(objectMapper, UserAuthCode.class)); | ||
return redisTemplate; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/ajou/hertz/domain/user_auth_code/UserAuthCode.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,26 @@ | ||
package com.ajou.hertz.domain.user_auth_code; | ||
|
||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class UserAuthCode implements Serializable { | ||
|
||
public static final int TTL_MINUTE = 5; | ||
|
||
private String code; | ||
private Long userId; | ||
|
||
private LocalDateTime createdAt; | ||
|
||
public UserAuthCode(String code, Long userId) { | ||
this(code, userId, LocalDateTime.now()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/ajou/hertz/domain/user_auth_code/repository/UserAuthCodeRepository.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,8 @@ | ||
package com.ajou.hertz.domain.user_auth_code.repository; | ||
|
||
import com.ajou.hertz.domain.user_auth_code.UserAuthCode; | ||
|
||
public interface UserAuthCodeRepository { | ||
|
||
UserAuthCode save(UserAuthCode userAuthCode); | ||
} |
28 changes: 28 additions & 0 deletions
28
...main/java/com/ajou/hertz/domain/user_auth_code/repository/UserAuthCodeRepositoryImpl.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,28 @@ | ||
package com.ajou.hertz.domain.user_auth_code.repository; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.ajou.hertz.domain.user_auth_code.UserAuthCode; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class UserAuthCodeRepositoryImpl implements UserAuthCodeRepository { | ||
|
||
private final RedisTemplate<String, UserAuthCode> template; | ||
|
||
@Override | ||
public UserAuthCode save(UserAuthCode userAuthCode) { | ||
template.opsForValue().set( | ||
userAuthCode.getCode(), | ||
userAuthCode, | ||
UserAuthCode.TTL_MINUTE, | ||
TimeUnit.MINUTES | ||
); | ||
return userAuthCode; | ||
} | ||
} |
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