Skip to content

Commit

Permalink
feat: 새로운 토큰 클래스 작성
Browse files Browse the repository at this point in the history
- @RedisHash 적용
- 토큰 만료 기간을 상수로 적용
  • Loading branch information
SJ70 committed Jul 25, 2024
1 parent 466d5ed commit f07e88d
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/j9/bestmoments/constants/TokenExpiration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.j9.bestmoments.constants;

public final class TokenExpiration {

// 10분
public static final int ACCESS_TOKEN = 60 * 10;

// 60분
public static final int REFRESH_TOKEN = 60 * 60;

}
13 changes: 13 additions & 0 deletions src/main/java/com/j9/bestmoments/domain/AccessToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.j9.bestmoments.domain;

import com.j9.bestmoments.constants.TokenExpiration;
import org.springframework.data.redis.core.RedisHash;

@RedisHash(value = "AccessToken", timeToLive = TokenExpiration.ACCESS_TOKEN)
public class AccessToken extends Token_ {

public AccessToken(Member member, String token) {
super(member, token);
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/j9/bestmoments/domain/RefreshToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.j9.bestmoments.domain;

import com.j9.bestmoments.constants.TokenExpiration;
import org.springframework.data.redis.core.RedisHash;

@RedisHash(value = "RefreshToken", timeToLive = TokenExpiration.REFRESH_TOKEN)
public class RefreshToken extends Token_ {

public RefreshToken(Member member, String token) {
super(member, token);
}

}
23 changes: 23 additions & 0 deletions src/main/java/com/j9/bestmoments/domain/Token_.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.j9.bestmoments.domain;

import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import java.util.UUID;
import lombok.Getter;
import org.springframework.data.redis.core.RedisHash;

@Getter
@NoArgsConstructor
@RedisHash("Token")
public class Token_ {

@Id
private String token;
private UUID memberId;

public Token_(Member member, String token) {
this.token = token;
this.memberId = member.getId();
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/j9/bestmoments/repository/Token_Repository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.j9.bestmoments.repository;

import com.j9.bestmoments.domain.Token_;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface Token_Repository extends CrudRepository<Token_, String> {

}
13 changes: 13 additions & 0 deletions src/main/java/com/j9/bestmoments/service/Token_Service.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.j9.bestmoments.service;

import com.j9.bestmoments.repository.Token_Repository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class Token_Service {

private final Token_Repository tokenRepository;

}

0 comments on commit f07e88d

Please sign in to comment.