diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 945ec0c7..870e4c8c 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -25,6 +25,9 @@ public class Onboarding extends AuditingTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; @Column(length = 30) private String nickname; @@ -65,8 +68,9 @@ public class Onboarding extends AuditingTimeEntity { @JoinColumn(name = "badge_id") private final List badges = new ArrayList<>(); - public static Onboarding newInstance(Personality personality, TestScore testScore) { + public static Onboarding newInstance(User user, Personality personality, TestScore testScore) { return Onboarding.builder() + .user(user) .isChecked(false) .personality(personality) .testScore(testScore) diff --git a/src/main/java/hous/server/domain/user/User.java b/src/main/java/hous/server/domain/user/User.java index 7bd5fe59..928fdb62 100644 --- a/src/main/java/hous/server/domain/user/User.java +++ b/src/main/java/hous/server/domain/user/User.java @@ -26,21 +26,23 @@ public class User extends AuditingTimeEntity { @Enumerated(EnumType.STRING) private UserStatus status; - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "onboarding_id", nullable = false) + @OneToOne(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private Onboarding onboarding; @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "setting_id", nullable = false) private Setting setting; - public static User newInstance(String socialId, UserSocialType socialType, String fcmToken, Onboarding onboarding, Setting setting) { + public static User newInstance(String socialId, UserSocialType socialType, String fcmToken, Setting setting) { return User.builder() .socialInfo(SocialInfo.of(socialId, socialType)) .fcmToken(fcmToken) - .onboarding(onboarding) .setting(setting) .status(UserStatus.ACTIVE) .build(); } + + public void setOnboarding(Onboarding onboarding) { + this.onboarding = onboarding; + } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 0222fd64..d61d9ad0 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -33,11 +33,14 @@ public class UserService { public Long registerUser(CreateUserDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); - User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), - onboardingRepository.save( - Onboarding.newInstance(personalityRepository.findPersonalityByColor(PersonalityColor.GRAY), - testScoreRepository.save(TestScore.newInstance()))), + User user = userRepository.save(User.newInstance( + request.getSocialId(), request.getSocialType(), request.getFcmToken(), settingRepository.save(Setting.newInstance()))); + Onboarding onboarding = onboardingRepository.save(Onboarding.newInstance( + user, + personalityRepository.findPersonalityByColor(PersonalityColor.GRAY), + testScoreRepository.save(TestScore.newInstance()))); + user.setOnboarding(onboarding); return user.getId(); }