Skip to content

Commit

Permalink
✨ feat: 유저의 인증 정보만을 저장하는 Auth Credential Domain 정의 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
loveysuby committed Sep 4, 2024
1 parent 3387674 commit 9abd27e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/main/java/slvtwn/khu/toyouserver/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<UserOAuthCredential, Long> {
Optional<UserOAuthCredential> findBySerialId(String serialId);
}

0 comments on commit 9abd27e

Please sign in to comment.