From 22dd758f4bb3bd491ded36ed6b5653ae1e87649a Mon Sep 17 00:00:00 2001
From: KronosDP <darrel.danadyaksa19@gmail.com>
Date: Wed, 26 Feb 2025 14:51:53 +0700
Subject: [PATCH] [REFACTOR] Update DevDataSeeder to use Runnable interface and
 simplify user seeding logic

---
 .../authentication/seeder/DevDataSeeder.java  | 73 ++++++++++++-------
 1 file changed, 47 insertions(+), 26 deletions(-)

diff --git a/src/main/java/com/safetypin/authentication/seeder/DevDataSeeder.java b/src/main/java/com/safetypin/authentication/seeder/DevDataSeeder.java
index 9edfd57..e33c4f6 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
+}
-- 
GitLab