Skip to content

Commit db615a8

Browse files
Merge pull request #13 from SoongSilComputingClub/feat/#12-PreUserEntity
[Feat/#12] PreUserEntity 도입 및 Refresh Token 관련 엔티티 설정
2 parents 5cd6ab2 + a51b170 commit db615a8

11 files changed

Lines changed: 206 additions & 0 deletions

File tree

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dependencies {
5757
implementation 'org.springframework.boot:spring-boot-starter-web'
5858
implementation 'org.springframework.boot:spring-boot-starter-validation'
5959
implementation 'org.springframework.boot:spring-boot-starter-actuator'
60+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
6061

6162
// Monitoring & Observability - OpenTelemetry (traces, logs)
6263
implementation 'io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter'

src/main/java/com/example/ssccwebbe/SsccWebBeApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.scheduling.annotation.EnableScheduling;
56

67
@SpringBootApplication
8+
@EnableScheduling
79
public class SsccWebBeApplication {
810

911
public static void main(String[] args) {
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.example.ssccwebbe.domain.preuser.entity;
2+
3+
import java.time.LocalDateTime;
4+
5+
import jakarta.persistence.Column;
6+
import jakarta.persistence.Entity;
7+
import jakarta.persistence.EntityListeners;
8+
import jakarta.persistence.EnumType;
9+
import jakarta.persistence.Enumerated;
10+
import jakarta.persistence.GeneratedValue;
11+
import jakarta.persistence.GenerationType;
12+
import jakarta.persistence.Id;
13+
import jakarta.persistence.Table;
14+
15+
import org.springframework.data.annotation.CreatedDate;
16+
import org.springframework.data.annotation.LastModifiedDate;
17+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
18+
19+
import com.example.ssccwebbe.global.security.UserRoleType;
20+
21+
import lombok.AllArgsConstructor;
22+
import lombok.Builder;
23+
import lombok.Getter;
24+
import lombok.NoArgsConstructor;
25+
26+
@Entity
27+
@EntityListeners(AuditingEntityListener.class) // 생성일, 수정일 자동 변경
28+
@Table(name = "pre_user_entity")
29+
@Getter
30+
@Builder
31+
@NoArgsConstructor
32+
@AllArgsConstructor
33+
public class PreUserEntity {
34+
35+
@Id
36+
@GeneratedValue(strategy = GenerationType.IDENTITY)
37+
private Long id;
38+
39+
@Column(name = "username", unique = true, nullable = false, updatable = false)
40+
private String username;
41+
42+
// 계정 잠김 여부
43+
@Column(name = "is_lock", nullable = false)
44+
private Boolean isLock;
45+
46+
// 소셜 로그인 계정 여부
47+
@Column(name = "is_social", nullable = false)
48+
private Boolean isSocial;
49+
50+
// 합격 정보
51+
@Column(name = "is_accepted", nullable = true)
52+
private Boolean isAccepted;
53+
54+
// 자체 로그인일 경우 null 값이 들어갈 예정
55+
// 소셜 로그인일 경우 어떤 소셜인지 구분자가 들어갈 예 (naver, google 등등)
56+
@Enumerated(EnumType.STRING) // Enum이 텍스트로 들어가도록 설정
57+
@Column(name = "social_provider_type")
58+
private SocialProviderType socialProviderType;
59+
60+
// 유저의 자격/역할 (preuser/user/admin 등등)
61+
@Enumerated(EnumType.STRING) // Enum이 텍스트로 들어가도록 설정
62+
@Column(name = "role_type", nullable = false)
63+
private UserRoleType roleType;
64+
65+
// 닉네임
66+
@Column(name = "nickname")
67+
private String nickname;
68+
69+
// 이메일
70+
@Column(name = "email")
71+
private String email;
72+
73+
// 튜플의 생성 시각
74+
@CreatedDate
75+
@Column(name = "created_date", updatable = false)
76+
private LocalDateTime createdDate;
77+
78+
// 튜플의 수정 시각
79+
@LastModifiedDate
80+
@Column(name = "updated_date")
81+
private LocalDateTime updatedDate;
82+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.example.ssccwebbe.domain.preuser.entity;
2+
3+
import java.time.LocalDateTime;
4+
5+
import jakarta.persistence.Column;
6+
import jakarta.persistence.Entity;
7+
import jakarta.persistence.EntityListeners;
8+
import jakarta.persistence.GeneratedValue;
9+
import jakarta.persistence.GenerationType;
10+
import jakarta.persistence.Id;
11+
import jakarta.persistence.Table;
12+
13+
import org.springframework.data.annotation.CreatedDate;
14+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
15+
16+
import lombok.AllArgsConstructor;
17+
import lombok.Builder;
18+
import lombok.Getter;
19+
import lombok.NoArgsConstructor;
20+
21+
@Entity
22+
@EntityListeners(AuditingEntityListener.class)
23+
@Table(name = "pre_user_refresh_entity")
24+
@Getter
25+
@Builder
26+
@NoArgsConstructor
27+
@AllArgsConstructor
28+
public class PreUserRefreshEntity {
29+
@Id
30+
@GeneratedValue(strategy = GenerationType.IDENTITY)
31+
private Long id;
32+
33+
@Column(name = "username", nullable = false)
34+
private String username;
35+
36+
@Column(name = "refresh", nullable = false, length = 512)
37+
private String refresh;
38+
39+
@CreatedDate
40+
@Column(name = "created_date", updatable = false)
41+
private LocalDateTime createdDate;
42+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.ssccwebbe.domain.preuser.entity;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public enum SocialProviderType {
7+
GOOGLE("구글");
8+
private final String description;
9+
10+
SocialProviderType(String description) {
11+
this.description = description;
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.ssccwebbe.domain.preuser.repository;
2+
3+
import java.time.LocalDateTime;
4+
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
7+
import com.example.ssccwebbe.domain.preuser.entity.PreUserRefreshEntity;
8+
9+
public interface PreUserRefreshRepository extends JpaRepository<PreUserRefreshEntity, Long> {
10+
void deleteByCreatedDateBefore(LocalDateTime createdDateBefore);
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.example.ssccwebbe.global.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
5+
6+
@Configuration
7+
@EnableJpaAuditing
8+
public class JpaAuditingConfig {
9+
// createdDate 와 updatedDate 갱신을 자동화 하기 위한 설정
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.example.ssccwebbe.global.security;
2+
3+
public enum UserRoleType {
4+
PREUSER,
5+
USER,
6+
ADMIN
7+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.example.ssccwebbe.global.security.config;
2+
3+
import java.time.LocalDateTime;
4+
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.scheduling.annotation.Scheduled;
7+
import org.springframework.stereotype.Component;
8+
import org.springframework.transaction.annotation.Transactional;
9+
10+
import com.example.ssccwebbe.domain.preuser.repository.PreUserRefreshRepository;
11+
12+
import lombok.RequiredArgsConstructor;
13+
14+
@Component
15+
@RequiredArgsConstructor
16+
public class ScheduleConfig {
17+
private final PreUserRefreshRepository preUserRefreshRepository;
18+
19+
@Value("${refresh-token.ttl-days}")
20+
private int refreshTokenTtlDays; // 리프레시 토큰 TTL 설정
21+
22+
// 매일 지정시간 마다 TTL 만료 Refresh 토큰 삭제
23+
@Scheduled(cron = "${refresh-token.cleanup-cron}")
24+
@Transactional
25+
public void refreshEntityTtlSchedule() {
26+
LocalDateTime cutoff = LocalDateTime.now().minusDays(refreshTokenTtlDays);
27+
preUserRefreshRepository.deleteByCreatedDateBefore(cutoff);
28+
}
29+
}

src/main/resources/application-local.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ spring:
1111
database-platform: org.hibernate.dialect.MySQLDialect
1212
show-sql: true
1313

14+
# Refresh Token Configuration
15+
refresh-token:
16+
ttl-days: 8
17+
cleanup-cron: "0 0 3 * * *" # 3AM
1418

1519
logging:
1620
level:

0 commit comments

Comments
 (0)