Skip to content

Commit b0b3490

Browse files
committed
feat(oauth): 정적 팩토리 메서드 추가
- 도메인 내부에 public으로 create 메서드를 만들어 private 빌더 패턴을 활용
1 parent 1c3024c commit b0b3490

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.somemore.global.auth.oauth.domain;
22

33
import com.somemore.global.common.entity.BaseEntity;
4+
import com.somemore.user.domain.User;
45
import jakarta.persistence.Column;
56
import jakarta.persistence.Entity;
67
import jakarta.persistence.EnumType;
@@ -37,8 +38,16 @@ public class OAuthInfo extends BaseEntity {
3738
@Column(name = "oauth_provider", nullable = false)
3839
private OAuthProvider oAuthProvider;
3940

41+
public static OAuthInfo create(User user, CommonOAuthInfo commonOAuthInfo) {
42+
return OAuthInfo.builder()
43+
.userId(user.getId())
44+
.oauthId(commonOAuthInfo.oauthId())
45+
.oAuthProvider(commonOAuthInfo.provider())
46+
.build();
47+
}
48+
4049
@Builder
41-
public OAuthInfo(UUID userId, String oauthId, OAuthProvider oAuthProvider) {
50+
private OAuthInfo(UUID userId, String oauthId, OAuthProvider oAuthProvider) {
4251
this.userId = userId;
4352
this.oauthId = oauthId;
4453
this.oAuthProvider = oAuthProvider;

src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrarImpl.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ public class OAuthInfoRegistrarImpl implements OAuthInfoRegistrar {
1919

2020
@Override
2121
public OAuthInfo register(User user, CommonOAuthInfo commonOAuthInfo) {
22-
return oauthInfoRepository.save(
23-
createOAuthInfo(user, commonOAuthInfo));
22+
OAuthInfo oAuthInfo = OAuthInfo.create(user, commonOAuthInfo);
23+
return oauthInfoRepository.save(oAuthInfo);
2424
}
2525

26-
private OAuthInfo createOAuthInfo(User user, CommonOAuthInfo commonOAuthInfo) {
27-
return OAuthInfo.builder()
28-
.userId(user.getId())
29-
.oauthId(commonOAuthInfo.oauthId())
30-
.oAuthProvider(commonOAuthInfo.provider())
31-
.build();
32-
}
26+
3327
}

0 commit comments

Comments
 (0)