Skip to content

Commit a26060e

Browse files
committed
♻️ refactor: 예외 메시지 수정, @transactional 명시
1 parent 2f5df09 commit a26060e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

backend/src/main/java/io/f1/backend/domain/user/app/UserService.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public SignupResponseDto signup(HttpSession session, SignupRequestDto signupRequ
2424
SessionUser sessionUser = extractSessionUser(session);
2525

2626
String nickname = signupRequest.nickname();
27-
validateNickname(nickname);
28-
validateDuplicateNickname(nickname);
27+
validateNicknameFormat(nickname);
28+
validateNicknameDuplicate(nickname);
2929

3030
User user = updateUserNickname(sessionUser.getUserId(), nickname);
3131
updateSessionAfterSignup(session, user);
@@ -37,12 +37,12 @@ public SignupResponseDto signup(HttpSession session, SignupRequestDto signupRequ
3737
private SessionUser extractSessionUser(HttpSession session) {
3838
SessionUser sessionUser = (SessionUser) session.getAttribute("OAuthUser");
3939
if (sessionUser == null) {
40-
throw new RuntimeException("세션에 OAuth 정보 없음");
40+
throw new RuntimeException("E401001: 로그인이 필요합니다.");
4141
}
4242
return sessionUser;
4343
}
4444

45-
private void validateNickname(String nickname) {
45+
private void validateNicknameFormat(String nickname) {
4646
if (nickname == null || nickname.trim().isEmpty()) {
4747
throw new RuntimeException("E400002: 닉네임은 필수 입력입니다.");
4848
}
@@ -54,15 +54,18 @@ private void validateNickname(String nickname) {
5454
}
5555
}
5656

57-
private void validateDuplicateNickname(String nickname) {
57+
@Transactional(readOnly = true)
58+
public void validateNicknameDuplicate(String nickname) {
5859
if (userRepository.existsUserByNickname(nickname)) {
59-
throw new RuntimeException("닉네임 중복");
60+
throw new RuntimeException("E409001: 중복된 닉네임입니다.");
6061
}
6162
}
6263

63-
private User updateUserNickname(Long userId, String nickname) {
64+
@Transactional
65+
public User updateUserNickname(Long userId, String nickname) {
6466
User user =
65-
userRepository.findById(userId).orElseThrow(() -> new RuntimeException("사용자 없음"));
67+
userRepository.findById(userId)
68+
.orElseThrow(() -> new RuntimeException("E404001: 존재하지 않는 회원입니다."));
6669
user.updateNickname(nickname);
6770

6871
return userRepository.save(user);

0 commit comments

Comments
 (0)