Skip to content

Commit

Permalink
feat: UserSignUpPolicy Domain Service 구현 및 SignUp 로직에 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
jihwan2da committed Jul 29, 2023
1 parent 972a333 commit 0cc7345
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
import com.gloddy.server.auth.domain.User;
import com.gloddy.server.auth.domain.vo.Phone;
import com.gloddy.server.auth.domain.vo.School;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import static com.gloddy.server.auth.domain.dto.AuthRequest.*;

@Component
@RequiredArgsConstructor
public class UserFactory {

private final UserSignUpPolicy userSignUpPolicy;

public User getUser(SignUp request) {
userSignUpPolicy.validate(request.getPhoneNumber());

Phone phone = getPhone(request.getPhoneNumber());
School school = getSchool(request.getSchoolInfo());
return User.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.gloddy.server.auth.domain.service;

import com.gloddy.server.auth.domain.User;
import com.gloddy.server.auth.domain.vo.Phone;
import com.gloddy.server.auth.exception.AlreadyUserSignUpException;
import com.gloddy.server.user.infra.repository.UserJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@RequiredArgsConstructor
public class UserSignUpPolicy {

private final UserJpaRepository userJpaRepository;

public void validate(String phoneNumber) {
Phone phone = new Phone(phoneNumber);

Optional<User> user = userJpaRepository.findByPhone(phone);

if (user.isPresent()) {
throw new AlreadyUserSignUpException();
}
}
}

0 comments on commit 0cc7345

Please sign in to comment.