diff --git a/src/main/java/slvtwn/khu/toyouserver/domain/User.java b/src/main/java/slvtwn/khu/toyouserver/domain/User.java index 059a6c9..b20ae66 100644 --- a/src/main/java/slvtwn/khu/toyouserver/domain/User.java +++ b/src/main/java/slvtwn/khu/toyouserver/domain/User.java @@ -17,22 +17,26 @@ @Getter public class User extends BaseTimeEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - private String name; + private String name; - private LocalDate birthday; + private LocalDate birthday; - private String introduction; + private String introduction; - private String profilePicture; + private String profilePicture; - public User(String name, LocalDate birthday, String introduction, String profilePicture) { - this.name = name; - this.birthday = birthday; - this.introduction = introduction; - this.profilePicture = profilePicture; - } + public User(String name, LocalDate birthday, String introduction, String profilePicture) { + this.name = name; + this.birthday = birthday; + this.introduction = introduction; + this.profilePicture = profilePicture; + } + + public static User create(String name, String profilePicture) { + return new User(name, null, null, profilePicture); + } } diff --git a/src/main/java/slvtwn/khu/toyouserver/domain/UserOAuthCredential.java b/src/main/java/slvtwn/khu/toyouserver/domain/UserOAuthCredential.java new file mode 100644 index 0000000..7fd985f --- /dev/null +++ b/src/main/java/slvtwn/khu/toyouserver/domain/UserOAuthCredential.java @@ -0,0 +1,39 @@ +package slvtwn.khu.toyouserver.domain; + +import static slvtwn.khu.toyouserver.domain.SocialAuthProvider.KAKAO; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class UserOAuthCredential { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, unique = true) + private String serialId; + + SocialAuthProvider provider; + + @Getter + @ManyToOne + @JoinColumn(name = "user_id", nullable = false) + private User user; + + public static UserOAuthCredential recordKAKAOCredential(User user, String serialId) { + return new UserOAuthCredential(null, serialId, KAKAO, user); + } +} diff --git a/src/main/java/slvtwn/khu/toyouserver/domain/UserOAuthCredentialRepository.java b/src/main/java/slvtwn/khu/toyouserver/domain/UserOAuthCredentialRepository.java new file mode 100644 index 0000000..801f922 --- /dev/null +++ b/src/main/java/slvtwn/khu/toyouserver/domain/UserOAuthCredentialRepository.java @@ -0,0 +1,8 @@ +package slvtwn.khu.toyouserver.domain; + +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserOAuthCredentialRepository extends JpaRepository { + Optional findBySerialId(String serialId); +}