Skip to content

Commit

Permalink
refactor : User desc 필드 추가 (#135)
Browse files Browse the repository at this point in the history
* user desc 추가 및 user info 수정 할 때 desc도 추가

* user 정보 조회할 때 user desc정보 추가

* 포메터 적용

* 포메터 찐 적용

* refactor : description 통일 피드백 반영

* description NotNull 명시

* notNull 및 nullable=false 어노테이션 추가

* .DS_store 삭제
  • Loading branch information
sh0723 authored Nov 5, 2024
1 parent 506e516 commit b525827
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ out/
/nbdist/
/.nb-gradle/

.DS_Store

### VS Code ###
.vscode/

src/main/resources/*.yml
src/main/resources/*.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class UserInfoResponse {
private String nickname;
private String profileImage;
private String bjNickname;
private String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand Down

0 comments on commit b525827

Please sign in to comment.