Skip to content

Commit

Permalink
Merge pull request #168 from makevook/issue/166
Browse files Browse the repository at this point in the history
feat,refactor,chore: 유저 닉네임 입력 시 앞뒤 공백 문자 무시 로직 추가
  • Loading branch information
seungyeop-lee authored Jul 22, 2024
2 parents 0aa2e60 + 7d601fc commit 87ff9e4
Show file tree
Hide file tree
Showing 47 changed files with 441 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import vook.server.api.domain.template_vocabulary.model.TemplateTermRepository;
import vook.server.api.domain.template_vocabulary.model.TemplateVocabularyRepository;
import vook.server.api.domain.template_vocabulary.model.TemplateVocabularyType;
import vook.server.api.domain.user.model.SocialUserRepository;
import vook.server.api.domain.user.model.UserInfoRepository;
import vook.server.api.domain.user.model.UserRepository;
import vook.server.api.domain.user.model.social_user.SocialUserRepository;
import vook.server.api.domain.user.model.user.UserRepository;
import vook.server.api.domain.user.model.user_info.UserInfoRepository;
import vook.server.api.domain.vocabulary.model.term.TermRepository;
import vook.server.api.infra.search.demo.MeilisearchDemoTermSearchService;
import vook.server.api.infra.vocabulary.cache.UserVocabularyCacheRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.RequiredArgsConstructor;
import vook.server.api.domain.user.exception.UserNotFoundException;
import vook.server.api.domain.user.logic.dto.UserOnboardingCommand;
import vook.server.api.domain.user.logic.dto.UserRegisterCommand;
import vook.server.api.domain.user.logic.dto.UserSignUpFromSocialCommand;
import vook.server.api.domain.user.model.*;
import vook.server.api.domain.user.model.social_user.SocialUser;
import vook.server.api.domain.user.model.social_user.SocialUserFactory;
import vook.server.api.domain.user.model.social_user.SocialUserRepository;
import vook.server.api.domain.user.model.user.User;
import vook.server.api.domain.user.model.user.UserFactory;
import vook.server.api.domain.user.model.user.UserRepository;
import vook.server.api.domain.user.model.user_info.UserInfo;
import vook.server.api.domain.user.model.user_info.UserInfoFactory;
import vook.server.api.domain.user.model.user_info.UserInfoRepository;
import vook.server.api.globalcommon.annotation.DomainLogic;

