Skip to content
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

[Main]: #152 리펙토링 #153

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public void createCommentLike(Long userId, Long commentId) {
throw new ConflictException(DUPLICATE_COMMENT_LIKE);
}

commentLikeModifier.save
(CommentLike.builder()
.user(user)
.comment(comment)
.build());
commentLikeModifier.save(CommentLike.of(user, comment));
}

public void deleteCommentLike(Long userId, Long commentId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ public CommentCreateResponseDto createComment(Long userId, Long postId, String c
throw new NotAllowedException(TOO_LONG_COMMENT_NOT_ALLOWED);
}

Comment newComment = commentModifier.save
(Comment.builder()
.post(post)
.user(writer)
.content(content)
.build());
Comment newComment = commentModifier.save(Comment.createComment(writer, post, content));

pushNotificationService.sendCommentNotification(postId, newComment);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public void createPostLike(Long userId, Long postId) {
}

postLikeAppender.save(
PostLike.builder()
.user(user)
.post(post)
.build()
PostLike.createPostLike(
user,
post
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,19 @@ public PostCreateResponseDto createPost(Long userId, List<MultipartFile> images,
throw new NotAllowedException(TOO_MANY_IMAGES_NOT_ALLOWED);
}

Post newPost = postAppender.save
(Post.builder()
.user(writer)
.postType(postType)
.title(requestDto.getTitle())
.content(requestDto.getContent())
.build());
Post newPost = postAppender.save(Post.createPost(writer, postType, requestDto.getTitle(), requestDto.getContent()));

List<String> imageUrls = null;
if(images != null && !images.isEmpty()) {
imageUrls = awsS3Service.uploadImages(images);
for(int i=0; i<images.size(); i++) {
postImageAppender.save(PostImage.builder()
.post(newPost)
.image_url(imageUrls.get(i))
.isRepresentative(i == 0)
.build());
postImageAppender.save(
PostImage.createPostImage(
newPost,
imageUrls.get(i),
i == 0
)
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public void createReplyLike(Long userId, Long replyId) {
throw new ConflictException(DUPLICATE_REPLY_LIKE);
}
replyLikeModifier.save(
ReplyLike.builder()
.user(user)
.reply(reply)
.build()
ReplyLike.createReplyLike(
user,
reply
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public ReplyCreateResponseDto createReply(Long userId, Long commentId, String co
Comment comment = commentReader.findById(commentId);

Reply newReply = replyModifier.save(
Reply.builder()
.user(user)
.comment(comment)
.content(content)
.build()
Reply.createReply(
user,
comment,
content
)
);

return ReplyCreateResponseDto.of(newReply.getId(), newReply.getUser().getProfile(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ public class Comment extends BaseEntity {
@ColumnDefault("0")
@Builder.Default()
private int reported = 0;

public static Comment createComment(User user, Post post, String content) {
return Comment.builder()
.user(user)
.post(post)
.content(content)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ public class CommentLike extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id")
private Comment comment;

public static CommentLike of(User user, Comment comment) {
return CommentLike.builder()
.user(user)
.comment(comment)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ public class Reply extends BaseEntity {
@ColumnDefault("0")
@Builder.Default()
private int reported = 0;

public static Reply createReply(User user, Comment comment, String content) {
return Reply.builder()
.user(user)
.comment(comment)
.content(content)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ public class ReplyLike {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "reply_id")
private Reply reply;

public static ReplyLike createReplyLike(User user, Reply reply) {
return ReplyLike.builder()
.user(user)
.reply(reply)
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ public class Post extends BaseEntity {
private String content;
@Enumerated(EnumType.STRING)
private PostType postType;

public static Post createPost(User user, PostType postType, String title, String content) {
return Post.builder()
.user(user)
.postType(postType)
.title(title)
.content(content)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ public class PostImage extends BaseEntity {
private String image_url;

private boolean isRepresentative;

public static PostImage createPostImage(Post post, String image_url, boolean isRepresentative) {
return PostImage.builder()
.post(post)
.image_url(image_url)
.isRepresentative(isRepresentative)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,12 @@ public class PostLike extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id")
private Post post;

public static PostLike createPostLike(User user, Post post) {
return PostLike.builder()
.user(user)
.post(post)
.build();
}
}