-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMain.java
More file actions
63 lines (58 loc) · 2.19 KB
/
Main.java
File metadata and controls
63 lines (58 loc) · 2.19 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
52
53
54
55
56
57
58
59
60
61
62
63
package com.booleanuk;
import com.booleanuk.cohorts.models.*;
import com.booleanuk.cohorts.repository.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;
@SpringBootApplication
public class Main implements CommandLineRunner {
@Autowired
private RoleRepository roleRepository;
@Autowired
private CohortRepository cohortRepository;
@Autowired
private UserRepository userRepository;
@Autowired
private ProfileRepository profileRepository;
@Autowired
private PostRepository postRepository;
@Autowired
PasswordEncoder encoder;
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
@Override
public void run(String... args) {
// Create a cohort.
Cohort cohort;
if (!this.cohortRepository.existsById(1)) {
cohort = this.cohortRepository.save(new Cohort());
} else {
cohort = this.cohortRepository.findById(1).orElse(null);
}
Role teacherRole;
if (!this.roleRepository.existsByName(ERole.ROLE_TEACHER)) {
teacherRole = this.roleRepository.save(new Role(ERole.ROLE_TEACHER));
} else {
teacherRole = this.roleRepository.findByName(ERole.ROLE_TEACHER).orElse(null);
}
Set<Role> teacherRoles = new HashSet<>();
teacherRoles.add(teacherRole);
Role studentRole;
if (!this.roleRepository.existsByName(ERole.ROLE_STUDENT)) {
studentRole = this.roleRepository.save(new Role(ERole.ROLE_STUDENT));
} else {
studentRole = this.roleRepository.findByName(ERole.ROLE_STUDENT).orElse(null);
}
Set<Role> studentRoles = new HashSet<>();
studentRoles.add(studentRole);
if (!this.roleRepository.existsByName(ERole.ROLE_ADMIN)) {
this.roleRepository.save(new Role(ERole.ROLE_ADMIN));
}
}
}