Skip to content

Commit b07106c

Browse files
committed
Refactor/233 elasticsearch 관련 코드 주석 처리 (#235)
* chore(search): elasticsearch 관련 코드 주석 처리 * chore(search): elasticsearch 관련 코드 주석 처리
1 parent 662fafd commit b07106c

29 files changed

+1326
-1331
lines changed

src/main/java/com/somemore/community/controller/CommunityBoardQueryApiController.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.somemore.community.dto.response.CommunityBoardDetailResponseDto;
44
import com.somemore.community.dto.response.CommunityBoardResponseDto;
5-
import com.somemore.community.usecase.board.CommunityBoardDocumentUseCase;
5+
//import com.somemore.community.usecase.board.CommunityBoardDocumentUseCase;
66
import com.somemore.community.usecase.board.CommunityBoardQueryUseCase;
77
import com.somemore.global.common.response.ApiResponse;
88
import io.swagger.v3.oas.annotations.Operation;
@@ -21,7 +21,7 @@
2121
public class CommunityBoardQueryApiController {
2222

2323
private final CommunityBoardQueryUseCase communityBoardQueryUseCase;
24-
private final CommunityBoardDocumentUseCase communityBoardDocumentUseCase;
24+
// private final CommunityBoardDocumentUseCase communityBoardDocumentUseCase;
2525

2626
@GetMapping("/community-boards")
2727
@Operation(summary = "전체 커뮤니티 게시글 조회", description = "전체 커뮤니티 게시글 목록을 조회합니다.")
@@ -48,18 +48,18 @@ public ApiResponse<Page<CommunityBoardResponseDto>> getByWriterId(
4848
);
4949
}
5050

51-
@GetMapping("/community-boards/search")
52-
@Operation(summary = "커뮤니티 게시글 키워드 검색", description = "키워드로 포함한 커뮤니티 게시글 목록을 조회합니다.")
53-
public ApiResponse<Page<CommunityBoardResponseDto>> getCommunityBoardsBySearch(
54-
String keyword,
55-
Pageable pageable
56-
) {
57-
return ApiResponse.ok(
58-
200,
59-
communityBoardDocumentUseCase.getCommunityBoardBySearch(keyword, pageable.getPageNumber()),
60-
"커뮤니티 게시글 검색 리스트 조회 성공"
61-
);
62-
}
51+
// @GetMapping("/community-boards/search")
52+
// @Operation(summary = "커뮤니티 게시글 키워드 검색", description = "키워드로 포함한 커뮤니티 게시글 목록을 조회합니다.")
53+
// public ApiResponse<Page<CommunityBoardResponseDto>> getCommunityBoardsBySearch(
54+
// String keyword,
55+
// Pageable pageable
56+
// ) {
57+
// return ApiResponse.ok(
58+
// 200,
59+
// communityBoardDocumentUseCase.getCommunityBoardBySearch(keyword, pageable.getPageNumber()),
60+
// "커뮤니티 게시글 검색 리스트 조회 성공"
61+
// );
62+
// }
6363

6464
@GetMapping("/community-board/{id}")
6565
@Operation(summary = "커뮤니티 게시글 상세 조회", description = "커뮤니티 게시글의 상세 정보를 조회합니다.")
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
package com.somemore.community.domain;
2-
3-
import jakarta.persistence.Id;
4-
import lombok.Builder;
5-
import lombok.Getter;
6-
import org.springframework.data.elasticsearch.annotations.Document;
7-
import org.springframework.data.elasticsearch.annotations.Field;
8-
import org.springframework.data.elasticsearch.annotations.FieldType;
9-
10-
@Getter
11-
@Document(indexName = "community_board")
12-
public class CommunityBoardDocument {
13-
14-
@Id
15-
private Long id;
16-
17-
@Field(type = FieldType.Text, analyzer = "nori_analyzer")
18-
private String title;
19-
20-
@Field(type = FieldType.Text, analyzer = "nori_analyzer")
21-
private String content;
22-
23-
@Builder
24-
public CommunityBoardDocument(Long id, String title, String content) {
25-
this.id = id;
26-
this.title = title;
27-
this.content = content;
28-
}
29-
}
1+
//package com.somemore.community.domain;
2+
//
3+
//import jakarta.persistence.Id;
4+
//import lombok.Builder;
5+
//import lombok.Getter;
6+
//import org.springframework.data.elasticsearch.annotations.Document;
7+
//import org.springframework.data.elasticsearch.annotations.Field;
8+
//import org.springframework.data.elasticsearch.annotations.FieldType;
9+
//
10+
//@Getter
11+
//@Document(indexName = "community_board")
12+
//public class CommunityBoardDocument {
13+
//
14+
// @Id
15+
// private Long id;
16+
//
17+
// @Field(type = FieldType.Text, analyzer = "nori_analyzer")
18+
// private String title;
19+
//
20+
// @Field(type = FieldType.Text, analyzer = "nori_analyzer")
21+
// private String content;
22+
//
23+
// @Builder
24+
// public CommunityBoardDocument(Long id, String title, String content) {
25+
// this.id = id;
26+
// this.title = title;
27+
// this.content = content;
28+
// }
29+
//}
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
package com.somemore.community.repository.board;
2-
3-
import com.somemore.community.domain.CommunityBoardDocument;
4-
import org.springframework.data.elasticsearch.annotations.Query;
5-
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
6-
7-
import java.util.List;
8-
9-
public interface CommunityBoardDocumentRepository extends ElasticsearchRepository<CommunityBoardDocument, Long> {
10-
List<CommunityBoardDocument> findAll();
11-
@Query("{\"multi_match\": {\"query\": \"?0\", \"fields\": [\"title\", \"content\"]}}")
12-
List<CommunityBoardDocument> findIdsByTitleOrContentContaining(String keyword);
13-
}
1+
//package com.somemore.community.repository.board;
2+
//
3+
//import com.somemore.community.domain.CommunityBoardDocument;
4+
//import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
5+
//
6+
//public interface CommunityBoardDocumentRepository extends ElasticsearchRepository<CommunityBoardDocument, Long> {
7+
//// List<CommunityBoardDocument> findAll();
8+
//// @Query("{\"multi_match\": {\"query\": \"?0\", \"fields\": [\"title\", \"content\"]}}")
9+
//// List<CommunityBoardDocument> findIdsByTitleOrContentContaining(String keyword);
10+
//}

src/main/java/com/somemore/community/repository/board/CommunityBoardRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ default boolean doesNotExistById(Long id) {
2020
}
2121
void deleteAllInBatch();
2222

23-
Page<CommunityBoardView> findByCommunityBoardsContaining(String keyword, Pageable pageable);
24-
void saveDocuments(List<CommunityBoard> communityBoards);
23+
// Page<CommunityBoardView> findByCommunityBoardsContaining(String keyword, Pageable pageable);
24+
// void saveDocuments(List<CommunityBoard> communityBoards);
2525
List<CommunityBoard> findAll();
26-
void deleteDocument(Long id);
26+
// void deleteDocument(Long id);
2727
}

