@@ -142,4 +142,84 @@ public ArticleListResponseDTO getUserCommentedArticles(Long targetUserId, int pa
142142 return new ArticleListResponseDTO (dtos , isLast , page );
143143 }
144144
145+ // 내가 작성한 게시글 조회
146+ public ArticleListResponseDTO getMyArticles (int page , int size , UserDetails userDetails ) {
147+
148+ // 사용자 정보 조회
149+ Member member = memberRepository .findByEmail (userDetails .getUsername ())
150+ .orElseThrow (() -> new NotFoundException (ErrorStatus .USER_NOTFOUND_EXCEPTION .getMessage ()));
151+ Long userId = member .getId ();
152+
153+ Pageable pageable = PageRequest .of (page , size , Sort .by ("createdAt" ).descending ());
154+ List <ArticleType > targetTypes = Arrays .asList (ArticleType .REVIEW , ArticleType .PHRASE , ArticleType .QNA );
155+
156+ // 게시글 조회
157+ Page <Article > articlePage = articleRepository .findByUserIdAndTypes (userId , targetTypes , pageable );
158+
159+ List <ArticleListDTO > articles = articlePage .getContent ().stream ()
160+ .map (a -> articleViewService .convertToListDTO (a , userDetails ))
161+ .collect (Collectors .toList ());
162+
163+ return new ArticleListResponseDTO (articles , articlePage .isLast (), page );
164+ }
165+
166+ // 내가 좋아요 누른 게시글 조회
167+ public ArticleListResponseDTO getMyLikedArticles (int page , int size , UserDetails userDetails ) {
168+
169+ // 사용자 정보 조회
170+ Member member = memberRepository .findByEmail (userDetails .getUsername ())
171+ .orElseThrow (() -> new NotFoundException (ErrorStatus .USER_NOTFOUND_EXCEPTION .getMessage ()));
172+
173+ Pageable pageable = PageRequest .of (page , size , Sort .by ("article.createdAt" ).descending ());
174+ List <ArticleType > targetTypes = Arrays .asList (ArticleType .REVIEW , ArticleType .PHRASE , ArticleType .QNA );
175+
176+ // 내 좋아요 목록
177+ Page <ArticleLike > likedPage = articleLikeRepository .findByMemberAndArticleTypeIn (member , targetTypes , pageable );
178+
179+ List <ArticleListDTO > articles = likedPage .getContent ().stream ()
180+ .map (like -> articleViewService .convertToListDTO (like .getArticle (), userDetails ))
181+ .collect (Collectors .toList ());
182+
183+ return new ArticleListResponseDTO (articles , likedPage .isLast (), page );
184+ }
185+
186+ // 내가 댓글 단 게시글 조회
187+ public ArticleListResponseDTO getMyCommentedArticles (int page , int size , UserDetails userDetails ) {
188+
189+ // 사용자 정보 조회
190+ Member member = memberRepository .findByEmail (userDetails .getUsername ())
191+ .orElseThrow (() -> new NotFoundException (ErrorStatus .USER_NOTFOUND_EXCEPTION .getMessage ()));
192+ Long userId = member .getId ();
193+
194+ // Review와 Phrase 게시글은 Comment 엔티티 사용
195+ List <ArticleType > reviewAndPhraseTypes = Arrays .asList (ArticleType .REVIEW , ArticleType .PHRASE );
196+ List <Article > articlesFromComment =
197+ commentRepository .findDistinctArticleByMemberIdAndArticleTypeIn (userId , reviewAndPhraseTypes );
198+
199+ // QnA 게시글은 QnaComment 엔티티 사용
200+ List <Article > articlesFromQnaComment =
201+ qnaCommentRepository .findDistinctQnaArticleByMemberId (userId );
202+
203+ // 두 리스트를 union 처리 (중복 제거)
204+ Set <Article > unionSet = new HashSet <>();
205+ unionSet .addAll (articlesFromComment );
206+ unionSet .addAll (articlesFromQnaComment );
207+
208+ // unionSet을 List로 변환 후, Article의 생성일(createdAt) 내림차순 정렬
209+ List <Article > combined = new ArrayList <>(unionSet );
210+ combined .sort ((a , b ) -> b .getCreatedAt ().compareTo (a .getCreatedAt ()));
211+
212+ // 수동 페이징 처리
213+ int start = page * size ;
214+ int end = Math .min (start + size , combined .size ());
215+ List <Article > subList = (start < combined .size ()) ? combined .subList (start , end ) : Collections .emptyList ();
216+
217+ List <ArticleListDTO > dtos = subList .stream ()
218+ .map (a -> articleViewService .convertToListDTO (a , userDetails ))
219+ .collect (Collectors .toList ());
220+
221+ boolean isLast = (end >= combined .size ());
222+ return new ArticleListResponseDTO (dtos , isLast , page );
223+ }
224+
145225}
0 commit comments