diff --git a/build.gradle b/build.gradle index 3a86c73..4054463 100644 --- a/build.gradle +++ b/build.gradle @@ -56,6 +56,8 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-api:0.11.5' implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' + // Redis + implementation 'org.springframework.boot:spring-boot-starter-data-redis' // Test testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' diff --git a/src/main/java/flobitt/oww/domain/user/entity/User.java b/src/main/java/flobitt/oww/domain/user/entity/User.java index 5b1cab1..352a74b 100644 --- a/src/main/java/flobitt/oww/domain/user/entity/User.java +++ b/src/main/java/flobitt/oww/domain/user/entity/User.java @@ -41,6 +41,11 @@ public class User extends SoftDeleteBaseEntity { @Builder.Default private UserStatus userStatus = UserStatus.NOT_VERIFIED; + @Column(name = "user_role") + @Enumerated(EnumType.STRING) + @Builder.Default + private UserRole userRole = UserRole.USER; + @Column(name = "email_verified_at") private LocalDateTime emailVerifiedAt; diff --git a/src/main/java/flobitt/oww/domain/user/entity/UserRole.java b/src/main/java/flobitt/oww/domain/user/entity/UserRole.java new file mode 100644 index 0000000..db46fca --- /dev/null +++ b/src/main/java/flobitt/oww/domain/user/entity/UserRole.java @@ -0,0 +1,8 @@ +package flobitt.oww.domain.user.entity; + +import lombok.Getter; + +@Getter +public enum UserRole { + USER +} diff --git a/src/main/java/flobitt/oww/global/config/RedisConfig.java b/src/main/java/flobitt/oww/global/config/RedisConfig.java new file mode 100644 index 0000000..d893728 --- /dev/null +++ b/src/main/java/flobitt/oww/global/config/RedisConfig.java @@ -0,0 +1,36 @@ +package flobitt.oww.global.config; + +import flobitt.oww.global.properties.RedisProperties; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Configuration +@RequiredArgsConstructor +public class RedisConfig { + + private final RedisProperties redisProperties; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(redisProperties.getHost(), redisProperties.getPort()); + } + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(connectionFactory); + + // Key와 Value 모두 String으로 직렬화 + template.setKeySerializer(new StringRedisSerializer()); + template.setValueSerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + template.setHashValueSerializer(new StringRedisSerializer()); + + return template; + } +} diff --git a/src/main/java/flobitt/oww/global/properties/RedisProperties.java b/src/main/java/flobitt/oww/global/properties/RedisProperties.java new file mode 100644 index 0000000..8e31fd7 --- /dev/null +++ b/src/main/java/flobitt/oww/global/properties/RedisProperties.java @@ -0,0 +1,14 @@ +package flobitt.oww.global.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Data +@Configuration +@ConfigurationProperties(prefix = "spring.data.redis") +public class RedisProperties { + + private String host; + private int port; +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 729b19d..a031dd2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -22,6 +22,10 @@ spring: auth: true starttls: enable: true + data: + redis: + host: localhost + port: 6379 app: frontend-url: ${FRONTEND_URL} verification-token-expiry: ${VERIFICATION_TOKEN_EXPIRY} diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index da007a2..bba670e 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -13,6 +13,7 @@ CREATE TABLE `USERS` ( `email` VARCHAR(255) NOT NULL UNIQUE COMMENT '이메일', `password` VARCHAR(255) NOT NULL COMMENT '암호화된 비밀번호(필요하면 추후에 비밀번호 만료일자도 별도 테이블로 추가)', `user_status` VARCHAR(20) NOT NULL DEFAULT 'NOT_VERIFIED' COMMENT '계정 활성화 상태(ACTIVE, NOT_VERIFIED)', + `user_role` VARCHAR(20) NOT NULL DEFAULT 'USER' COMMENT '계정 역할(USER, ADMIN)', `email_verified_at` DATETIME NULL COMMENT '이메일 인증 완료 시간', `is_deleted` BOOLEAN NOT NULL DEFAULT FALSE, `deleted_at` DATETIME NULL,