1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| package tacos;
import java.util.Arrays;
import org.springframework.boot.CommandLineRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.security.crypto.password.PasswordEncoder;
import tacos.Ingredient.Type; import tacos.data.IngredientRepository; import tacos.data.TacoRepository; import tacos.data.UserRepository;
@Profile("!prod") @Configuration public class DevelopmentConfig {
@Bean public CommandLineRunner dataLoader( IngredientRepository repo, UserRepository userRepo, PasswordEncoder encoder, TacoRepository tacoRepo) { return args -> { Ingredient flourTortilla = new Ingredient( "FLTO", "Flour Tortilla", Type.WRAP); Ingredient cornTortilla = new Ingredient( "COTO", "Corn Tortilla", Type.WRAP); Ingredient groundBeef = new Ingredient( "GRBF", "Ground Beef", Type.PROTEIN); Ingredient carnitas = new Ingredient( "CARN", "Carnitas", Type.PROTEIN); Ingredient tomatoes = new Ingredient( "TMTO", "Diced Tomatoes", Type.VEGGIES); Ingredient lettuce = new Ingredient( "LETC", "Lettuce", Type.VEGGIES); Ingredient cheddar = new Ingredient( "CHED", "Cheddar", Type.CHEESE); Ingredient jack = new Ingredient( "JACK", "Monterrey Jack", Type.CHEESE); Ingredient salsa = new Ingredient( "SLSA", "Salsa", Type.SAUCE); Ingredient sourCream = new Ingredient( "SRCR", "Sour Cream", Type.SAUCE); repo.save(flourTortilla); repo.save(cornTortilla); repo.save(groundBeef); repo.save(carnitas); repo.save(tomatoes); repo.save(lettuce); repo.save(cheddar); repo.save(jack); repo.save(salsa); repo.save(sourCream);
userRepo.save(new User("habuma", encoder.encode("password"), "Craig Walls", "123 North Street", "Cross Roads", "TX", "76227", "123-123-1234"));
Taco taco1 = new Taco(); taco1.setName("Carnivore"); taco1.setIngredients(Arrays.asList( flourTortilla, groundBeef, carnitas, sourCream, salsa, cheddar)); tacoRepo.save(taco1);
Taco taco2 = new Taco(); taco2.setName("Bovine Bounty"); taco2.setIngredients(Arrays.asList( cornTortilla, groundBeef, cheddar, jack, sourCream)); tacoRepo.save(taco2);
Taco taco3 = new Taco(); taco3.setName("Veg-Out"); taco3.setIngredients(Arrays.asList( flourTortilla, cornTortilla, tomatoes, lettuce, salsa)); tacoRepo.save(taco3); }; } }
|