Skip to content

Commit

Permalink
refactor: 엔티티 빌더에 대해 private 접근 제어자 추가 (#215)
Browse files Browse the repository at this point in the history
* refactor: 엔티티 빌더에 비공개 접근제어자 추가

* fix: 리프레시 토큰에 대한 정적 팩토리 메서드 추가
  • Loading branch information
uwoobeat authored Mar 1, 2024
1 parent dda8433 commit 7ac21fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ public RefreshTokenDto createRefreshToken(Long memberId) {
}

private void saveRefreshTokenToRedis(RefreshTokenDto refreshTokenDto) {
RefreshToken refreshToken = RefreshToken.builder()
.memberId(refreshTokenDto.memberId())
.token(refreshTokenDto.tokenValue())
.ttl(refreshTokenDto.ttl())
.build();
RefreshToken refreshToken =
RefreshToken.create(refreshTokenDto.memberId(), refreshTokenDto.tokenValue(), refreshTokenDto.ttl());

refreshTokenRepository.save(refreshToken);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gdschongik.gdsc.domain.auth.domain;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import org.springframework.data.annotation.Id;
Expand All @@ -18,10 +19,14 @@ public class RefreshToken {
@TimeToLive
private long ttl;

@Builder
public RefreshToken(Long memberId, String token, long ttl) {
@Builder(access = AccessLevel.PRIVATE)
private RefreshToken(Long memberId, String token, long ttl) {
this.memberId = memberId;
this.token = token;
this.ttl = ttl;
}

public static RefreshToken create(Long memberId, String token, long ttl) {
return RefreshToken.builder().memberId(memberId).token(token).ttl(ttl).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gdschongik.gdsc.global.exception.CustomException;
import com.gdschongik.gdsc.global.exception.ErrorCode;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import org.springframework.data.annotation.Id;
Expand All @@ -23,7 +24,7 @@ public class DiscordVerificationCode {
@TimeToLive
private Long ttl;

@Builder
@Builder(access = AccessLevel.PRIVATE)
private DiscordVerificationCode(String discordUsername, Integer code, Long ttl) {
validateCodeRange(code);
this.discordUsername = discordUsername;
Expand Down

0 comments on commit 7ac21fd

Please sign in to comment.