import java.util.Optional;
Expand All @@ -17,6 +23,9 @@
@RequiredArgsConstructor
public class UserLogic {

private final UserFactory userFactory;
private final SocialUserFactory socialUserFactory;
private final UserInfoFactory userInfoFactory;
private final UserRepository repository;
private final SocialUserRepository socialUserRepository;
private final UserInfoRepository userInfoRepository;
Expand All @@ -25,37 +34,30 @@ public Optional<SocialUser> findByProvider(@NotBlank String provider, @NotBlank
return socialUserRepository.findByProviderAndProviderUserId(provider, providerUserId);
}

public SocialUser signUpFromSocial(@Valid UserSignUpFromSocialCommand command) {
public SocialUser signUpFromSocial(@NotNull @Valid UserSignUpFromSocialCommand command) {
User user = repository
.findByEmail(command.email())
.orElseGet(() -> repository.save(command.toNewUser()));
.orElseGet(() -> repository.save(command.toNewUser(userFactory)));

SocialUser savedSocialUser = socialUserRepository.save(command.toSocialUser(user));
user.addSocialUser(savedSocialUser);

return savedSocialUser;
return socialUserRepository.save(command.toSocialUser(socialUserFactory, user));
}

public User getByUid(@NotBlank String uid) {
return getUserByUid(uid);
}

public void register(@Valid UserRegisterCommand command) {
public void register(@NotNull @Valid UserRegisterCommand command) {
User user = getUserByUid(command.userUid());
user.validateRegisterProcessReady();

UserInfo userInfo = userInfoRepository.save(UserInfo.forRegisterOf(
UserInfo userInfo = userInfoFactory.createForRegisterOf(
command.nickname(),
user,
command.marketingEmailOptIn()
));
user.register(userInfo);
command.marketingEmailOptIn(),
user
);
userInfoRepository.save(userInfo);
}

public void onboarding(@Valid UserOnboardingCommand command) {
public void onboarding(@NotNull @Valid UserOnboardingCommand command) {
User user = getUserByUid(command.userUid());
user.validateOnboardingProcessReady();

user.onboarding(command.funnel(), command.job());
}

Expand All @@ -64,22 +66,16 @@ public void updateInfo(
@NotBlank @Size(min = 1, max = 10) String nickname
) {
User user = getUserByUid(uid);
user.validateRegisterProcessCompleted();
user.update(nickname);
}

public void withdraw(@NotBlank String uid) {
User user = getUserByUid(uid);
if (user.getStatus() == UserStatus.WITHDRAWN) {
return;
}
user.withdraw();
}

public void reRegister(UserRegisterCommand command) {
public void reRegister(@NotNull @Valid UserRegisterCommand command) {
User user = getUserByUid(command.userUid());
user.validateReRegisterProcessReady();

user.reRegister(command.nickname(), command.marketingEmailOptIn());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package vook.server.api.domain.user.logic.dto;
package vook.server.api.domain.user.logic;

import jakarta.validation.constraints.NotBlank;
import lombok.Builder;
import vook.server.api.domain.user.model.Funnel;
import vook.server.api.domain.user.model.Job;
import vook.server.api.domain.user.model.user_info.Funnel;
import vook.server.api.domain.user.model.user_info.Job;

@Builder
public record UserOnboardingCommand(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vook.server.api.domain.user.logic.dto;
package vook.server.api.domain.user.logic;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package vook.server.api.domain.user.logic;

import jakarta.validation.constraints.Email;
import lombok.Builder;
import vook.server.api.domain.user.model.social_user.SocialUser;
import vook.server.api.domain.user.model.social_user.SocialUserFactory;
import vook.server.api.domain.user.model.user.User;
import vook.server.api.domain.user.model.user.UserFactory;

@Builder
public record UserSignUpFromSocialCommand(
String provider,
String providerUserId,

@Email
String email
) {
public User toNewUser(UserFactory factory) {
return factory.createForSignUpFromSocialOf(email);
}

public SocialUser toSocialUser(SocialUserFactory factory, User user) {
return factory.createForNewOf(provider, providerUserId, user);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package vook.server.api.domain.user.model.social_user;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import vook.server.api.domain.user.model.user.User;
import vook.server.api.globalcommon.annotation.ModelFactory;

@ModelFactory
public class DefaultSocialUserFactory implements SocialUserFactory {

@Override
public SocialUser createForNewOf(
@NotEmpty String provider,
@NotEmpty String providerUserId,
@NotNull User user
) {
SocialUser socialUser = SocialUser.builder()
.provider(provider)
.providerUserId(providerUserId)
.user(user)
.build();

user.addSocialUser(socialUser);
return socialUser;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package vook.server.api.domain.user.model;
package vook.server.api.domain.user.model.social_user;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import vook.server.api.domain.user.model.user.User;

import java.time.LocalDateTime;

@Getter
@Entity
@Table(name = "social_user")
@EntityListeners(AuditingEntityListener.class)
@Builder(access = AccessLevel.PACKAGE)
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PACKAGE)
public class SocialUser {

@Id
Expand All @@ -28,16 +32,4 @@ public class SocialUser {
@ManyToOne
@JoinColumn(name = "user_id")
private User user;

public static SocialUser forNewOf(
String provider,
String providerUserId,
User user
) {
SocialUser socialUser = new SocialUser();
socialUser.provider = provider;
socialUser.providerUserId = providerUserId;
socialUser.user = user;
return socialUser;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package vook.server.api.domain.user.model.social_user;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import vook.server.api.domain.user.model.user.User;

public interface SocialUserFactory {

SocialUser createForNewOf(
@NotEmpty String provider,
@NotEmpty String providerUserId,
@NotNull User user
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vook.server.api.domain.user.model;
package vook.server.api.domain.user.model.social_user;

import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package vook.server.api.domain.user.model.user;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty;
import vook.server.api.globalcommon.annotation.ModelFactory;

import java.util.ArrayList;
import java.util.UUID;

@ModelFactory
public class DefaultUserFactory implements UserFactory {

@Override
public User createForSignUpFromSocialOf(@NotEmpty @Email String email) {
return User.builder()
.uid(UUID.randomUUID().toString())
.email(email)
.status(UserStatus.SOCIAL_LOGIN_COMPLETED)
.onboardingCompleted(false)
.socialUsers(new ArrayList<>())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package vook.server.api.domain.user.model;
package vook.server.api.domain.user.model.user;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.*;
import vook.server.api.domain.user.exception.*;
import vook.server.api.domain.user.model.social_user.SocialUser;
import vook.server.api.domain.user.model.user_info.Funnel;
import vook.server.api.domain.user.model.user_info.Job;
import vook.server.api.domain.user.model.user_info.UserInfo;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Getter
@Entity
@Table(name = "users")
@Builder(access = AccessLevel.PACKAGE)
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PACKAGE)
public class User {

@Id
Expand All @@ -38,23 +44,13 @@ public class User {

private LocalDateTime withdrawnAt;

@Builder.Default
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
private List<SocialUser> socialUsers = new ArrayList<>();

@OneToOne(mappedBy = "user")
private UserInfo userInfo;

public static User forSignUpFromSocialOf(
String email
) {
User user = new User();
user.uid = UUID.randomUUID().toString();
user.email = email;
user.status = UserStatus.SOCIAL_LOGIN_COMPLETED;
user.onboardingCompleted = false;
return user;
}

public void addSocialUser(SocialUser socialUser) {
socialUsers.add(socialUser);
}
Expand All @@ -66,22 +62,32 @@ public void register(UserInfo userInfo) {
}

public void onboarding(Funnel funnel, Job job) {
validateOnboardingProcessReady();

this.onboardingCompleted = true;
this.userInfo.addOnboardingInfo(funnel, job);
this.onboardingCompletedAt = LocalDateTime.now();
}

public void update(String nickname) {
validateRegisterProcessCompleted();

this.userInfo.update(nickname);
this.lastUpdatedAt = LocalDateTime.now();
}

public void withdraw() {
if (this.status == UserStatus.WITHDRAWN) {
return;
}

this.status = UserStatus.WITHDRAWN;
this.withdrawnAt = LocalDateTime.now();
}

public void reRegister(String nickname, Boolean marketingEmailOptIn) {
validateReRegisterProcessReady();

this.status = UserStatus.REGISTERED;
this.onboardingCompleted = false;
this.userInfo.reRegister(nickname, marketingEmailOptIn);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package vook.server.api.domain.user.model.user;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty;

public interface UserFactory {
User createForSignUpFromSocialOf(@NotEmpty @Email String email);
}
Loading

0 comments on commit 87ff9e4

Please sign in to comment.