99import com .back .domain .cocktail .repository .CocktailRepository ;
1010import com .back .domain .post .comment .enums .CommentStatus ;
1111import com .back .domain .user .entity .User ;
12+ import com .back .global .exception .UnauthorizedException ;
1213import com .back .global .rq .Rq ;
1314import lombok .RequiredArgsConstructor ;
1415import org .springframework .stereotype .Service ;
@@ -46,6 +47,7 @@ public CocktailCommentResponseDto createCocktailComment(Long cocktailId, Cocktai
4647 .cocktail (cocktail )
4748 .user (user )
4849 .content (reqBody .content ())
50+ .status (reqBody .status ())
4951 .build ();
5052
5153 return new CocktailCommentResponseDto (cocktailCommentRepository .save (cocktailComment ));
@@ -54,17 +56,34 @@ public CocktailCommentResponseDto createCocktailComment(Long cocktailId, Cocktai
5456 // 칵테일 댓글 다건 조회 로직 (무한스크롤)
5557 @ Transactional (readOnly = true )
5658 public List <CocktailCommentResponseDto > getCocktailComments (Long cocktailId , Long lastId ) {
59+ User actor = rq .getActor (); // 서비스에서 호출 가능
60+
61+ if (actor == null ) {
62+ throw new UnauthorizedException ("로그인이 필요합니다." );
63+ }
64+ Long currentUserId = actor .getId ();
65+ List <CocktailComment > comments ;
66+
5767 if (lastId == null ) {
58- return cocktailCommentRepository .findTop10ByCocktailIdAndStatusOrderByIdDesc (cocktailId , CommentStatus .PUBLIC )
59- .stream ()
60- .map (CocktailCommentResponseDto ::new )
61- .toList ();
68+ comments = cocktailCommentRepository
69+ .findTop10ByCocktailIdAndStatusInOrderByIdDesc (cocktailId , List .of (CommentStatus .PUBLIC , CommentStatus .PRIVATE )
70+ );
6271 } else {
63- return cocktailCommentRepository .findTop10ByCocktailIdAndStatusAndIdLessThanOrderByIdDesc (cocktailId , CommentStatus .PUBLIC , lastId )
64- .stream ()
65- .map (CocktailCommentResponseDto ::new )
66- .toList ();
72+ comments = cocktailCommentRepository
73+ .findTop10ByCocktailIdAndStatusInAndIdLessThanOrderByIdDesc (cocktailId , List .of (CommentStatus .PUBLIC , CommentStatus .PRIVATE ),
74+ lastId );
6775 }
76+
77+ return comments .stream ()
78+ .filter (comment ->{
79+ if (comment .getStatus () == CommentStatus .PUBLIC ) return true ;
80+ if (comment .getStatus () == CommentStatus .PRIVATE ) {
81+ return comment .getUser ().getId ().equals (currentUserId );
82+ }
83+ return false ;
84+ })
85+ .map (CocktailCommentResponseDto ::new )
86+ .toList ();
6887 }
6988
7089 // 칵테일 댓글 단건 조회 로직
0 commit comments