Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum ExceptionType {
// User
USER_NOT_FOUND(NOT_FOUND, "U001","사용자가 존재하지 않습니다"),
SCHOOL_EMAIL_ALREADY_REGISTERED(FORBIDDEN, "U002", "학교 이메일이 등록된 상태입니다"),
DUPLICATED_SCHOOL_EMAIL(CONFLICT, "U003", "이미 사용중인 이메일입니다"),
DUPLICATED_SCHOOL_EMAIL(CONFLICT, "U003", "이미 사용중인 학교 이메일입니다"),
DEPARTMENT_NOT_FOUND(BAD_REQUEST, "U004", "존재하지 않는 학과 명입니다"),
USER_WITHDRAWN(FORBIDDEN, "U005", "탈퇴한 사용자입니다."),
DUPLICATED_STUDENT_ID(CONFLICT, "U006", "이미 사용중인 학번입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gpt.geumpumtabackend.global.oauth.user.OAuth2Provider;
import com.gpt.geumpumtabackend.user.domain.User;
import jakarta.validation.constraints.Pattern;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
Expand All @@ -19,4 +20,8 @@ public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByProviderAndProviderIdAndDeletedAtIsNull(OAuth2Provider provider, String providerId);

Optional<User> findByProviderAndProviderId(OAuth2Provider provider, String providerId);

boolean existsByStudentId(String studentId);

boolean existsBySchoolEmail(String schoolEmail);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public void generateRandomNickname(User user){
user.setInitialNickname(nickname);
}

// TODO : 데이터 중복 검증 추가하기
@Transactional
public TokenResponse completeRegistration(CompleteRegistrationRequest request, Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(()->new BusinessException(ExceptionType.USER_NOT_FOUND));
validateDuplication(request);
user.completeRegistration(request);
generateRandomNickname(user);

Expand All @@ -69,6 +69,16 @@ public TokenResponse completeRegistration(CompleteRegistrationRequest request, L
return TokenResponse.to(token);
}

private void validateDuplication(CompleteRegistrationRequest request) {
if(userRepository.existsBySchoolEmail((request.email()))){
throw new BusinessException(ExceptionType.DUPLICATED_SCHOOL_EMAIL);
}

if(userRepository.existsByStudentId(request.studentId())){
throw new BusinessException(ExceptionType.DUPLICATED_STUDENT_ID);
}
}

public UserProfileResponse getUserProfile(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(()->new BusinessException(ExceptionType.USER_NOT_FOUND));
Expand Down
Loading