-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathRoleInitializer.java
More file actions
25 lines (21 loc) · 867 Bytes
/
RoleInitializer.java
File metadata and controls
25 lines (21 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.sopromadze.blogapi.utils;
import com.sopromadze.blogapi.model.role.Role;
import com.sopromadze.blogapi.model.role.RoleName;
import com.sopromadze.blogapi.repository.RoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class RoleInitializer implements CommandLineRunner {
@Autowired
private RoleRepository roleRepository;
public void run(String... args){
if(!roleRepository.existsByName(RoleName.ROLE_ADMIN)){
roleRepository.save(new Role(RoleName.ROLE_ADMIN));
}
if(!roleRepository.existsByName(RoleName.ROLE_USER)){
roleRepository.save(new Role(RoleName.ROLE_USER));
}
System.out.println("Role Initialized Successfully");
}
}