11package cat .udl .eps .softarch .demo .bootstrap ;
22
3+ import cat .udl .eps .softarch .demo .domain .Business ;
34import cat .udl .eps .softarch .demo .domain .Category ;
5+ import cat .udl .eps .softarch .demo .domain .Inventory ;
46import cat .udl .eps .softarch .demo .domain .Product ;
5- import cat .udl .eps .softarch .demo .repository .CategoryRepository ; // <--- Import nou
7+ import cat .udl .eps .softarch .demo .repository .BusinessRepository ;
8+ import cat .udl .eps .softarch .demo .repository .CategoryRepository ;
9+ import cat .udl .eps .softarch .demo .repository .InventoryRepository ;
610import cat .udl .eps .softarch .demo .repository .ProductRepository ;
711import lombok .RequiredArgsConstructor ;
812import org .springframework .boot .CommandLineRunner ;
1923public class ProductLoader implements CommandLineRunner {
2024
2125 private final ProductRepository productRepository ;
22- private final CategoryRepository categoryRepository ; // <--- Injectem el repo de categories
26+ private final CategoryRepository categoryRepository ;
27+ private final BusinessRepository businessRepository ;
28+ private final InventoryRepository inventoryRepository ;
2329
2430 @ Override
2531 public void run (String ... args ) throws Exception {
@@ -29,18 +35,41 @@ public void run(String... args) throws Exception {
2935 }
3036
3137 private void loadData () {
32- // --- 1. CREAR I GUARDAR CATEGORIES ---
38+
39+
40+ Business mainBusiness = new Business ();
41+ mainBusiness .setName ("Lleida Coffee Shop" );
42+ mainBusiness .setEmail ("info@lleidacoffee.com" );
43+ mainBusiness .setUsername ("admin1" );
44+
45+
46+ mainBusiness .setPassword ("password123" ); // Ara té 11 caràcters, ja passarà la validació
47+ mainBusiness .setAddress ("Carrer Major, 1, Lleida" );
48+ // ------------------------------------------------
49+
50+ businessRepository .save (mainBusiness );
51+
52+ Inventory mainInventory = new Inventory ();
53+ mainInventory .setName ("Main Warehouse" );
54+ mainInventory .setDescription ("Magatzem principal de la botiga" );
55+ mainInventory .setLocation ("Lleida, Rovira Roure 4" );
56+ mainInventory .setTotalStock (1000 );
57+ mainInventory .setBusiness (mainBusiness );
58+
59+ inventoryRepository .save (mainInventory );
60+
61+ System .out .println ("📦 Created Main Inventory: " + mainInventory .getName ());
62+
63+
3364 Category catCoffee = Category .builder ().name ("Specialty Coffee" ).description ("Best beans in town" ).build ();
3465 Category catFood = Category .builder ().name ("Food & Pastry" ).description ("Freshly baked goods" ).build ();
3566 Category catDrink = Category .builder ().name ("Drinks" ).description ("Cold and refreshing" ).build ();
3667 Category catAlt = Category .builder ().name ("Alternatives" ).description ("Plant based options" ).build ();
3768 Category catMerch = Category .builder ().name ("Merchandise" ).description ("Gifts and accessories" ).build ();
3869
39- // Guardem les categories primer per tenir ID i poder associar-les
4070 categoryRepository .saveAll (Arrays .asList (catCoffee , catFood , catDrink , catAlt , catMerch ));
4171
4272
43- // --- 2. CREAR PRODUCTES AMB LA CATEGORIA ASSIGNADA ---
4473
4574 Product cafeEtiopia = Product .builder ()
4675 .name ("Ethiopia Yirgacheffe (250g)" )
@@ -49,7 +78,8 @@ private void loadData() {
4978 .stock (20 )
5079 .isAvailable (true )
5180 .brand ("Nomad Coffee" )
52- .category (catCoffee ) // <--- Assignem la categoria
81+ .category (catCoffee )
82+ .inventory (mainInventory )
5383 .barcode ("8410000000010" )
5484 .kcal (2 )
5585 .ingredients (Set .of ("100% Washed Arabica Coffee" ))
@@ -66,7 +96,8 @@ private void loadData() {
6696 .stock (15 )
6797 .isAvailable (true )
6898 .brand ("Local Bakery" )
69- .category (catFood ) // <--- Assignem la categoria
99+ .category (catFood )
100+ .inventory (mainInventory )
70101 .barcode ("8410000000020" )
71102 .kcal (280 )
72103 .carbs (30 )
@@ -86,7 +117,8 @@ private void loadData() {
86117 .stock (3 )
87118 .isAvailable (true )
88119 .brand ("MyCoffee House" )
89- .category (catDrink ) // <--- Assignem la categoria
120+ .category (catDrink )
121+ .inventory (mainInventory )
90122 .barcode ("8410000000030" )
91123 .kcal (5 )
92124 .ingredients (Set .of ("Filtered water" , "Coffee" ))
@@ -103,7 +135,8 @@ private void loadData() {
103135 .stock (0 )
104136 .isAvailable (true )
105137 .brand ("Local Bakery" )
106- .category (catFood ) // <--- Assignem la categoria
138+ .category (catFood )
139+ .inventory (mainInventory )
107140 .barcode ("8410000000040" )
108141 .kcal (350 )
109142 .allergens (Set .of ("Gluten" , "Nuts" , "Soy" ))
@@ -118,7 +151,8 @@ private void loadData() {
118151 .stock (50 )
119152 .isAvailable (true )
120153 .brand ("Oatly" )
121- .category (catAlt ) // <--- Assignem la categoria
154+ .category (catAlt )
155+ .inventory (mainInventory )
122156 .barcode ("8410000000050" )
123157 .kcal (60 )
124158 .ingredients (Set .of ("Water" , "Oats" , "Rapeseed oil" ))
@@ -136,7 +170,8 @@ private void loadData() {
136170 .stock (10 )
137171 .isAvailable (true )
138172 .brand ("MyCoffee House" )
139- .category (catMerch ) // <--- Assignem la categoria
173+ .category (catMerch )
174+ .inventory (mainInventory )
140175 .barcode ("8410000000060" )
141176 .rating (5.0 )
142177 .isPartOfLoyaltyProgram (true )
@@ -146,8 +181,8 @@ private void loadData() {
146181
147182 productRepository .saveAll (Arrays .asList (cafeEtiopia , croissant , coldBrew , cookieXoc , oatMilk , giftPack ));
148183
149- System .out .println ("------------------------------------------------" );
150- System .out .println ("☕ COFFEE SHOP MENU LOADED WITH CATEGORIES ☕" );
151- System .out .println ("------------------------------------------------" );
184+ System .out .println ("------------------------------------------------------- " );
185+ System .out .println ("☕ COFFEE SHOP MENU LOADED WITH CATEGORIES & INVENTORY ☕" );
186+ System .out .println ("------------------------------------------------------- " );
152187 }
153188}
0 commit comments