Skip to content

Commit

Permalink
Merge pull request #29 from Leets-Official/Refactor-#24
Browse files Browse the repository at this point in the history
Refactor-#24
  • Loading branch information
KoungQ authored Jul 16, 2024
2 parents ee1ca96 + 1d955f9 commit 65ba143
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/main/java/leets/weeth/domain/user/dto/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public record SignUp (
@NotBlank String name,
@Email @NotBlank String email,
@NotBlank String password,
@NotBlank String passwordConfirm,
@NotBlank String studentId,
@NotBlank String phoneNumber,
@NotBlank String tel,
@NotNull Position position,
@NotNull Department department,
@NotNull Integer cardinal
Expand All @@ -23,6 +24,7 @@ public record Response(
Integer id,
String name,
String studentId,
String tel,
Department department,
String email,
Integer cardinal,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/leets/weeth/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class User extends BaseEntity {

private String studentId;

private String phoneNumber;
private String tel;

@Enumerated(EnumType.STRING)
private Position position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public interface UserRepository extends JpaRepository<User, Long> {

Optional<User> findByEmail(String email);

boolean existsByEmail(String email);

boolean existsByStudentId(String studentId);

boolean existsByTel(String tel);

List<User> findAllByStatusOrderByName(Status status);

Optional<User> findByRefreshToken(String refreshToken);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/leets/weeth/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import leets.weeth.domain.user.mapper.UserMapper;
import leets.weeth.domain.user.repository.UserRepository;
import leets.weeth.global.common.error.exception.custom.BusinessLogicException;
import leets.weeth.global.common.error.exception.custom.EmailExistsException;
import leets.weeth.global.common.error.exception.custom.InvalidAccessException;
import leets.weeth.global.common.error.exception.custom.UserExistsException;
import leets.weeth.global.common.error.exception.custom.UserNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
Expand All @@ -30,10 +30,10 @@ public class UserService {
private final PasswordEncoder passwordEncoder;

public void signUp(UserDTO.SignUp requestDto) {
if (userRepository.findByEmail(requestDto.email()).isPresent())
throw new EmailExistsException();

// 수정: 아이디 이외 중복 처리
if(userRepository.existsByEmail(requestDto.email()) || // 이메일 중복
userRepository.existsByStudentId(requestDto.studentId()) || // 학번 중복
userRepository.existsByTel(requestDto.tel())) // 전화번호 중복
throw new UserExistsException();

User user = mapper.from(requestDto, passwordEncoder);
userRepository.save(user);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package leets.weeth.global.common.error.exception.custom;

import jakarta.persistence.EntityNotFoundException;

public class UserExistsException extends EntityNotFoundException {
public UserExistsException() {
super("이미 가입된 사용자입니다.");
}
}

0 comments on commit 65ba143

Please sign in to comment.