diff --git a/src/main/java/com/safetypin/authentication/seeder/DevDataSeeder.java b/src/main/java/com/safetypin/authentication/seeder/DevDataSeeder.java index 9edfd5733e8de30913b18061999376056bd7b174..e33c4f659450536ae7de1ad8c425cef83b322826 100644 --- a/src/main/java/com/safetypin/authentication/seeder/DevDataSeeder.java +++ b/src/main/java/com/safetypin/authentication/seeder/DevDataSeeder.java @@ -2,20 +2,13 @@ package com.safetypin.authentication.seeder; import com.safetypin.authentication.model.User; import com.safetypin.authentication.repository.UserRepository; -import org.springframework.boot.CommandLineRunner; -import org.springframework.context.annotation.Profile; import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Component; import java.time.LocalDate; -import java.util.List; -@Component -@Profile({"dev"}) // Runs only in 'dev' profile -public class DevDataSeeder implements CommandLineRunner { +public class DevDataSeeder implements Runnable { private final UserRepository userRepository; - private final PasswordEncoder passwordEncoder; public DevDataSeeder(UserRepository userRepository, PasswordEncoder passwordEncoder) { @@ -24,25 +17,53 @@ public class DevDataSeeder implements CommandLineRunner { } @Override - public void run(String... args) { + public void run() { + // Only seed if there are no users in the repository if (userRepository.count() == 0) { - userRepository.saveAll(List.of( - new User("alice@example.com", passwordEncoder.encode("password123"), "Alice Johnson", true, "developer", - LocalDate.of(1998, 5, 21), "EMAIL", "social_1001"), - new User("bob@example.com", passwordEncoder.encode("password456"), "Bob Smith", false, "designer", - LocalDate.of(2000, 8, 15), "GOOGLE", "social_1002"), - new User("charlie@example.com", passwordEncoder.encode("password789"), "Charlie Davis", true, "manager", - LocalDate.of(1995, 12, 3), "APPLE", "social_1003"), - new User("diana@example.com", passwordEncoder.encode("password321"), "Diana Roberts", true, "QA engineer", - LocalDate.of(2002, 6, 10), "EMAIL", "social_1004"), - new User("ethan@example.com", passwordEncoder.encode("password654"), "Ethan Brown", false, "data analyst", - LocalDate.of(1999, 11, 27), "EMAIL", "social_1005") - )); - System.out.println("Dummy users inserted in DEV environment"); - } else { - System.out.println("User repo is not empty"); - } + userRepository.save(new User("user1@example.com", + passwordEncoder.encode("password1"), + "User One", + true, + "user", + LocalDate.of(1990, 1, 1), + "EMAIL", + "social1")); + + userRepository.save(new User("user2@example.com", + passwordEncoder.encode("password2"), + "User Two", + true, + "user", + LocalDate.of(1991, 2, 2), + "EMAIL", + "social2")); + userRepository.save(new User("user3@example.com", + passwordEncoder.encode("password3"), + "User Three", + true, + "user", + LocalDate.of(1992, 3, 3), + "EMAIL", + "social3")); + userRepository.save(new User("user4@example.com", + passwordEncoder.encode("password4"), + "User Four", + true, + "user", + LocalDate.of(1993, 4, 4), + "EMAIL", + "social4")); + + userRepository.save(new User("user5@example.com", + passwordEncoder.encode("password5"), + "User Five", + true, + "user", + LocalDate.of(1994, 5, 5), + "EMAIL", + "social5")); + } } -} \ No newline at end of file +}