|
1 | 1 | package com.back.global.init; |
2 | 2 |
|
| 3 | +import com.back.domain.cocktail.entity.Cocktail; |
| 4 | +import com.back.domain.cocktail.repository.CocktailRepository; |
3 | 5 | import com.back.domain.notification.entity.Notification; |
4 | 6 | import com.back.domain.notification.enums.NotificationType; |
5 | 7 | import com.back.domain.notification.repository.NotificationRepository; |
6 | | -import com.back.domain.cocktail.entity.Cocktail; |
7 | | -import com.back.domain.cocktail.enums.AlcoholBaseType; |
8 | | -import com.back.domain.cocktail.enums.AlcoholStrength; |
9 | | -import com.back.domain.cocktail.enums.CocktailType; |
10 | | -import com.back.domain.cocktail.repository.CocktailRepository; |
11 | 8 | import com.back.domain.post.category.entity.Category; |
12 | 9 | import com.back.domain.post.category.repository.CategoryRepository; |
13 | 10 | import com.back.domain.post.comment.entity.Comment; |
|
19 | 16 | import com.back.domain.post.post.repository.PostRepository; |
20 | 17 | import com.back.domain.user.entity.User; |
21 | 18 | import com.back.domain.user.repository.UserRepository; |
22 | | -import org.springframework.transaction.annotation.Transactional; |
23 | 19 | import lombok.RequiredArgsConstructor; |
24 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
25 | 21 | import org.springframework.boot.ApplicationRunner; |
26 | 22 | import org.springframework.context.annotation.Bean; |
27 | 23 | import org.springframework.context.annotation.Configuration; |
28 | 24 | import org.springframework.context.annotation.Lazy; |
29 | 25 | import org.springframework.context.annotation.Profile; |
| 26 | +import org.springframework.transaction.annotation.Transactional; |
30 | 27 |
|
31 | 28 | @Configuration |
32 | 29 | @Profile("dev") |
@@ -59,56 +56,15 @@ ApplicationRunner devInitDataApplicationRunner() { |
59 | 56 | } |
60 | 57 |
|
61 | 58 | @Transactional |
62 | | - public void cocktailInit() { |
63 | | - if (cocktailRepository.count() > 0) return; |
64 | | - |
65 | | - // 1) 하이볼 |
66 | | - cocktailRepository.save(Cocktail.builder() |
67 | | - .cocktailName("Highball") |
68 | | - .cocktailNameKo("하이볼") |
69 | | - .alcoholStrength(AlcoholStrength.LIGHT) |
70 | | - .cocktailType(CocktailType.LONG) |
71 | | - .alcoholBaseType(AlcoholBaseType.WHISKY) |
72 | | - .ingredient("위스키, 탄산수, 얼음, 레몬피") |
73 | | - .recipe("잔에 얼음 → 위스키 → 탄산수 → 가볍게 스터") |
74 | | - .cocktailImgUrl("/img/cocktail/1.jpg") |
75 | | - .build()); |
76 | | - |
77 | | - // 2) 진토닉 |
78 | | - cocktailRepository.save(Cocktail.builder() |
79 | | - .cocktailName("Gin and Tonic") |
80 | | - .cocktailNameKo("진토닉") |
81 | | - .alcoholStrength(AlcoholStrength.WEAK) |
82 | | - .cocktailType(CocktailType.LONG) |
83 | | - .alcoholBaseType(AlcoholBaseType.GIN) |
84 | | - .ingredient("진, 토닉워터, 얼음, 라임") |
85 | | - .recipe("잔에 얼음 → 진 → 토닉워터 → 라임") |
86 | | - .cocktailImgUrl("/img/cocktail/2.jpg") |
87 | | - .build()); |
88 | | - |
89 | | - // 3) 올드패션드 |
90 | | - cocktailRepository.save(Cocktail.builder() |
91 | | - .cocktailName("Old Fashioned") |
92 | | - .cocktailNameKo("올드패션드") |
93 | | - .alcoholStrength(AlcoholStrength.STRONG) |
94 | | - .cocktailType(CocktailType.SHORT) |
95 | | - .alcoholBaseType(AlcoholBaseType.WHISKY) |
96 | | - .ingredient("버번 위스키, 설탕/시럽, 앙고스투라 비터스, 오렌지 필") |
97 | | - .recipe("시럽+비터스 → 위스키 → 얼음 → 스터 → 오렌지 필") |
98 | | - .cocktailImgUrl("/img/cocktail/3.jpg") |
99 | | - .build()); |
| 59 | + public void cocktailInit() throws Exception { |
| 60 | + // H2 DB에 이미 데이터가 들어가 있는지 확인 |
| 61 | + if (cocktailRepository.count() > 0) { |
| 62 | + System.out.println("Cocktail 데이터가 이미 존재합니다."); |
| 63 | + return; |
| 64 | + } |
100 | 65 |
|
101 | | - // 4) 모히또 |
102 | | - cocktailRepository.save(Cocktail.builder() |
103 | | - .cocktailName("Mojito") |
104 | | - .cocktailNameKo("모히또") |
105 | | - .alcoholStrength(AlcoholStrength.LIGHT) |
106 | | - .cocktailType(CocktailType.LONG) |
107 | | - .alcoholBaseType(AlcoholBaseType.RUM) |
108 | | - .ingredient("라임, 민트, 설탕/시럽, 화이트 럼, 탄산수, 얼음") |
109 | | - .recipe("라임+민트+시럽 머들 → 럼 → 얼음 → 탄산수") |
110 | | - .cocktailImgUrl("/img/cocktail/4.jpg") |
111 | | - .build()); |
| 66 | + // data-h2.sql에서 자동 삽입되므로 여기서는 추가하지 않음. |
| 67 | + System.out.println("Cocktail 초기화: CSV에서 데이터를 이미 로드합니다."); |
112 | 68 | } |
113 | 69 |
|
114 | 70 | @Transactional |
|
0 commit comments