User setup added

This commit is contained in:
Sidharth Prabhu
2026-08-03 10:41:57 +05:30
parent 28a13d619c
commit 6b3714f2bc
8 changed files with 692 additions and 54 deletions

View File

@@ -2,15 +2,21 @@ package com.rit.canteen.sales.service;
import com.rit.canteen.sales.model.BaseItem;
import com.rit.canteen.sales.model.Product;
import com.rit.canteen.sales.model.Stall;
import com.rit.canteen.sales.model.SystemUser;
import com.rit.canteen.sales.repository.BaseItemRepository;
import com.rit.canteen.sales.repository.ProductRepository;
import com.rit.canteen.sales.repository.StallRepository;
import com.rit.canteen.sales.repository.SystemUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.List;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
@Component
public class DatabaseSeeder implements CommandLineRunner {
@@ -21,6 +27,15 @@ public class DatabaseSeeder implements CommandLineRunner {
@Autowired
private ProductRepository productRepository;
@Autowired
private StallRepository stallRepository;
@Autowired
private SystemUserRepository systemUserRepository;
@Autowired
private BCryptPasswordEncoder passwordEncoder;
@Autowired
private JdbcTemplate jdbcTemplate;
@@ -34,6 +49,8 @@ public class DatabaseSeeder implements CommandLineRunner {
repairLobColumns();
seedCategories();
seedProducts();
seedStalls();
seedMasterUser();
}
private void repairFeedbackSchema() {
@@ -254,4 +271,42 @@ public class DatabaseSeeder implements CommandLineRunner {
p.setActive(true);
return p;
}
private void seedStalls() {
if (stallRepository.count() == 0) {
List<Product> allProducts = productRepository.findAll();
Stall s1 = new Stall("Main Canteen Stall", "Primary food counter serving meals, fast food, and beverages", null);
Stall s2 = new Stall("Bakery & Juice Counter", "Fresh bakery items, pastries, snacks, and fresh fruit juices", null);
Stall s3 = new Stall("South Indian Express", "Authentic dosas, idlis, vadas, and South Indian breakfast specials", null);
s1.setProducts(allProducts);
s2.setProducts(allProducts.stream()
.filter(p -> "Bakery & Sweets".equalsIgnoreCase(p.getCategory()) || "Beverages & Drinks".equalsIgnoreCase(p.getCategory()) || "Snacks & Quick Bites".equalsIgnoreCase(p.getCategory()))
.toList());
s3.setProducts(allProducts.stream()
.filter(p -> "Snacks & Quick Bites".equalsIgnoreCase(p.getCategory()) || "Indian Main Course".equalsIgnoreCase(p.getCategory()))
.toList());
stallRepository.saveAll(List.of(s1, s2, s3));
System.out.println(">>> SEEDED DEFAULT STALLS (Main Canteen, Bakery & Juice Counter, South Indian Express)");
}
}
private void seedMasterUser() {
Optional<SystemUser> existingAdmin = systemUserRepository.findByEmail("admin");
if (existingAdmin.isEmpty()) {
SystemUser admin = new SystemUser();
admin.setName("Admin Master");
admin.setEmail("admin");
admin.setPassword(passwordEncoder.encode("admin"));
admin.setRole("MASTER");
admin.setPermissions(List.of("dashboard", "sale", "customers", "purchases", "inventory", "expense", "reports", "stores", "table", "wallet", "promotions", "feedback"));
admin.setViewOnly(false);
systemUserRepository.save(admin);
System.out.println(">>> SEEDED ADMIN MASTER USER (username: admin, password: admin)");
} else {
System.out.println(">>> ADMIN MASTER USER EXISTS. Skipping admin user creation.");
}
}
}

View File

@@ -27,7 +27,7 @@ app.jwt.expiration-ms=86400000
# Master Account — REQUIRED environment variables
# ============================================================
app.master.username=${MASTER_USER:admin}
app.master.password=${MASTER_PASSWORD:admin123}
app.master.password=${MASTER_PASSWORD:admin}
# File upload configuration
spring.servlet.multipart.max-file-size=10MB