|
@@ -6,33 +6,71 @@ import org.springframework.beans.factory.annotation.Autowired;
|
6
|
6
|
import org.springframework.boot.CommandLineRunner;
|
7
|
7
|
import org.springframework.stereotype.Component;
|
8
|
8
|
|
|
9
|
+import rocks.zipcode.weblogg.model.Comment;
|
9
|
10
|
import rocks.zipcode.weblogg.model.Post;
|
|
11
|
+import rocks.zipcode.weblogg.model.User;
|
10
|
12
|
|
11
|
13
|
@Component
|
12
|
14
|
public class PostCLR implements CommandLineRunner {
|
13
|
|
- private static final Logger log = Logger.getLogger("PostCLR");
|
14
|
|
- @Autowired
|
15
|
|
- private PostRepository postRepo;
|
16
|
|
-
|
17
|
|
- @Override
|
18
|
|
- public void run(String...args) {
|
19
|
|
- log.info("-------------------------------");
|
20
|
|
- log.info("Adding Demo Posts.");
|
21
|
|
- log.info("-------------------------------");
|
22
|
|
- if (!postRepo.existsByTitle("Hello World!")) {
|
23
|
|
- Post tom = new Post("Hello World!", "It's great to be here. Wonderful, really.");
|
24
|
|
- postRepo.save(tom);
|
25
|
|
- }
|
26
|
|
- if (!postRepo.existsByTitle("Another Incredible!")) {
|
27
|
|
- Post tom = new Post("Another Incredible!", "It's great to be here. Wonderful, really.");
|
28
|
|
- postRepo.save(tom);
|
29
|
|
- }
|
|
15
|
+ private static final Logger log = Logger.getLogger("PostCLR");
|
|
16
|
+ @Autowired
|
|
17
|
+ private PostRepository postRepo;
|
30
|
18
|
|
31
|
|
- if (!postRepo.existsByTitle("Interesting Lorem!")) {
|
32
|
|
- Post tom = new Post("Interesting Lorem!", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
|
33
|
|
- postRepo.save(tom);
|
34
|
|
- }
|
|
19
|
+ @Autowired
|
|
20
|
+ private UserRepository userRepo;
|
|
21
|
+
|
|
22
|
+ @Autowired
|
|
23
|
+ private CommentRepository cmmtRepo;
|
|
24
|
+
|
|
25
|
+ @Override
|
|
26
|
+ public void run(String... args) {
|
|
27
|
+ User usr;
|
35
|
28
|
|
36
|
|
- }
|
|
29
|
+ log.info("-------------------------------");
|
|
30
|
+ log.info("Deleting all Demo data.");
|
|
31
|
+ log.info("-------------------------------");
|
|
32
|
+ cmmtRepo.deleteAllInBatch();
|
|
33
|
+ postRepo.deleteAllInBatch();
|
|
34
|
+ userRepo.deleteAllInBatch();
|
|
35
|
+
|
|
36
|
+ log.info("-------------------------------");
|
|
37
|
+ log.info("Adding Demo User.");
|
|
38
|
+ log.info("-------------------------------");
|
|
39
|
+ if (!userRepo.existsByUsername("anony@mous.coward")) {
|
|
40
|
+ // User(String username, String passwordHash, String fullName)
|
|
41
|
+ usr = new User("anony@mous.coward", "", "Anonymous Coward");
|
|
42
|
+ userRepo.save(usr);
|
|
43
|
+ } else {
|
|
44
|
+ usr = userRepo.findByUsername("anony@mous.coward");
|
|
45
|
+ }
|
|
46
|
+ log.info("-------------------------------");
|
|
47
|
+ log.info("Adding Demo Posts.");
|
|
48
|
+ log.info("-------------------------------");
|
|
49
|
+ if (!postRepo.existsByTitle("Hello World!")) {
|
|
50
|
+ Post tom = new Post("Hello World!", "It's great to be here. Wonderful, really.");
|
|
51
|
+ tom.setUser(usr);
|
|
52
|
+ usr.addPost(tom);
|
|
53
|
+ postRepo.save(tom);
|
|
54
|
+ Comment cmt = new Comment();
|
|
55
|
+ cmt.setText("amazing!");
|
|
56
|
+ cmt.setPost(tom);
|
|
57
|
+ cmmtRepo.save(cmt);
|
|
58
|
+ }
|
|
59
|
+ if (!postRepo.existsByTitle("Another Incredible!")) {
|
|
60
|
+ Post tom = new Post("Another Incredible!", "It's great to be here. Wonderful, really.");
|
|
61
|
+ usr.addPost(tom);
|
|
62
|
+ tom.setUser(usr);
|
|
63
|
+ postRepo.save(tom);
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ if (!postRepo.existsByTitle("Interesting Lorem!")) {
|
|
67
|
+ Post tom = new Post("Interesting Lorem!",
|
|
68
|
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
|
|
69
|
+ usr.addPost(tom);
|
|
70
|
+ tom.setUser(usr);
|
|
71
|
+ postRepo.save(tom);
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ }
|
37
|
75
|
|
38
|
76
|
}
|