-
Notifications
You must be signed in to change notification settings - Fork 0
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
[feat] #31 repost 기능 구현 및 코드 통합 #31
Merged
The head ref may contain hidden characters: "feat/#27/repost-\uAE30\uB2A5"
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a7236fd
feat: repost 관련 비즈니스 로직 구현
hyxklee 8021d84
feat: 이미 리포스트 한 글에 대한 예외 구현
hyxklee 0683ac1
feat: 리포스트 엔티티 구현
hyxklee d1b487a
feat: 리포스트 저장소 구현
hyxklee 6bc2d26
feat: 포스트 타입 구분을 위한 enum 구현
hyxklee 7944bce
feat: 리포스트 양방향 매핑 추가
hyxklee 57f1c9d
refactor: enum 명 변경으로 인한 수정
hyxklee 286b2b8
Merge branch 'refs/heads/main' into feat/#27/repost-기능
hyxklee 67e3616
refactor: 사용하지 않는 dto 삭제
hyxklee 3f91bba
refactor: 리포스트 관련 정보 추가
hyxklee 5e3f771
refactor: 추가 정보 및 객체 생성 책임 이전
hyxklee 9675973
feat: post 관련 dto를 생성하는 커스텀 매퍼 클래스 생성
hyxklee ddd32f2
refactor: 요구사항에 맞는 API로 수정
hyxklee bda584a
refactor: 요구사항에 맞는 API로 수정
hyxklee 15525c0
refactor: repost 관련 로직 수정
hyxklee 6cf2a04
feat: 응답 상수 메시지 추가
hyxklee ec472e6
refactor: replyTo 항목 주석처리
hyxklee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.leets.X.domain.post.domain; | ||
|
||
import com.leets.X.domain.user.domain.User; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Builder | ||
@Getter | ||
public class Repost { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "repost_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "post_id") | ||
private Post post; | ||
|
||
public static Repost of(User user, Post post) { | ||
return Repost.builder() | ||
.user(user) | ||
.post(post) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.leets.X.domain.post.domain.enums; | ||
|
||
public enum Type { | ||
POST, REPOST | ||
} |
87 changes: 87 additions & 0 deletions
87
src/main/java/com/leets/X/domain/post/dto/mapper/PostMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.leets.X.domain.post.dto.mapper; | ||
|
||
import com.leets.X.domain.image.dto.response.ImageResponse; | ||
import com.leets.X.domain.like.repository.LikeRepository; | ||
import com.leets.X.domain.post.domain.Post; | ||
import com.leets.X.domain.post.domain.enums.Type; | ||
import com.leets.X.domain.post.dto.response.ParentPostResponseDto; | ||
import com.leets.X.domain.post.dto.response.PostResponseDto; | ||
import com.leets.X.domain.post.dto.response.PostUserResponse; | ||
import com.leets.X.domain.user.domain.User; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
public class PostMapper { | ||
|
||
public PostResponseDto toPostResponseDto(Post post, User user, LikeRepository likeRepository, Type postType) { | ||
return PostResponseDto.builder() | ||
.id(post.getId()) | ||
.content(post.getContent()) | ||
.views(post.getViews()) | ||
.isDeleted(post.getIsDeleted()) | ||
.createdAt(post.getCreatedAt()) | ||
.user(toPostUserResponse(post.getUser())) | ||
.likeCount(post.getLikeCount()) | ||
.isLikedByUser(isLikedByUser(post, user, likeRepository)) | ||
.postType(postType) | ||
.myPost(isMyPost(post, user)) | ||
// .replyTo(getCustomId(post)) | ||
.images(toImageResponse(post)) | ||
.replies(toReplies(post.getReplies(), user, likeRepository, postType)) | ||
.build(); | ||
} | ||
|
||
public ParentPostResponseDto toParentPostResponseDto(Post post, User user, LikeRepository likeRepository, Type postType, Long repostingUserId) { | ||
return ParentPostResponseDto.builder() | ||
.id(post.getId()) | ||
.content(post.getContent()) | ||
.views(post.getViews()) | ||
.isDeleted(post.getIsDeleted()) | ||
.createdAt(post.getCreatedAt()) | ||
.user(toPostUserResponse(post.getUser())) | ||
.likeCount(post.getLikeCount()) | ||
.isLikedByUser(isLikedByUser(post, user, likeRepository)) | ||
.repostingUserId(repostingUserId) | ||
.postType(postType) | ||
.myPost(isMyPost(post, user)) | ||
// .replyTo(getCustomId(post)) | ||
.images(toImageResponse(post)) | ||
.build(); | ||
} | ||
|
||
public PostUserResponse toPostUserResponse(User user) { | ||
return PostUserResponse.from(user); | ||
} | ||
|
||
public List<ImageResponse> toImageResponse(Post post) { | ||
return post.getImages().stream() | ||
.map(ImageResponse::from) | ||
.toList(); | ||
} | ||
|
||
private List<PostResponseDto> toReplies(List<Post> replies, User user, LikeRepository likeRepository, Type postType) { | ||
return replies.stream() | ||
.map(reply -> toPostResponseDto(reply, user, likeRepository, postType)) | ||
.collect(Collectors.toList()); | ||
|
||
} | ||
|
||
private boolean isLikedByUser(Post post, User user, LikeRepository likeRepository) { | ||
return likeRepository.existsByPostAndUser(post, user); | ||
} | ||
|
||
private boolean isMyPost(Post post, User user) { | ||
return post.getUser().equals(user); | ||
} | ||
|
||
private String getCustomId(Post post) { | ||
if(post.getParent() == null){ | ||
return null; | ||
} | ||
return post.getParent().getUser().getCustomId(); | ||
} | ||
|
||
} |
13 changes: 0 additions & 13 deletions
13
src/main/java/com/leets/X/domain/post/dto/response/ImageResponseDto.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기존에는 dto의 from이나 entity의 of 정적 메서드를 사용했다면,
post와 repost를 공통으로 사용하는 dto 변환과 관련 로직을 위해 Mapper를 두어 관심사를 분리한건가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기존 PostResponseDto 내부 로직이 많아짐에 따라 dto의 역할을 넘어서는 책임이 생긴다고 판단해 dto를 만드는 커스텀 매퍼를 구현했습니다
또 post의 경우 자기 참조를 진행 중이라 dto로 만들어 반환하는 과정에 재귀적인 로직이 필요해 책임을 이전했습니다!