-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat#50: user 프로필 조회 기능 구현 #51
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
src/main/java/server/poptato/user/application/response/UserResponseDto.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,13 @@ | ||
package server.poptato.user.application.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class UserResponseDto { | ||
private String name; | ||
private String email; | ||
} |
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import org.springframework.transaction.annotation.Transactional; | ||
import server.poptato.auth.application.service.JwtService; | ||
import server.poptato.todo.domain.repository.TodoRepository; | ||
import server.poptato.user.application.response.UserResponseDto; | ||
import server.poptato.user.domain.entity.User; | ||
import server.poptato.user.domain.repository.UserRepository; | ||
import server.poptato.user.exception.UserException; | ||
|
@@ -35,18 +36,18 @@ public void deleteUser(Long userId) { | |
entityManager.flush(); | ||
} | ||
@Transactional | ||
@CacheEvict(value = "users", key = "#kakaoId") | ||
public Optional<User> findUserByKakaoId(String kakaoId) { | ||
entityManager.clear(); // 영속성 컨텍스트 초기화 | ||
return userRepository.findByKakaoId(kakaoId); | ||
} | ||
@Transactional | ||
public void updateUserName(Long userId, String newName) { | ||
// 사용자 조회 | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new UserException(UserExceptionErrorCode.USER_NOT_EXIST)); | ||
|
||
// name 업데이트 | ||
user.changeName(newName); | ||
} | ||
@Transactional(readOnly = true) | ||
public UserResponseDto getUserNameAndEmailById(Long userId) { | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new UserException(UserExceptionErrorCode.USER_NOT_EXIST)); | ||
|
||
return new UserResponseDto(user.getName(), user.getEmail()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Response는 만들어놓은 Builder를 사용해도 될 것 같아요! |
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
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.response.UserResponseDto; | ||
import server.poptato.user.application.service.UserService; | ||
import server.poptato.user.domain.entity.User; | ||
import server.poptato.user.domain.repository.UserRepository; | ||
|
@@ -54,5 +55,29 @@ void updateUserName_ShouldThrowException_WhenUserNotFound() { | |
|
||
assertThat(exception.getMessage()).isEqualTo(UserExceptionErrorCode.USER_NOT_EXIST.getMessage()); | ||
} | ||
@Test | ||
@DisplayName("getUserNameAndEmailById 메서드는 유효한 userId가 주어졌을 때 사용자 이름과 이메일을 반환한다") | ||
public void shouldReturnUserNameAndEmail_WhenUserIdIsValid() { | ||
// Given | ||
Long userId = 1L; | ||
|
||
// When | ||
UserResponseDto responseDto = userService.getUserNameAndEmailById(userId); | ||
|
||
// Then | ||
assertThat(responseDto.getName()).isEqualTo("Poptato"); | ||
assertThat(responseDto.getEmail()).isEqualTo("[email protected]"); | ||
} | ||
|
||
@Test | ||
@DisplayName("getUserNameAndEmailById 메서드는 유효하지 않은 userId가 주어졌을 때 UserException을 던진다") | ||
public void shouldThrowUserException_WhenUserIdIsInvalid() { | ||
// Given | ||
Long invalidUserId = 2L; | ||
|
||
// When & Then | ||
org.junit.jupiter.api.Assertions.assertThrows(UserException.class, | ||
() -> userService.getUserNameAndEmailById(invalidUserId)); | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User user = userRepository.findById(userId)
.orElseThrow(() -> new UserException(UserExceptionErrorCode.USER_NOT_EXIST));
이 부분이 서비스 메서드마다 있는데, 하나의 메소드로 리팩토링해보는 건 어떨까요?