Skip to content

Commit

Permalink
BE: [fix] Merge Admin to exam: 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
JongbeomLee623 committed Nov 2, 2024
2 parents 9d23ec8 + 09e2d1c commit 1d36f40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ public enum BaseResponseCode {
UNSUPPORTED_TOKEN("GL008", HttpStatus.BAD_REQUEST, "지원하지 않는 토큰입니다."),
TOKEN_ERROR("GL009", HttpStatus.BAD_REQUEST, "토큰에 문제가 발생했습니다."),
MALFORMED_TOKEN("GL010", HttpStatus.BAD_REQUEST, "토큰의 구조가 잘못되었습니다."),

UNAUTHORIZED("GL011", HttpStatus.UNAUTHORIZED, "로그인이 필요합니다."),
INVALID_STATUS("GL012", HttpStatus.BAD_REQUEST, "유효하지 않은 상태 값입니다."),
INVALID_INPUT("GL013", HttpStatus.BAD_REQUEST, "입력이 잘못되었습니다."),

// User Errors
ALREADY_EXIST_USER("U0001", HttpStatus.CONFLICT, "이미 존재하는 사용자입니다"),
WRONG_PASSWORD("U0002", HttpStatus.BAD_REQUEST, "비밀번호가 틀렸습니다."),
NOT_FOUND_USER("U0003", HttpStatus.NOT_FOUND, "사용자를 찾을 수 없습니다."),
NOT_EQUAL_PASSWORD("U0004", HttpStatus.BAD_REQUEST, "비밀번호가 일치하지 않습니다."),
WEAK_PASSWORD("U0005", HttpStatus.BAD_REQUEST, "비밀번호는 8자 이상이어야 합니다."),
INVALID_EMAIL_FORMAT("U0006", HttpStatus.BAD_REQUEST, "이메일 형식이 잘못되었습니다."),

// Exam Errors
NOT_FOUND_EXAM("E0001", HttpStatus.NOT_FOUND, "시험을 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AdminService {
Expand All @@ -19,15 +20,31 @@ public class AdminService {
@Autowired
private PasswordEncoder passwordEncoder;

// 회원가입 메서드
@Transactional
public Admin registerAdmin(AdminSignupRequestDTO adminSignupRequestDTO) {
if (adminSignupRequestDTO.getAdminEmail() == null ||
adminSignupRequestDTO.getPassword() == null ||
adminSignupRequestDTO.getPasswordConfirm() == null) {
throw new BaseException(BaseResponseCode.INVALID_INPUT); // 잘못된 입력 예외 처리
}

if (adminRepository.findByAdminEmail(adminSignupRequestDTO.getAdminEmail()).isPresent()) {
throw new BaseException(BaseResponseCode.ALREADY_EXIST_USER); // 이메일 중복 예외 처리
}

if (!adminSignupRequestDTO.getPassword().equals(adminSignupRequestDTO.getPasswordConfirm())) {
throw new BaseException(BaseResponseCode.NOT_EQUAL_PASSWORD); // 비밀번호 불일치 예외 처리
}

if (adminSignupRequestDTO.getPassword().length() < 8) {
throw new BaseException(BaseResponseCode.WEAK_PASSWORD); // 비밀번호 강도 예외 처리
}

String emailPattern = "^[A-Za-z0-9+_.-]+@(.+)$";
if (!adminSignupRequestDTO.getAdminEmail().matches(emailPattern)) {
throw new BaseException(BaseResponseCode.INVALID_EMAIL_FORMAT); // 잘못된 이메일 형식 예외 처리
}

Admin admin = new Admin();
admin.setAdminEmail(adminSignupRequestDTO.getAdminEmail());
admin.setPassword(passwordEncoder.encode(adminSignupRequestDTO.getPassword()));
Expand Down

0 comments on commit 1d36f40

Please sign in to comment.