feat: add role initializer
This commit is contained in:
parent
abc399860e
commit
c1a35325d6
@ -1,7 +1,11 @@
|
||||
package dev.gfxv.blps;
|
||||
|
||||
import dev.gfxv.blps.entity.Role;
|
||||
import dev.gfxv.blps.repository.RoleRepository;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
public class BlpsApplication {
|
||||
@ -10,4 +14,20 @@ public class BlpsApplication {
|
||||
SpringApplication.run(BlpsApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
CommandLineRunner initRoles(RoleRepository roleRepository) {
|
||||
return args -> {
|
||||
if (roleRepository.findByName("ROLE_USER").isEmpty()) {
|
||||
Role userRole = new Role();
|
||||
userRole.setName("ROLE_USER");
|
||||
roleRepository.save(userRole);
|
||||
}
|
||||
if (roleRepository.findByName("ROLE_MODERATOR").isEmpty()) {
|
||||
Role modRole = new Role();
|
||||
modRole.setName("ROLE_MODERATOR");
|
||||
roleRepository.save(modRole);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user