Skip to content

Commit 25e6299

Browse files
committed
hotfix : 문제 카테고리를 db table 로 변경 작업 완료
1 parent 0cd2d25 commit 25e6299

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/main/java/org/ezcode/codetest/application/problem/service/ProblemService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ public void modifyProblem(Long problemId, ProblemUpdateRequest request) {
106106

107107
Problem findProblem = problemDomainService.getProblem(problemId);
108108

109-
problemDomainService.updateProblemCategory(findProblem, request.categories());
110-
111109
findProblem.update(
112110
findProblem.getCreator(),
113111
request.title(),
@@ -117,6 +115,9 @@ public void modifyProblem(Long problemId, ProblemUpdateRequest request) {
117115
request.timeLimit(),
118116
request.reference()
119117
);
118+
119+
problemDomainService.updateCategoryAndSearchEngine(findProblem, request.categories());
120+
120121
}
121122

122123
// 문제 삭제 ( 관리자 )

src/main/java/org/ezcode/codetest/domain/problem/service/ProblemDomainService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public List<ProblemCategory> getProblemsCategoryList(List<Problem> problem) {
5050
return problemCategoryRepository.findByProblemIdsIn(problemIds);
5151
}
5252

53-
public void updateProblemCategory(Problem problem, List<String> categories) {
53+
public void updateCategoryAndSearchEngine(Problem problem, List<String> categories) {
5454

5555
problemCategoryRepository.deleteAllByProblemId(problem.getId());
5656

@@ -60,7 +60,10 @@ public void updateProblemCategory(Problem problem, List<String> categories) {
6060
.map(cat -> ProblemCategory.from(problem, cat))
6161
.toList();
6262

63-
problemCategoryRepository.saveAll(problemCategories);
63+
List<ProblemCategory> savedCategories = problemCategoryRepository.saveAll(problemCategories);
64+
65+
searchRepository.save(ProblemSearchDocument.from(problem, savedCategories.stream().map(
66+
ProblemCategory::getCategory).toList()));
6467
}
6568

6669
public Problem createProblem(Problem problem, Map<String, String> categories) {

src/main/java/org/ezcode/codetest/infrastructure/persistence/repository/problem/ProblemCategoryRepositoryImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public List<ProblemCategory> findByProblemIdsIn(List<Long> problemIds) {
3636
public void deleteAllByProblemId(Long problemId) {
3737

3838
problemCategoryRepository.deleteAllByProblemId(problemId);
39+
problemCategoryRepository.flush();
3940
}
4041

4142
@Override

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
1515
# ========================
1616
# JPA
1717
# ========================
18-
spring.jpa.hibernate.ddl-auto=create-drop
18+
spring.jpa.hibernate.ddl-auto=update
1919
spring.jpa.show-sql=true
2020
spring.jpa.properties.hibernate.format_sql=true
2121

0 commit comments

Comments
 (0)