33import com .devin .dev .entity .post .Post ;
44import com .devin .dev .entity .post .PostImage ;
55import com .devin .dev .entity .post .PostStatus ;
6+ import com .devin .dev .entity .reply .ReplyStatus ;
7+ import com .devin .dev .entity .user .UserStatus ;
68import com .querydsl .core .annotations .QueryProjection ;
79import lombok .Data ;
810
@@ -24,13 +26,14 @@ public class PostDetailsDto {
2426 private List <String > post_images ;
2527 private List <String > post_tags ;
2628 private boolean status_accept ;
29+ private boolean like_post ;
2730 private LocalDateTime date_create ;
2831 private LocalDateTime date_update ;
2932 private Integer reply_num ;
3033 private List <PostReplyDto > reply ;
3134
3235 @ QueryProjection
33- public PostDetailsDto (Long post_id , Long publisher_id , String publisher_name , String publisher_profile , Long publisher_exp , String title , String content , List <String > post_images , List <String > post_tags , boolean status_accept , boolean like_post , LocalDateTime date_create , LocalDateTime date_update , Integer reply_num , List <PostReplyDto > replyDtos ) {
36+ public PostDetailsDto (Long post_id , Long publisher_id , String publisher_name , String publisher_profile , Long publisher_exp , String title , String content , List <String > post_images , List <String > post_tags , boolean status_accept , boolean like_post , LocalDateTime date_create , LocalDateTime date_update , Integer reply_num , List <PostReplyDto > reply ) {
3437 this .post_id = post_id ;
3538 this .publisher_id = publisher_id ;
3639 this .publisher_name = publisher_name ;
@@ -41,10 +44,11 @@ public PostDetailsDto(Long post_id, Long publisher_id, String publisher_name, St
4144 this .post_images = post_images ;
4245 this .post_tags = post_tags ;
4346 this .status_accept = status_accept ;
47+ this .like_post = like_post ;
4448 this .date_create = date_create ;
4549 this .date_update = date_update ;
4650 this .reply_num = reply_num ;
47- this .reply = replyDtos ;
51+ this .reply = reply ;
4852 }
4953
5054 public PostDetailsDto (Post post ) {
@@ -58,9 +62,35 @@ public PostDetailsDto(Post post) {
5862 this .post_images = post .getImages ().stream ().map (PostImage ::getPath ).collect (Collectors .toList ());
5963 this .post_tags = post .getPostTags ();
6064 this .status_accept = post .getStatus () == PostStatus .SELECTED ;
65+ this .like_post = post .getLikes ().size () > 0 ;
6166 this .date_create = post .getCreatedDate ();
6267 this .date_update = post .getLastModifiedDate ();
6368 this .reply_num = post .getReplies ().size ();
6469 this .reply = post .getReplies ().stream ().map (PostReplyDto ::new ).collect (Collectors .toList ());
6570 }
71+
72+ public PostDetailsDto (Post post , UserStatus status ) {
73+ this .post_id = post .getId ();
74+ this .publisher_id = post .getUser ().getId ();
75+ this .publisher_name = post .getUser ().getName ();
76+ this .publisher_profile = post .getUser ().getProfile ();
77+ this .publisher_exp = post .getUser ().getExp ();
78+ this .title = post .getTitle ();
79+ this .content = post .getContent ();
80+ this .post_images = post .getImages ().stream ().map (PostImage ::getPath ).collect (Collectors .toList ());
81+ this .post_tags = post .getPostTags ();
82+ this .status_accept = post .getStatus () == PostStatus .SELECTED ;
83+ this .like_post = post .getLikes ().size () > 0 ;
84+ this .date_create = post .getCreatedDate ();
85+ this .date_update = post .getLastModifiedDate ();
86+ this .reply_num = post .getReplies ().size ();
87+ this .reply = status == UserStatus .ACTIVE || status == UserStatus .ADMIN ?
88+ post .getReplies ().stream ().map (PostReplyDto ::new ).collect (Collectors .toList ()) :
89+ post .getReplies ().stream ().map (PostReplyDto ::new ).peek (dto -> {
90+ if (dto .isStatus_accept ()) {
91+ dto .setContent ("비회원은 볼 수 없습니다." );
92+ dto .getReply_images ().clear ();
93+ }
94+ }).collect (Collectors .toList ());
95+ }
6696}
0 commit comments