Skip to content

Commit

Permalink
#82 fix : 이메일 중복시 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
rivkode committed Apr 26, 2024
1 parent 6d67e53 commit 69e0c0c
Showing 1 changed file with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import com.seoultech.synergybe.domain.common.idgenerator.IdGenerator;
import com.seoultech.synergybe.domain.common.idgenerator.IdPrefix;
import com.seoultech.synergybe.domain.common.paging.ListResponse;
import com.seoultech.synergybe.domain.follow.repository.FollowRepository;
import com.seoultech.synergybe.domain.follow.service.FollowService;
import com.seoultech.synergybe.domain.user.dto.response.*;
import com.seoultech.synergybe.domain.user.exception.UserBadRequestException;
import com.seoultech.synergybe.domain.user.exception.UserNotFoundException;
import com.seoultech.synergybe.domain.user.repository.UserRepository;
import com.seoultech.synergybe.domain.user.User;
import com.seoultech.synergybe.domain.user.vo.UserEmail;
import com.seoultech.synergybe.system.exception.ErrorCode;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Predicate;
Expand All @@ -39,18 +40,15 @@ public class UserService {
private final CustomPasswordEncoder passwordEncoder;
private final IdGenerator idGenerator;

public CheckDuplicateVolunteerEmailResponse checkDuplicateVolunteerEmailResponse(String email) {
boolean isDuplicated = userRepository.existsByEmail(email);
return CheckDuplicateVolunteerEmailResponse.from(isDuplicated);
}

@Transactional
public String createUser(
String email,
String password,
String name,
String major
) {
checkEmailDuplicate(email);

String userId = idGenerator.generateId(IdPrefix.USER);
User user = User.builder()
.id(userId)
Expand All @@ -65,6 +63,14 @@ public String createUser(
return user.getId();
}

private void checkEmailDuplicate(String email) {
UserEmail userEmail = new UserEmail(email);
boolean isEmailDuplicated = userRepository.existsByEmail(userEmail);
if (isEmailDuplicated) {
throw new UserBadRequestException(ErrorCode.BAD_REQUEST, "이미 존재하는 이메일입니다.");
}
}

public User getUser(String userId) {
return userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("존재하지 않는 유저입니다."));
}
Expand Down Expand Up @@ -175,21 +181,5 @@ private List<String> extractIds(String response) {
throw new RuntimeException(e);
}
}

// public ListResponse<String> getFollowerIds(String userId) {
// List<String> getFollowerIdList = followService.getFollowerIdList(userId);
//
// ListResponse<String> getUserIdListResponses = new ListResponse(getFollowerIdList);
//
// return getUserIdListResponses;
// }
//
// public ListResponse<String> getFollowingIds(String userId) {
// List<String> getFollowingIdList = followService.getFollowingIdList(userId);
//
// ListResponse<String> getUserIdListResponses = new ListResponse(getFollowingIdList);
//
// return getUserIdListResponses;
// }
}

0 comments on commit 69e0c0c

Please sign in to comment.