Skip to content

Commit

Permalink
#27 Refactor : 빌더 패턴 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaeYoon committed Jul 19, 2023
1 parent a7c6ae9 commit 71afcc4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public CommentRequestDto(Long userId, Long postId, String content) {
this.content = content;
}

public CommentRequestDto(String content) {
this.content = content;
}

public Comment toEntity() {
return Comment.builder()
.user(user)
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/kr/org/booklog/domain/post/dto/PostRequestDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ public PostRequestDto(Long userId, String postTitle, String bookTitle, String bo
this.content = content;
}

public PostRequestDto(String postTitle, String bookTitle, String bookWriter,
LocalDate readStart, LocalDate readEnd, LocalDate postAt,
Integer rating, String content) {
this.postTitle = postTitle;
this.bookTitle = bookTitle;
this.bookWriter = bookWriter;
this.readStart = readStart;
this.readEnd = readEnd;
this.postAt = postAt;
this.rating = rating;
this.content = content;
}

public Post toEntity() {
return Post.builder()
.user(user)
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/kr/org/booklog/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;

@Getter
@Setter
@NoArgsConstructor
@Entity
public class User extends BaseTimeEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class CommentServiceTest {
Long commentId = commentService.save(new CommentRequestDto(userId, postId, "댓글 수정 테스트의 댓글"));

// when
commentService.update(commentId, new CommentRequestDto("댓글이 수정되었습니다!"));
CommentRequestDto dto = CommentRequestDto.builder().content("댓글이 수정되었습니다!").build();
commentService.update(commentId, dto);

// then
assertThat(commentRepository.findById(commentId).get().getContent()).isEqualTo("댓글이 수정되었습니다!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ class PostServiceTest {
postRepository.save(post);

//when
Long updatedId = postService.update(post.getId(), new PostRequestDto("인간실격을 읽고...", "테스트", "zzyoon",
LocalDate.of(2023, 5, 14), LocalDate.of(2023, 6, 14), LocalDate.of(2023, 6, 14),
1, "감상평 테스트"));
PostRequestDto dto = PostRequestDto.builder()
.postTitle("인간실격을 읽고...")
.bookTitle("테스트")
.bookWriter("zzyoon")
.readStart(LocalDate.of(2023, 5, 14))
.readEnd(LocalDate.of(2023, 6, 14))
.postAt(LocalDate.of(2023, 6, 14))
.rating(1)
.content("감상평 테스트")
.build();
Long updatedId = postService.update(post.getId(), dto);

//then
assertThat(postRepository.findById(updatedId).get().getPostTitle()).isEqualTo("인간실격을 읽고...");
Expand Down

0 comments on commit 71afcc4

Please sign in to comment.