From 8a748018dee7b708246f831ce9640604bfd1c61c Mon Sep 17 00:00:00 2001 From: gitjiho Date: Sat, 16 Nov 2024 01:50:39 +0900 Subject: [PATCH] feat: db --- .../service/DailyQuestionService.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/gdg/kkia/dailyresponse/service/DailyQuestionService.java b/src/main/java/com/gdg/kkia/dailyresponse/service/DailyQuestionService.java index 25aad0e..055d713 100644 --- a/src/main/java/com/gdg/kkia/dailyresponse/service/DailyQuestionService.java +++ b/src/main/java/com/gdg/kkia/dailyresponse/service/DailyQuestionService.java @@ -38,23 +38,23 @@ public class DailyQuestionService { private final DailyQuestionRepository dailyQuestionRepository; private final DailyResponseRepository dailyResponseRepository; -// @PostConstruct -// public void loadQuestionsFromFile() { -// try (InputStream inputStream = getClass().getResourceAsStream("/dailyQuestions.txt"); -// BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(inputStream)))) { -// -// String line; -// while ((line = reader.readLine()) != null) { -// String finalLine = line; -// if (dailyQuestionRepository.findAll().stream().noneMatch(q -> q.getQuestion().equals(finalLine.trim()))) { -// DailyQuestion question = new DailyQuestion(line.trim()); -// dailyQuestionRepository.save(question); -// } -// } -// } catch (IOException e) { -// logger.error("Failed to load questions from file", e); -// } -// } + @PostConstruct + public void loadQuestionsFromFile() { + try (InputStream inputStream = getClass().getResourceAsStream("/dailyQuestions.txt"); + BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(inputStream)))) { + + String line; + while ((line = reader.readLine()) != null) { + String finalLine = line; + if (dailyQuestionRepository.findAll().stream().noneMatch(q -> q.getQuestion().equals(finalLine.trim()))) { + DailyQuestion question = new DailyQuestion(line.trim()); + dailyQuestionRepository.save(question); + } + } + } catch (IOException e) { + logger.error("Failed to load questions from file", e); + } + } @Transactional public void addDailyQuestion(DailyQuestionRequest dailyQuestionRequest) {