-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from Kusitms-POPTATO-DEV/feat/change-mypage-name
Feat#40: 마이페이지 이름 변경
- Loading branch information
Showing
10 changed files
with
222 additions
and
36 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/server/poptato/auth/exception/AuthException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package server.poptato.auth.exception; | ||
|
||
import lombok.Getter; | ||
import server.poptato.global.response.status.ResponseStatus; | ||
|
||
@Getter | ||
public class AuthException extends RuntimeException{ | ||
private final ResponseStatus exceptionStatus; | ||
|
||
public AuthException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/server/poptato/auth/exception/errorcode/AuthExceptionErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package server.poptato.auth.exception.errorcode; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import server.poptato.global.response.status.ResponseStatus; | ||
|
||
@RequiredArgsConstructor | ||
public enum AuthExceptionErrorCode implements ResponseStatus { | ||
|
||
/** | ||
* 6000: Auth 도메인 오류 | ||
*/ | ||
|
||
TOKEN_NOT_EXIST(6000, HttpStatus.BAD_REQUEST.value(), "토큰 값이 필요합니다."), | ||
TOKEN_TIME_EXPIRED(6001, HttpStatus.BAD_REQUEST.value(), "토큰이 만료되었습니다"), | ||
INVALID_TOKEN(6002, HttpStatus.BAD_REQUEST.value(), "토큰이 유효하지 않습니다"); | ||
|
||
private final int code; | ||
private final int status; | ||
private final String message; | ||
|
||
|
||
@Override | ||
public int getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/server/poptato/auth/exception/handler/AuthExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package server.poptato.auth.exception.handler; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import server.poptato.auth.exception.AuthException; | ||
import server.poptato.global.response.BaseErrorResponse; | ||
|
||
@Slf4j | ||
@Order(0) | ||
@RestControllerAdvice | ||
public class AuthExceptionHandler { | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(AuthException.class) | ||
public BaseErrorResponse handleAuthException(AuthException e) { | ||
log.error("[UserException: handle_UserException 호출]", e); | ||
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/server/poptato/user/api/request/UserChangeNameRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package server.poptato.user.api.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class UserChangeNameRequestDto { | ||
@NotBlank(message = "이름은 빈 값일 수 없습니다.") | ||
String newName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/test/java/server/poptato/user/application/UserServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package server.poptato.user.application; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import server.poptato.user.application.service.UserService; | ||
import server.poptato.user.domain.entity.User; | ||
import server.poptato.user.domain.repository.UserRepository; | ||
import server.poptato.user.exception.UserException; | ||
import server.poptato.user.exception.errorcode.UserExceptionErrorCode; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
@SpringBootTest | ||
class UserServiceTest { | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Test | ||
@DisplayName("사용자 이름 변경 성공 테스트") | ||
@Transactional | ||
void updateUserName_ShouldChangeUserName() { | ||
// given | ||
Long userId = 1L; | ||
String newName = "New Name"; | ||
|
||
// when | ||
userService.updateUserName(userId, newName); | ||
|
||
// then | ||
User updatedUser = userRepository.findById(userId).orElseThrow(); | ||
assertThat(updatedUser.getName()).isEqualTo(newName); | ||
} | ||
|
||
@Test | ||
@DisplayName("존재하지 않는 사용자일 경우 예외 발생 테스트") | ||
@Transactional | ||
void updateUserName_ShouldThrowException_WhenUserNotFound() { | ||
// given | ||
Long nonExistentUserId = 999L; // 존재하지 않는 유저 ID | ||
String newName = "New Name"; | ||
|
||
// when & then | ||
UserException exception = assertThrows(UserException.class, () -> { | ||
userService.updateUserName(nonExistentUserId, newName); | ||
}); | ||
|
||
assertThat(exception.getMessage()).isEqualTo(UserExceptionErrorCode.USER_NOT_EXIST.getMessage()); | ||
} | ||
} | ||
|