Skip to content

Commit

Permalink
refactor: Post user 관련 메서드명 author로 변경 및 필드, 메서드 정리 (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
bperhaps committed Jul 28, 2021
1 parent 300b7c8 commit fd7bb11
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 53 deletions.
Expand Up @@ -74,7 +74,7 @@ private Post createPost(PostRequestDto postRequestDto) {
.content(content)
.images(imageUrls)
.githubRepoUrl(githubRepoUrl)
.user(user)
.author(user)
.build();

post.addTags(tags);
Expand Down
Expand Up @@ -35,58 +35,58 @@ public class Post {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@Embedded
private Images images;

@Embedded
private PostContent content;

private String githubRepoUrl;

@Embedded
private Likes likes;

@Embedded
private Comments comments;

@Embedded
private PostTags postTags;

private String githubRepoUrl;

@CreatedDate
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updatedAt;

@Embedded
private PostTags postTags;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

protected Post() {
}

protected Post(
Long id,
User user,
Images images,
PostContent content,
String githubRepoUrl,
Likes likes,
Comments comments,
LocalDateTime createdAt,
LocalDateTime updatedAt,
PostTags postTags,
User user
String githubRepoUrl,
LocalDateTime createdAt,
LocalDateTime updatedAt
) {
this.id = id;
this.user = user;
this.images = images;
this.content = content;
this.githubRepoUrl = githubRepoUrl;
this.likes = likes;
this.content = content;
this.comments = comments;
this.postTags = postTags;
this.githubRepoUrl = githubRepoUrl;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.postTags = postTags;
this.user = user;

images.setMapping(this);
}
Expand Down Expand Up @@ -116,7 +116,6 @@ public List<String> getImageUrls() {
return images.getUrls();
}


public String getGithubRepoUrl() {
return githubRepoUrl;
}
Expand Down Expand Up @@ -173,24 +172,25 @@ public int hashCode() {
public static class Builder {

private Long id;
private User author;
private Images images = new Images(List.of());
private PostContent content;
private String githubRepoUrl;
private Likes likes = new Likes();
private Comments comments = new Comments();
private PostTags postTags = new PostTags();
private String githubRepoUrl;
private LocalDateTime createdAt = null;
private LocalDateTime updatedAt = null;
private PostTags postTags = new PostTags();
private User user;

private List<Tag> tags = new ArrayList<>();

public Builder id(Long id) {
this.id = id;
return this;
}

public Builder images(Images images) {
this.images = images;
public Builder author(User user) {
this.author = user;
return this;
}

Expand All @@ -203,11 +203,26 @@ public Builder images(List<String> imageUrls) {
return this;
}

public Builder images(Images images) {
this.images = images;
return this;
}

public Builder content(String content) {
this.content = new PostContent(content);
return this;
}

public Builder tags(Tag... tags) {
tags(List.of(tags));
return this;
}

public Builder tags(List<Tag> tags) {
this.tags = tags;
return this;
}

public Builder githubRepoUrl(String githubRepoUrl) {
this.githubRepoUrl = githubRepoUrl;
return this;
Expand All @@ -225,33 +240,18 @@ public Builder updatedAt(LocalDateTime updatedAt) {
return this;
}

public Builder tags(Tag... tags) {
tags(List.of(tags));
return this;
}

public Builder tags(List<Tag> tags) {
this.tags = tags;
return this;
}

public Builder user(User user) {
this.user = user;
return this;
}

public Post build() {
Post post = new Post(
id,
author,
images,
content,
githubRepoUrl,
likes,
comments,
createdAt,
updatedAt,
postTags,
user
githubRepoUrl,
createdAt,
updatedAt
);

post.addTags(tags);
Expand Down
Expand Up @@ -68,7 +68,7 @@ void addComment_ValidContent_Success() {
Post post = Post.builder()
.content("testContent")
.githubRepoUrl("https://github.com/bperhaps")
.user(savedTestUser)
.author(savedTestUser)
.build();
Post savedPost = postRepository.save(post);

Expand Down Expand Up @@ -100,7 +100,7 @@ void addComment_InvalidContent_ExceptionThrown(String content) {
Post post = Post.builder()
.content("testContent")
.githubRepoUrl("https://github.com/bperhaps")
.user(savedTestUser)
.author(savedTestUser)
.build();
Post savedPost = postRepository.save(post);

Expand Down
Expand Up @@ -9,8 +9,6 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import com.woowacourse.pickgit.authentication.domain.user.GuestUser;
import com.woowacourse.pickgit.authentication.domain.user.LoginUser;
import com.woowacourse.pickgit.common.factory.UserFactory;
import com.woowacourse.pickgit.exception.authentication.UnauthorizedException;
import com.woowacourse.pickgit.exception.user.UserNotFoundException;
Expand Down Expand Up @@ -79,7 +77,7 @@ void readHomeFeed_getMainHomeFeed_success() {
private Post createPostOfId(long id) {
return Post.builder()
.id(id)
.user(UserFactory.user())
.author(UserFactory.user())
.content("test")
.build();
}
Expand Down
Expand Up @@ -175,7 +175,7 @@ void addComment_ValidContent_Success() {
User user = UserFactory.user(1L, "testUser1");
Post post = Post.builder()
.id(1L)
.user(user)
.author(user)
.build();

given(postRepository.findById(anyLong()))
Expand Down
Expand Up @@ -48,7 +48,7 @@ void save_SavedPost_Success() {

Post post = Post.builder()
.content("test")
.user(savedTestUser)
.author(savedTestUser)
.build();

// when
Expand All @@ -72,7 +72,7 @@ void save_SavedPostWithCreatedDate_Success() {

Post post = Post.builder()
.content("test")
.user(savedTestUser)
.author(savedTestUser)
.build();

// when
Expand All @@ -93,7 +93,7 @@ void save_WhenSavingPost_TagSavedTogether() {
Post post = Post.builder()
.content("testContent")
.githubRepoUrl("https://github.com/bperhaps")
.user(savedTestUser)
.author(savedTestUser)
.build();
Post savedPost = postRepository.save(post);

Expand Down Expand Up @@ -140,7 +140,7 @@ void addComment_WhenSavingPost_CommentSavedTogether() {
Post post = Post.builder()
.content("testContent")
.githubRepoUrl("https://github.com/bperhaps")
.user(savedTestUser)
.author(savedTestUser)
.build();

// when
Expand Down

0 comments on commit fd7bb11

Please sign in to comment.