From 7135d79427e1c000c81e1841d2b976c634672034 Mon Sep 17 00:00:00 2001 From: gitjiho Date: Sun, 17 Nov 2024 15:58:58 +0900 Subject: [PATCH] deploy: db migration mySQL -> H2 --- build.gradle | 2 +- .../service/DailyQuestionService.java | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index dce1bb6..39fb231 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ dependencies { implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.6.0' implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.1' runtimeOnly 'com.mysql:mysql-connector-j' - testImplementation 'mysql:mysql-connector-java:8.0.33' + implementation 'com.h2database:h2' } tasks.named('test') { 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) {