Skip to content

Commit

Permalink
#67 [fix] User, Onboarding 테이블 연관관계 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
orijoon98 committed Sep 14, 2022
1 parent c320d86 commit a492ff8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/main/java/hous/server/domain/user/Onboarding.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -65,8 +68,9 @@ public class Onboarding extends AuditingTimeEntity {
@JoinColumn(name = "badge_id")
private final List<Badge> 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)
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/hous/server/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
11 changes: 7 additions & 4 deletions src/main/java/hous/server/service/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit a492ff8

Please sign in to comment.