Implement more methods in user service
This commit is contained in:
@@ -20,16 +20,7 @@ public class UserController {
|
||||
private final UserService userService;
|
||||
|
||||
@PostMapping("/signUp")
|
||||
public Boolean signUp(@ModelAttribute @Validated UserSignUpRequest signUpReq) throws Exception {
|
||||
if(userService.isEmailExist(signUpReq.getEmail())) {
|
||||
throw new Exception("Your Mail already Exist.");
|
||||
}
|
||||
User newUser = userService.signUp(signUpReq.toUserEntity());
|
||||
System.out.println("newUser = " + newUser.toString());
|
||||
if(newUser.getId() != null) {
|
||||
System.out.println("running");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
public User signUp(@ModelAttribute @Validated UserSignUpRequest signUpReq) throws Exception {
|
||||
return userService.signUp(signUpReq);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,30 @@
|
||||
package demo.api.user;
|
||||
|
||||
import demo.api.user.domain.User;
|
||||
import demo.api.user.dtos.UserSignUpRequest;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UserService {
|
||||
/**
|
||||
* 유저의 정보로 회원가입
|
||||
* @param user 가입할 유저의 정보
|
||||
* @param signUpReq 가입할 유저의 정보 Dto
|
||||
* @return 가입된 유저 정보
|
||||
*/
|
||||
User signUp(User user);
|
||||
User signUp(UserSignUpRequest signUpReq) throws Exception;
|
||||
|
||||
/**
|
||||
* 모든 유저 리스트를 반환
|
||||
* @return 유저 리스트
|
||||
*/
|
||||
List<User> findAll();
|
||||
|
||||
/**
|
||||
* 이메일을 통해 유저 조회
|
||||
* @param email
|
||||
* @return 조회된 유저
|
||||
*/
|
||||
User findUserByEmail(String email);
|
||||
Optional<User> findByEmail(String email);
|
||||
|
||||
/**
|
||||
* 유저 정보 수정
|
||||
@@ -25,10 +34,11 @@ public interface UserService {
|
||||
*/
|
||||
User updateUser(User user, String newInfo);
|
||||
|
||||
/**
|
||||
* 이메일 중복 여부를 확인
|
||||
* @param email
|
||||
* @return true | false
|
||||
*/
|
||||
boolean isEmailExist(String email);
|
||||
// /**
|
||||
// * 이메일 중복 여부를 확인
|
||||
// *
|
||||
// * @param email
|
||||
// * @return true | false
|
||||
// */
|
||||
// boolean isEmailExist(String email);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package demo.api.user;
|
||||
|
||||
import demo.api.user.domain.User;
|
||||
import demo.api.user.dtos.UserSignUpRequest;
|
||||
import demo.api.user.repository.UserRepository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -10,18 +13,24 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RequiredArgsConstructor
|
||||
@Transactional
|
||||
public class UserServiceImpl implements UserService {
|
||||
// private final BCryptPasswordEncoder passwordEncoder;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public User signUp(User user) {
|
||||
// user.hashPassword(passwordEncoder);
|
||||
return userRepository.save(user);
|
||||
public User signUp(UserSignUpRequest signUpReq) throws Exception {
|
||||
if(this.isEmailExist(signUpReq.getEmail())) {
|
||||
throw new Exception("Your Mail already Exist.");
|
||||
}
|
||||
return userRepository.save(signUpReq.toUserEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findUserByEmail(String email) {
|
||||
return null;
|
||||
public List<User> findAll() {
|
||||
return userRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<User> findByEmail(String email) {
|
||||
return userRepository.findByEmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,8 +38,14 @@ public class UserServiceImpl implements UserService {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmailExist(String email) {
|
||||
return false;
|
||||
/**
|
||||
* 이메일 중복 여부를 확인
|
||||
*
|
||||
* @param email
|
||||
* @return true | false
|
||||
*/
|
||||
private boolean isEmailExist(String email) {
|
||||
Optional<User> byEmail = userRepository.findByEmail(email);
|
||||
return !byEmail.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,13 @@ public class UserSignUpRequest {
|
||||
@NotEmpty(message = "Please enter your Name")
|
||||
private String name;
|
||||
|
||||
@Builder
|
||||
public UserSignUpRequest(String email, String password, String name) {
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform to User Entity
|
||||
* @return User Entity
|
||||
|
||||
Reference in New Issue
Block a user