-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] #31 repost 기능 구현 및 코드 통합
- Loading branch information
Showing
14 changed files
with
390 additions
and
162 deletions.
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.