Repository navigation
Expand file tree
/
Copy pathSeedData.java
More file actions
51 lines (40 loc) · 1.52 KB
/
Copy pathSeedData.java
File metadata and controls
51 lines (40 loc) · 1.52 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.lambdaschool.authenticatedusers;
import com.lambdaschool.authenticatedusers.model.Quote;
import com.lambdaschool.authenticatedusers.model.Role;
import com.lambdaschool.authenticatedusers.model.User;
import com.lambdaschool.authenticatedusers.model.UserRoles;
import com.lambdaschool.authenticatedusers.repository.RoleRepository;
import com.lambdaschool.authenticatedusers.repository.UserRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
@Transactional
@Component
public class SeedData implements CommandLineRunner
{
RoleRepository rolerepos;
UserRepository userrepos;
public SeedData(RoleRepository rolerepos, UserRepository userrepos)
{
this.rolerepos = rolerepos;
this.userrepos = userrepos;
}
@Override
public void run(String[] args) throws Exception
{
Role r1 = new Role("admin");
Role r2 = new Role("user");
ArrayList<UserRoles> admins = new ArrayList<>();
admins.add(new UserRoles(new User(), r1));
admins.add(new UserRoles(new User(), r2));
ArrayList<UserRoles> users = new ArrayList<>();
users.add(new UserRoles(new User(), r2));
rolerepos.save(r1);
rolerepos.save(r2);
User u1 = new User("barnbarn", "ILuvM4th!", users);
User u2 = new User("admin", "password", admins);
userrepos.save(u1);
userrepos.save(u2);
}
}