diff --git a/.gitignore b/.gitignore index 529df13e..ef15cf26 100644 --- a/.gitignore +++ b/.gitignore @@ -33,7 +33,9 @@ out/ /nbdist/ /.nb-gradle/ +.DS_Store + ### VS Code ### .vscode/ -src/main/resources/*.yml +src/main/resources/*.yml \ No newline at end of file diff --git a/src/main/java/com/gamzabat/algohub/feature/user/domain/User.java b/src/main/java/com/gamzabat/algohub/feature/user/domain/User.java index 4f1a2792..6abae6a2 100644 --- a/src/main/java/com/gamzabat/algohub/feature/user/domain/User.java +++ b/src/main/java/com/gamzabat/algohub/feature/user/domain/User.java @@ -7,12 +7,14 @@ import com.gamzabat.algohub.enums.Role; +import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -32,6 +34,9 @@ public class User { private String nickname; private String bjNickname; private String profileImage; + @Column(nullable = false) + @NotNull + private String description = ""; private LocalDateTime deletedAt; @@ -49,6 +54,10 @@ public User(String email, String password, String nickname, String bjNickname, S this.deletedAt = null; } + public void editDescription(String description) { + this.description = description; + } + public void editNickname(String nickname) { this.nickname = nickname; } diff --git a/src/main/java/com/gamzabat/algohub/feature/user/dto/UpdateUserRequest.java b/src/main/java/com/gamzabat/algohub/feature/user/dto/UpdateUserRequest.java index 5175221f..9590a491 100644 --- a/src/main/java/com/gamzabat/algohub/feature/user/dto/UpdateUserRequest.java +++ b/src/main/java/com/gamzabat/algohub/feature/user/dto/UpdateUserRequest.java @@ -6,9 +6,11 @@ public class UpdateUserRequest { private final String nickname; private final String bjNickname; + private final String description; - public UpdateUserRequest(String nickname, String bjNickname) { + public UpdateUserRequest(String nickname, String bjNickname, String description) { this.nickname = nickname; this.bjNickname = bjNickname; + this.description = description; } } diff --git a/src/main/java/com/gamzabat/algohub/feature/user/dto/UserInfoResponse.java b/src/main/java/com/gamzabat/algohub/feature/user/dto/UserInfoResponse.java index f4f80803..96df9998 100644 --- a/src/main/java/com/gamzabat/algohub/feature/user/dto/UserInfoResponse.java +++ b/src/main/java/com/gamzabat/algohub/feature/user/dto/UserInfoResponse.java @@ -12,4 +12,5 @@ public class UserInfoResponse { private String nickname; private String profileImage; private String bjNickname; + private String description; } diff --git a/src/main/java/com/gamzabat/algohub/feature/user/service/UserService.java b/src/main/java/com/gamzabat/algohub/feature/user/service/UserService.java index 102aa70b..b327d1ac 100644 --- a/src/main/java/com/gamzabat/algohub/feature/user/service/UserService.java +++ b/src/main/java/com/gamzabat/algohub/feature/user/service/UserService.java @@ -90,7 +90,8 @@ public SignInResponse signIn(SignInRequest request) { @Transactional(readOnly = true) public UserInfoResponse userInfo(User user) { - return new UserInfoResponse(user.getEmail(), user.getNickname(), user.getProfileImage(), user.getBjNickname()); + return new UserInfoResponse(user.getEmail(), user.getNickname(), user.getProfileImage(), user.getBjNickname(), + user.getDescription()); } @Transactional @@ -108,6 +109,9 @@ public void userUpdate(User user, UpdateUserRequest updateUserRequest, Multipart if (updateUserRequest.getBjNickname() != null && !updateUserRequest.getBjNickname().isEmpty()) { user.editBjNickname(updateUserRequest.getBjNickname()); } + if (updateUserRequest.getDescription() != null && !updateUserRequest.getDescription().isEmpty()) { + user.editDescription(updateUserRequest.getDescription()); + } userRepository.save(user); } diff --git a/src/test/java/com/gamzabat/algohub/feature/user/controller/UserControllerTest.java b/src/test/java/com/gamzabat/algohub/feature/user/controller/UserControllerTest.java index e269837a..de745036 100644 --- a/src/test/java/com/gamzabat/algohub/feature/user/controller/UserControllerTest.java +++ b/src/test/java/com/gamzabat/algohub/feature/user/controller/UserControllerTest.java @@ -249,7 +249,7 @@ void signInFailed_3() throws Exception { @DisplayName("회원 정보 수정 성공") void updateUser() throws Exception { // given - UpdateUserRequest request = new UpdateUserRequest("newNickname", "newBjNickname"); + UpdateUserRequest request = new UpdateUserRequest("newNickname", "newBjNickname", "I am Superman"); MockMultipartFile requestPart = new MockMultipartFile("request", "", "application/json", objectMapper.writeValueAsString(request).getBytes()); MockMultipartFile profileImage = new MockMultipartFile("profileImage", "profile.jpg", "image/jpeg", @@ -274,7 +274,7 @@ void updateUser() throws Exception { @DisplayName("회원 정보 조회 성공") void getUserInfo() throws Exception { // given - UserInfoResponse response = new UserInfoResponse("email", "nickname", "profileImage", "bjNickname"); + UserInfoResponse response = new UserInfoResponse("email", "nickname", "profileImage", "bjNickname", ""); when(userService.userInfo(user)).thenReturn(response); // when, then mockMvc.perform(get("/api/user") @@ -283,7 +283,8 @@ void getUserInfo() throws Exception { .andExpect(jsonPath("$.email").value("email")) .andExpect(jsonPath("$.nickname").value("nickname")) .andExpect(jsonPath("$.profileImage").value("profileImage")) - .andExpect(jsonPath("$.bjNickname").value("bjNickname")); + .andExpect(jsonPath("$.bjNickname").value("bjNickname")) + .andExpect(jsonPath("$.description").value("")); verify(userService, times(1)).userInfo(any(User.class)); } diff --git a/src/test/java/com/gamzabat/algohub/feature/user/service/UserServiceTest.java b/src/test/java/com/gamzabat/algohub/feature/user/service/UserServiceTest.java index d3ac67d1..6e6fd679 100644 --- a/src/test/java/com/gamzabat/algohub/feature/user/service/UserServiceTest.java +++ b/src/test/java/com/gamzabat/algohub/feature/user/service/UserServiceTest.java @@ -82,7 +82,6 @@ class UserServiceTest { private final String encoded = "encoded"; private final String imageUrl = "imageUrl"; private final String bjNickname = "bjNickname"; - private User user; @BeforeEach @@ -115,6 +114,7 @@ void register() { assertThat(user.getProfileImage()).isEqualTo(imageUrl); assertThat(user.getRole()).isEqualTo(Role.USER); assertThat(user.getBjNickname()).isEqualTo(bjNickname); + assertThat(user.getDescription()).isEqualTo(""); } @Test @@ -190,13 +190,14 @@ void userInfo() { assertThat(response.getNickname()).isEqualTo(nickname); assertThat(response.getProfileImage()).isEqualTo(imageUrl); assertThat(response.getBjNickname()).isEqualTo(bjNickname); + assertThat(response.getDescription()).isEqualTo(""); } @Test @DisplayName("회원 정보 수정 성공") void userUpdate() { // given - UpdateUserRequest request = new UpdateUserRequest("newNickname", "newBjNickname"); + UpdateUserRequest request = new UpdateUserRequest("newNickname", "newBjNickname", "I am Batman"); MockMultipartFile newProfileImage = new MockMultipartFile("newImage", "image.jpg", "image/jpeg", "test".getBytes()); when(imageService.saveImage(newProfileImage)).thenReturn("newProfileImageUrl"); @@ -207,6 +208,7 @@ void userUpdate() { assertThat(user.getNickname()).isEqualTo("newNickname"); assertThat(user.getBjNickname()).isEqualTo("newBjNickname"); assertThat(user.getProfileImage()).isEqualTo("newProfileImageUrl"); + assertThat(user.getDescription()).isEqualTo("I am Batman"); } @Test