From fe947088c5ef6ba023bf03e290d29031ac39d2c1 Mon Sep 17 00:00:00 2001 From: LeeYulhee Date: Mon, 21 Jul 2025 12:26:06 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Chore:=20Redis=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 ++ .../oww/global/config/RedisConfig.java | 36 +++++++++++++++++++ .../global/properties/RedisProperties.java | 14 ++++++++ src/main/resources/application.yml | 4 +++ 4 files changed, 56 insertions(+) create mode 100644 src/main/java/flobitt/oww/global/config/RedisConfig.java create mode 100644 src/main/java/flobitt/oww/global/properties/RedisProperties.java 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/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} From cf015b54a45a39aeb996ae79ec834a419b4e4f8b Mon Sep 17 00:00:00 2001 From: LeeYulhee Date: Wed, 23 Jul 2025 00:14:00 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Feat:=20user=5Frole=20=EC=BB=AC=EB=9F=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/flobitt/oww/domain/user/entity/User.java | 5 +++++ .../java/flobitt/oww/domain/user/entity/UserRole.java | 8 ++++++++ src/main/resources/data.sql | 1 + 3 files changed, 14 insertions(+) create mode 100644 src/main/java/flobitt/oww/domain/user/entity/UserRole.java 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/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,