55import com .querydsl .jpa .impl .JPAQuery ;
66import com .querydsl .jpa .impl .JPAQueryFactory ;
77import com .somemore .community .domain .CommunityBoard ;
8- import com .somemore .community .domain .CommunityBoardDocument ;
98import com .somemore .community .repository .mapper .CommunityBoardView ;
109import com .somemore .community .domain .QCommunityBoard ;
1110import com .somemore .volunteer .domain .QVolunteer ;
1514import org .springframework .data .support .PageableExecutionUtils ;
1615import org .springframework .stereotype .Repository ;
1716
18- import java .util .ArrayList ;
1917import java .util .List ;
2018import java .util .Optional ;
2119import java .util .UUID ;
@@ -26,7 +24,7 @@ public class CommunityBoardRepositoryImpl implements CommunityBoardRepository {
2624
2725 private final JPAQueryFactory queryFactory ;
2826 private final CommunityBoardJpaRepository communityBoardJpaRepository ;
29- private final CommunityBoardDocumentRepository documentRepository ;
27+ // private final CommunityBoardDocumentRepository documentRepository;
3028
3129 private static final QCommunityBoard communityBoard = QCommunityBoard .communityBoard ;
3230 private static final QVolunteer volunteer = QVolunteer .volunteer ;
@@ -86,41 +84,41 @@ public boolean existsById(Long id) {
8684 return communityBoardJpaRepository .existsByIdAndDeletedFalse (id );
8785 }
8886
89- @ Override
90- public Page <CommunityBoardView > findByCommunityBoardsContaining (String keyword , Pageable pageable ) {
91- List <CommunityBoardDocument > boardDocuments = getBoardDocuments (keyword );
92-
93- List <Long > boardIds = boardDocuments .stream ()
94- .map (CommunityBoardDocument ::getId )
95- .toList ();
96-
97- List <CommunityBoardView > content = getCommunityBoardsQuery ()
98- .where (communityBoard .id .in (boardIds )
99- .and (isNotDeleted ()))
100- .offset (pageable .getOffset ())
101- .limit (pageable .getPageSize ())
102- .fetch ();
103-
104- JPAQuery <Long > countQuery = queryFactory
105- .select (communityBoard .count ())
106- .from (communityBoard )
107- .join (volunteer ).on (communityBoard .writerId .eq (volunteer .id ))
108- .where (communityBoard .id .in (boardIds )
109- .and (isNotDeleted ()));
110-
111- return PageableExecutionUtils .getPage (content , pageable , countQuery ::fetchOne );
112- }
113-
114- @ Override
115- public void saveDocuments (List <CommunityBoard > communityBoards ) {
116- List <CommunityBoardDocument > communityBoardDocuments = convertEntityToDocuments (communityBoards );
117- documentRepository .saveAll (communityBoardDocuments );
118- }
119-
120- @ Override
121- public void deleteDocument (Long id ) {
122- documentRepository .deleteById (id );
123- }
87+ // @Override
88+ // public Page<CommunityBoardView> findByCommunityBoardsContaining(String keyword, Pageable pageable) {
89+ // List<CommunityBoardDocument> boardDocuments = getBoardDocuments(keyword);
90+ //
91+ // List<Long> boardIds = boardDocuments.stream()
92+ // .map(CommunityBoardDocument::getId)
93+ // .toList();
94+ //
95+ // List<CommunityBoardView> content = getCommunityBoardsQuery()
96+ // .where(communityBoard.id.in(boardIds)
97+ // .and(isNotDeleted()))
98+ // .offset(pageable.getOffset())
99+ // .limit(pageable.getPageSize())
100+ // .fetch();
101+ //
102+ // JPAQuery<Long> countQuery = queryFactory
103+ // .select(communityBoard.count())
104+ // .from(communityBoard)
105+ // .join(volunteer).on(communityBoard.writerId.eq(volunteer.id))
106+ // .where(communityBoard.id.in(boardIds)
107+ // .and(isNotDeleted()));
108+ //
109+ // return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne);
110+ // }
111+
112+ // @Override
113+ // public void saveDocuments(List<CommunityBoard> communityBoards) {
114+ // List<CommunityBoardDocument> communityBoardDocuments = convertEntityToDocuments(communityBoards);
115+ // documentRepository.saveAll(communityBoardDocuments);
116+ // }
117+
118+ // @Override
119+ // public void deleteDocument(Long id) {
120+ // documentRepository.deleteById(id);
121+ // }
124122
125123 @ Override
126124 public List <CommunityBoard > findAll () {
@@ -142,31 +140,31 @@ private JPAQuery<CommunityBoardView> getCommunityBoardsQuery() {
142140 .orderBy (communityBoard .createdAt .desc ());
143141 }
144142
145- private List <CommunityBoardDocument > convertEntityToDocuments (List <CommunityBoard > communityBoards ) {
146- List <CommunityBoardDocument > communityBoardDocuments = new ArrayList <>();
147-
148- for (CommunityBoard communityboard : communityBoards ) {
149- CommunityBoardDocument document = CommunityBoardDocument .builder ()
150- .id (communityboard .getId ())
151- .title (communityboard .getTitle ())
152- .content (communityboard .getContent ())
153- .build ();
154- communityBoardDocuments .add (document );
155- }
156- return communityBoardDocuments ;
157- }
143+ // private List<CommunityBoardDocument> convertEntityToDocuments(List<CommunityBoard> communityBoards) {
144+ // List<CommunityBoardDocument> communityBoardDocuments = new ArrayList<>();
145+ //
146+ // for (CommunityBoard communityboard : communityBoards) {
147+ // CommunityBoardDocument document = CommunityBoardDocument.builder()
148+ // .id(communityboard.getId())
149+ // .title(communityboard.getTitle())
150+ // .content(communityboard.getContent())
151+ // .build();
152+ // communityBoardDocuments.add(document);
153+ // }
154+ // return communityBoardDocuments;
155+ // }
158156
159157 private BooleanExpression isNotDeleted () {
160158 return communityBoard .deleted .eq (false );
161159 }
162160
163161 private BooleanExpression isWriter (UUID writerId ) {return communityBoard .writerId .eq (writerId ); }
164162
165- private List <CommunityBoardDocument > getBoardDocuments (String keyword ) {
166-
167- if (keyword == null || keyword .isEmpty ()) {
168- return documentRepository .findAll ();
169- }
170- return documentRepository .findIdsByTitleOrContentContaining (keyword );
171- }
163+ // private List<CommunityBoardDocument> getBoardDocuments(String keyword) {
164+ //
165+ // if (keyword == null || keyword.isEmpty()) {
166+ // return documentRepository.findAll();
167+ // }
168+ // return documentRepository.findIdsByTitleOrContentContaining(keyword);
169+ // }
172170}
0 commit comments