3
3
import com .devin .dev .entity .post .Post ;
4
4
import com .devin .dev .entity .post .PostImage ;
5
5
import com .devin .dev .entity .post .PostStatus ;
6
+ import com .devin .dev .entity .reply .ReplyStatus ;
7
+ import com .devin .dev .entity .user .UserStatus ;
6
8
import com .querydsl .core .annotations .QueryProjection ;
7
9
import lombok .Data ;
8
10
@@ -24,13 +26,14 @@ public class PostDetailsDto {
24
26
private List <String > post_images ;
25
27
private List <String > post_tags ;
26
28
private boolean status_accept ;
29
+ private boolean like_post ;
27
30
private LocalDateTime date_create ;
28
31
private LocalDateTime date_update ;
29
32
private Integer reply_num ;
30
33
private List <PostReplyDto > reply ;
31
34
32
35
@ 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 ) {
34
37
this .post_id = post_id ;
35
38
this .publisher_id = publisher_id ;
36
39
this .publisher_name = publisher_name ;
@@ -41,10 +44,11 @@ public PostDetailsDto(Long post_id, Long publisher_id, String publisher_name, St
41
44
this .post_images = post_images ;
42
45
this .post_tags = post_tags ;
43
46
this .status_accept = status_accept ;
47
+ this .like_post = like_post ;
44
48
this .date_create = date_create ;
45
49
this .date_update = date_update ;
46
50
this .reply_num = reply_num ;
47
- this .reply = replyDtos ;
51
+ this .reply = reply ;
48
52
}
49
53
50
54
public PostDetailsDto (Post post ) {
@@ -58,9 +62,35 @@ public PostDetailsDto(Post post) {
58
62
this .post_images = post .getImages ().stream ().map (PostImage ::getPath ).collect (Collectors .toList ());
59
63
this .post_tags = post .getPostTags ();
60
64
this .status_accept = post .getStatus () == PostStatus .SELECTED ;
65
+ this .like_post = post .getLikes ().size () > 0 ;
61
66
this .date_create = post .getCreatedDate ();
62
67
this .date_update = post .getLastModifiedDate ();
63
68
this .reply_num = post .getReplies ().size ();
64
69
this .reply = post .getReplies ().stream ().map (PostReplyDto ::new ).collect (Collectors .toList ());
65
70
}
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
+ }
66
96
}
0 commit comments