|
| 1 | +package com.webservice.algorithmchef.service; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.springframework.boot.CommandLineRunner; |
| 7 | +import org.springframework.stereotype.Component; |
| 8 | +import org.springframework.transaction.annotation.Transactional; |
| 9 | + |
| 10 | +import com.webservice.algorithmchef.model.Allergy; |
| 11 | +import com.webservice.algorithmchef.model.HealthGoal; |
| 12 | +import com.webservice.algorithmchef.repository.AllergyRepository; |
| 13 | +import com.webservice.algorithmchef.repository.HealthGoalRepository; |
| 14 | + |
| 15 | +import lombok.RequiredArgsConstructor; |
| 16 | +import lombok.extern.slf4j.Slf4j; |
| 17 | + |
| 18 | +@Component |
| 19 | +@RequiredArgsConstructor |
| 20 | +@Slf4j |
| 21 | +public class DataInitializer implements CommandLineRunner{ |
| 22 | + |
| 23 | + private final HealthGoalRepository healthGoalRepository; |
| 24 | + private final AllergyRepository allergyRepository; |
| 25 | + |
| 26 | + @Override |
| 27 | + @Transactional |
| 28 | + public void run(String... args) throws Exception { |
| 29 | + // TODO Auto-generated method stub |
| 30 | + |
| 31 | + if(healthGoalRepository.count() == 0) { |
| 32 | + log.info("데이터 베이스에 건강 목표 삽입 진행합니다."); |
| 33 | + List<HealthGoal> goals = Arrays.asList( |
| 34 | + HealthGoal.builder().name("다이어트 (체중 감량)").category("체중 관리").description("저칼로리, 저지방 식단").build(), |
| 35 | + HealthGoal.builder().name("근육 증가 (고단백)").category("체중 관리").description("단백질 함량이 높은 식단").build(), |
| 36 | + HealthGoal.builder().name("체중 유지").category("체중 관리").description("균형 잡힌 영양소 섭취").build(), |
| 37 | + |
| 38 | + HealthGoal.builder().name("저염 식단").category("건강 상태").description("나트륨 섭취를 줄이는 식단").build(), |
| 39 | + HealthGoal.builder().name("혈압 관리").category("건강 상태").description("칼륨이 풍부한 식단").build(), |
| 40 | + HealthGoal.builder().name("당뇨 관리 (저당)").category("건강 상태").description("혈당을 천천히 올리는 식단").build(), |
| 41 | + HealthGoal.builder().name("콜레스테롤 관리").category("건강 상태").description("포화지방이 적은 식단").build(), |
| 42 | + |
| 43 | + HealthGoal.builder().name("채식 (비건)").category("라이프스타일").description("모든 동물성 제품 제외").build(), |
| 44 | + HealthGoal.builder().name("채식 (락토-오보)").category("라이프스타일").description("고기 제외 (유제품, 계란 허용)").build(), |
| 45 | + HealthGoal.builder().name("임산부 식단").category("라이프 스타일"). |
| 46 | + description("엽산, 철분 등이 풍부하고 날음식을 피하는 식단").build(), |
| 47 | + HealthGoal.builder().name("키토제닉 (고지방 저탄수화물)").category("라이프 스타일") |
| 48 | + .description("탄수화물을 극단적으로 줄이고 지방 섭취").build() |
| 49 | + ); |
| 50 | + healthGoalRepository.saveAll(goals); |
| 51 | + log.info("건강 목표 저장 완료"); |
| 52 | + } |
| 53 | + |
| 54 | + if(allergyRepository.count() == 0) { |
| 55 | + log.info("데이터 베이스에 알러지 종류 삽입 진행합니다."); |
| 56 | + List<Allergy> allergies = Arrays.asList( |
| 57 | + Allergy.builder().name("갑각류 알레르기").build(), |
| 58 | + Allergy.builder().name("견과 알레르기").build(), |
| 59 | + Allergy.builder().name("달걀 알레르기").build(), |
| 60 | + Allergy.builder().name("땅콩 알레르기").build(), |
| 61 | + Allergy.builder().name("밀 알레르기").build(), |
| 62 | + Allergy.builder().name("생선 알레르기").build(), |
| 63 | + Allergy.builder().name("우유 알레르기").build(), |
| 64 | + Allergy.builder().name("조개 알레르기").build(), |
| 65 | + Allergy.builder().name("콩 알레르기").build(), |
| 66 | + Allergy.builder().name("복숭아 알레르기").build() |
| 67 | + ); |
| 68 | + allergyRepository.saveAll(allergies); |
| 69 | + log.info("알레르기 정보 데이터베이스에 저장완료"); |
| 70 | + } |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments