parent
e0dcd66962
commit
0b85079b10
@ -0,0 +1,95 @@ |
|||||||
|
//--------------------------------
|
||||||
|
// InitStuffs.java
|
||||||
|
//
|
||||||
|
// 更新履歴:2025/06/10 新規作成
|
||||||
|
// Copyright(c) 2025 IVIS All rights reserved.
|
||||||
|
//
|
||||||
|
// Stuffsの初期データを起動時に設定するクラス
|
||||||
|
// すでにデータが存在する場合は、一時的にコメント部を有効にして
|
||||||
|
// 既存データを削除してから実行してください。
|
||||||
|
//--------------------------------------------
|
||||||
|
|
||||||
|
package com.example.todoapp.config; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct; |
||||||
|
|
||||||
|
import com.example.todoapp.model.ToBuys; |
||||||
|
import com.example.todoapp.repository.ToBuysRepository; |
||||||
|
import com.example.todoapp.model.Stocks; |
||||||
|
import com.example.todoapp.repository.StocksRepository; |
||||||
|
import com.example.todoapp.model.Recipes; |
||||||
|
import com.example.todoapp.repository.RecipesRepository; |
||||||
|
import com.example.todoapp.model.RecipeStuffs; |
||||||
|
import com.example.todoapp.repository.RecipeStuffsRepository; |
||||||
|
import com.example.todoapp.model.Stuffs; |
||||||
|
import com.example.todoapp.repository.StuffsRepository; |
||||||
|
|
||||||
|
@Configuration |
||||||
|
public class InitStuff { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ToBuysRepository tobuysRepository; |
||||||
|
@Autowired |
||||||
|
private StocksRepository stocksRepository; |
||||||
|
@Autowired |
||||||
|
private RecipesRepository recipesRepository; |
||||||
|
@Autowired |
||||||
|
private RecipeStuffsRepository recipeStuffsRepository; |
||||||
|
@Autowired |
||||||
|
private StuffsRepository stuffsRepository; |
||||||
|
|
||||||
|
@PostConstruct |
||||||
|
public void initStuff() { |
||||||
|
|
||||||
|
// tobuysRepository.deleteAll();
|
||||||
|
// stocksRepository.deleteAll();
|
||||||
|
// stuffsRepository.deleteAll();
|
||||||
|
|
||||||
|
if (stuffsRepository.count() > 0) { |
||||||
|
return; // すでにデータが存在する場合は何もしない
|
||||||
|
|
||||||
|
} else { |
||||||
|
setNewStuff(1L, "牛乳", null, "乳製品"); |
||||||
|
setNewStuff(2L, "ヨーグルト", null, "乳製品"); |
||||||
|
setNewStuff(3L, "チーズ", null, "乳製品"); |
||||||
|
setNewStuff(4L, "バター", null, "乳製品"); |
||||||
|
setNewStuff(5L, "生クリーム", null, "乳製品"); |
||||||
|
|
||||||
|
setNewStuff(6L, "鮭", null, "魚・肉"); |
||||||
|
setNewStuff(7L, "鶏むね肉", null, "魚・肉"); |
||||||
|
setNewStuff(8L, "豚バラ肉", null, "魚・肉"); |
||||||
|
setNewStuff(9L, "牛ひき肉", null, "魚・肉"); |
||||||
|
setNewStuff(10L, "まぐろ", null, "魚・肉"); |
||||||
|
|
||||||
|
setNewStuff(11L, "にんじん", null, "野菜"); |
||||||
|
setNewStuff(12L, "キャベツ", null, "野菜"); |
||||||
|
setNewStuff(13L, "ほうれん草", null, "野菜"); |
||||||
|
setNewStuff(14L, "玉ねぎ", null, "野菜"); |
||||||
|
setNewStuff(15L, "ピーマン", null, "野菜"); |
||||||
|
|
||||||
|
setNewStuff(16L, "醤油", null, "調味料"); |
||||||
|
setNewStuff(17L, "味噌", null, "調味料"); |
||||||
|
setNewStuff(18L, "塩", null, "調味料"); |
||||||
|
setNewStuff(19L, "砂糖", null, "調味料"); |
||||||
|
setNewStuff(20L, "酢", null, "調味料"); |
||||||
|
|
||||||
|
setNewStuff(21L, "米", null, "その他"); |
||||||
|
setNewStuff(22L, "パスタ", null, "その他"); |
||||||
|
setNewStuff(23L, "小麦粉", null, "その他"); |
||||||
|
setNewStuff(24L, "卵", null, "その他"); |
||||||
|
setNewStuff(25L, "豆腐", null, "その他"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void setNewStuff(Long stuffId, String stuffName, String summary, String category) { |
||||||
|
Stuffs stuff = new Stuffs(); |
||||||
|
stuff.setStuffId(stuffId); |
||||||
|
stuff.setStuffName(stuffName); |
||||||
|
stuff.setSummary(summary); |
||||||
|
stuff.setCategory(category); |
||||||
|
stuffsRepository.save(stuff); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
//--------------------------------
|
||||||
|
// RecipeStuffsRepository.java
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 更新履歴:2025/06/10 新規作成
|
||||||
|
// Copyright(c) 2025 IVIS All rights reserved.
|
||||||
|
//--------------------------------------------
|
||||||
|
package com.example.todoapp.repository; |
||||||
|
|
||||||
|
import com.example.todoapp.model.RecipeStuffs; |
||||||
|
|
||||||
|
import jakarta.transaction.Transactional; |
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||||
|
import org.springframework.data.jpa.repository.Modifying; |
||||||
|
import org.springframework.data.jpa.repository.Query; |
||||||
|
import org.springframework.data.repository.query.Param; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 料理-材料エンティティのリポジトリインターフェース |
||||||
|
* <p> |
||||||
|
* このインターフェースは料理-材料データへのアクセスと操作を提供します。 |
||||||
|
* Spring Data JPAによって自動的に実装されます。 |
||||||
|
* </p> |
||||||
|
*/ |
||||||
|
|
||||||
|
@Repository |
||||||
|
public interface RecipeStuffsRepository extends JpaRepository<RecipeStuffs, Long> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
//--------------------------------
|
||||||
|
// RecipesRepository.java
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 更新履歴:2025/06/10 新規作成
|
||||||
|
// Copyright(c) 2025 IVIS All rights reserved.
|
||||||
|
//--------------------------------------------
|
||||||
|
package com.example.todoapp.repository; |
||||||
|
|
||||||
|
import com.example.todoapp.model.Recipes; |
||||||
|
|
||||||
|
import jakarta.transaction.Transactional; |
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||||
|
import org.springframework.data.jpa.repository.Modifying; |
||||||
|
import org.springframework.data.jpa.repository.Query; |
||||||
|
import org.springframework.data.repository.query.Param; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 料理エンティティのリポジトリインターフェース |
||||||
|
* <p> |
||||||
|
* このインターフェースは料理データへのアクセスと操作を提供します。 |
||||||
|
* Spring Data JPAによって自動的に実装されます。 |
||||||
|
* </p> |
||||||
|
*/ |
||||||
|
|
||||||
|
@Repository |
||||||
|
public interface RecipesRepository extends JpaRepository<Recipes, Long> { |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue