-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…wform [Feature] 리뷰 생성하기
- Loading branch information
Showing
34 changed files
with
1,014 additions
and
462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 28 additions & 36 deletions
64
src/main/java/com/_119/wepro/global/config/DataInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,88 @@ | ||
package com._119.wepro.global.config; | ||
|
||
import com._119.wepro.global.enums.CategoryType; | ||
import com._119.wepro.review.domain.ChoiceOption; | ||
import com._119.wepro.review.domain.Option; | ||
import com._119.wepro.review.domain.Question; | ||
import com._119.wepro.review.domain.repository.ChoiceOptionCustomRepository; | ||
import com._119.wepro.review.domain.repository.ChoiceOptionJdbcRepository; | ||
import com._119.wepro.review.domain.repository.QuestionCustomRepository; | ||
import com._119.wepro.review.domain.repository.QuestionJdbcRepository; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class DataInitializer implements ApplicationRunner { | ||
|
||
private final ChoiceOptionJdbcRepository choiceOptionJdbcRepository; | ||
private final ChoiceOptionCustomRepository choiceOptionCustomRepository; | ||
private final QuestionJdbcRepository questionJdbcRepository; | ||
private final QuestionCustomRepository questionCustomRepository; | ||
|
||
private final ObjectMapper objectMapper; | ||
private final AtomicLong questionIdCounter = new AtomicLong(1); | ||
private final AtomicLong optionIdCounter = new AtomicLong(1); | ||
|
||
@Override | ||
public void run(ApplicationArguments args) throws Exception { | ||
|
||
setDefaultQuestionsAndChoiceOption(); | ||
setDefaultQuestionsAndOptions(); | ||
} | ||
|
||
private void setDefaultQuestionsAndChoiceOption() { | ||
|
||
// DB에 데이터 없는 경우만 새로 생성 | ||
if (!questionCustomRepository.exists() && !choiceOptionCustomRepository.exists()) { | ||
private void setDefaultQuestionsAndOptions() { | ||
// DB에 데이터가 없는 경우만 새로 생성 | ||
if (!questionCustomRepository.exists()) { | ||
|
||
List<Question> allQuestions = new ArrayList<>(); | ||
List<ChoiceOption> allChoiceOptions = new ArrayList<>(); | ||
List<CategoryQuestions> categoryQuestionsList; | ||
|
||
// json 파일 읽기 | ||
// JSON 파일 읽기 | ||
try { | ||
ClassPathResource resource = new ClassPathResource("default-questions.json"); | ||
categoryQuestionsList = objectMapper.readValue( | ||
resource.getInputStream(), new TypeReference<List<CategoryQuestions>>() { | ||
}); | ||
resource.getInputStream(), new TypeReference<List<CategoryQuestions>>() {}); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return; | ||
} | ||
|
||
// CategoryQuestions -> Question, ChoiceOption | ||
// CategoryQuestions -> Question, Option | ||
categoryQuestionsList.forEach(categoryQuestions -> { | ||
CategoryType categoryType = categoryQuestions.categoryType(); | ||
categoryQuestions.questions().forEach(questionWithOptions -> { | ||
Question question = Question.of(questionIdCounter.getAndIncrement(), categoryType, | ||
questionWithOptions.question()); | ||
List<ChoiceOption> options = createOptionsForQuestion(question, | ||
questionWithOptions.options()); | ||
|
||
Question question = Question.builder() | ||
.content(questionWithOptions.question()) | ||
.categoryType(categoryType) | ||
.options(createOptionsForQuestion(questionWithOptions.options())) | ||
.build(); | ||
|
||
allQuestions.add(question); | ||
allChoiceOptions.addAll(options); | ||
}); | ||
}); | ||
|
||
questionJdbcRepository.batchInsert(allQuestions); | ||
choiceOptionJdbcRepository.batchInsert(allChoiceOptions); | ||
} | ||
} | ||
|
||
private List<ChoiceOption> createOptionsForQuestion(Question question, List<String> optionTexts) { | ||
List<ChoiceOption> options = new ArrayList<>(); | ||
private List<Option> createOptionsForQuestion(List<String> optionTexts) { | ||
List<Option> options = new ArrayList<>(); | ||
for (int i = 0; i < optionTexts.size(); i++) { | ||
options.add(ChoiceOption.of(i + 1, optionTexts.get(i), question)); | ||
options.add(Option.builder() | ||
.id(optionIdCounter.getAndIncrement()) | ||
.content(optionTexts.get(i)) | ||
.build()); | ||
} | ||
return options; | ||
} | ||
|
||
private record CategoryQuestions(CategoryType categoryType, List<QuestionWithOptions> questions) { | ||
private record CategoryQuestions(CategoryType categoryType, List<QuestionWithOptions> questions) {} | ||
|
||
} | ||
|
||
private record QuestionWithOptions(String question, List<String> options) { | ||
|
||
} | ||
private record QuestionWithOptions(String question, List<String> options) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/_119/wepro/project/domain/repository/ProjectMemberCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com._119.wepro.project.domain.repository; | ||
|
||
import com._119.wepro.alarm.domain.QAlarm; | ||
import com._119.wepro.global.enums.AlarmType; | ||
import com._119.wepro.member.domain.QMember; | ||
import com._119.wepro.project.domain.ProjectMember; | ||
import com._119.wepro.project.domain.QProjectMember; | ||
import com.querydsl.jpa.JPAExpressions; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class ProjectMemberCustomRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
public List<ProjectMember> getProjectMembersWithoutReviewRequest(Long reviewFormId) { | ||
QProjectMember projectMember = QProjectMember.projectMember; | ||
QAlarm alarm = QAlarm.alarm; | ||
QMember member = QMember.member; // Member 엔티티를 가져오기 위해 추가 | ||
|
||
return queryFactory | ||
.selectFrom(projectMember) | ||
.join(projectMember.member, member).fetchJoin() | ||
.where(projectMember.id.notIn( | ||
JPAExpressions | ||
.select(alarm.receiver.id) | ||
.from(alarm) | ||
.where(alarm.targetId.eq(reviewFormId) | ||
.and(alarm.alarmType.eq(AlarmType.REVIEW_REQUEST))) | ||
)) | ||
.fetch(); | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
src/main/java/com/_119/wepro/review/domain/ChoiceOption.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.