src/main/java/com/somemore/community/repository/board/CommunityBoardRepositoryImpl.java

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.querydsl.jpa.impl.JPAQuery;
66
import com.querydsl.jpa.impl.JPAQueryFactory;
77
import com.somemore.community.domain.CommunityBoard;
8-
import com.somemore.community.domain.CommunityBoardDocument;
98
import com.somemore.community.repository.mapper.CommunityBoardView;
109
import com.somemore.community.domain.QCommunityBoard;
1110
import com.somemore.volunteer.domain.QVolunteer;
@@ -15,7 +14,6 @@
1514
import org.springframework.data.support.PageableExecutionUtils;
1615
import org.springframework.stereotype.Repository;
1716

18-
import java.util.ArrayList;
1917
import java.util.List;
2018
import java.util.Optional;
2119
import 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
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
package com.somemore.community.scheduler;
2-
3-
import com.somemore.community.domain.CommunityBoard;
4-
import com.somemore.community.usecase.board.CommunityBoardDocumentUseCase;
5-
import com.somemore.community.usecase.board.CommunityBoardQueryUseCase;
6-
import lombok.RequiredArgsConstructor;
7-
import org.springframework.scheduling.annotation.Scheduled;
8-
import org.springframework.stereotype.Component;
9-
10-
import java.util.List;
11-
12-
@Component
13-
@RequiredArgsConstructor
14-
public class CommunityBoardUpdateScheduler {
15-
16-
private final CommunityBoardQueryUseCase communityBoardQueryUseCase;
17-
private final CommunityBoardDocumentUseCase communityBoardDocumentUseCase;
18-
19-
20-
@Scheduled(cron = "${spring.schedules.cron.updateCommunityBoardDocuments}")
21-
public void updateCommunityBoardDocuments() {
22-
List<CommunityBoard> communityBoards = communityBoardQueryUseCase.getAllCommunityBoards();
23-
communityBoardDocumentUseCase.saveCommunityBoardDocuments(communityBoards);
24-
}
25-
}
1+
//package com.somemore.community.scheduler;
2+
//
3+
//import com.somemore.community.domain.CommunityBoard;
4+
//import com.somemore.community.usecase.board.CommunityBoardDocumentUseCase;
5+
//import com.somemore.community.usecase.board.CommunityBoardQueryUseCase;
6+
//import lombok.RequiredArgsConstructor;
7+
//import org.springframework.scheduling.annotation.Scheduled;
8+
//import org.springframework.stereotype.Component;
9+
//
10+
//import java.util.List;
11+
//
12+
//@Component
13+
//@RequiredArgsConstructor
14+
//public class CommunityBoardUpdateScheduler {
15+
//
16+
// private final CommunityBoardQueryUseCase communityBoardQueryUseCase;
17+
// private final CommunityBoardDocumentUseCase communityBoardDocumentUseCase;
18+
//
19+
//
20+
// @Scheduled(cron = "${spring.schedules.cron.updateCommunityBoardDocuments}")
21+
// public void updateCommunityBoardDocuments() {
22+
// List<CommunityBoard> communityBoards = communityBoardQueryUseCase.getAllCommunityBoards();
23+
// communityBoardDocumentUseCase.saveCommunityBoardDocuments(communityBoards);
24+
// }
25+
//}

0 commit comments

Comments
 (0)