-
Notifications
You must be signed in to change notification settings - Fork 578
Expand file tree
/
Copy pathInitData.java
More file actions
146 lines (128 loc) · 4.78 KB
/
InitData.java
File metadata and controls
146 lines (128 loc) · 4.78 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package org.example.expert;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.example.expert.client.WeatherClient;
import org.example.expert.config.PasswordEncoder;
import org.example.expert.domain.comment.entity.Comment;
import org.example.expert.domain.comment.repository.CommentRepository;
import org.example.expert.domain.todo.entity.Todo;
import org.example.expert.domain.todo.repository.TodoRepository;
import org.example.expert.domain.user.entity.User;
import org.example.expert.domain.user.enums.UserRole;
import org.example.expert.domain.user.repository.UserRepository;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class InitData {
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder;
private final TodoRepository todoRepository;
private final WeatherClient weatherClient;
private final CommentRepository commentRepository;
@PostConstruct
public void init() {
String encodedPassword = passwordEncoder.encode("TestTest1");
UserRole userRole1 = UserRole.of("ADMIN");
UserRole userRole2 = UserRole.of("USER");
User newUser = new User(
"lee@seo.jun",
encodedPassword,
userRole1
);
User newUser1 = new User(
"lee@jun.beum",
encodedPassword,
userRole2
);
User savedUser = userRepository.save(newUser);
User savedUser1 = userRepository.save(newUser1);
String weather = weatherClient.getTodayWeather();
Todo newTodo = new Todo(
"TODO 테스트",
"TODO 내용인가요",
weather,
savedUser
);
Todo newTodo2 = new Todo(
"TODO 테스트",
"TODO 내용인가요",
weather,
savedUser
);
Todo newTodo3 = new Todo(
"TODO 테스트",
"TODO 내용인가요",
weather,
savedUser1
);
Todo newTodo4 = new Todo(
"TODO 테스트",
"TODO 내용인가요",
weather,
savedUser1
);
Todo newTodo5 = new Todo(
"TODO 테스트",
"TODO 내용인가요",
weather,
savedUser
);
Todo savedTodo = todoRepository.save(newTodo);
Todo savedTodo1 = todoRepository.save(newTodo2);
Todo savedTodo2 = todoRepository.save(newTodo3);
Todo savedTodo3 = todoRepository.save(newTodo4);
Todo savedTodo4 = todoRepository.save(newTodo5);
Comment newComment = new Comment(
"댓글 내용입니다.",
newUser,
savedTodo
);
Comment newComment1 = new Comment(
"댓글 내용입니다.",
newUser1,
savedTodo
);Comment newComment2 = new Comment(
"댓글 내용입니다.",
newUser1,
savedTodo
);Comment newComment3 = new Comment(
"댓글 내용입니다.",
newUser,
savedTodo2
);Comment newComment4 = new Comment(
"댓글 내용입니다.",
newUser,
savedTodo3
);Comment newComment5 = new Comment(
"댓글 내용입니다.",
newUser,
savedTodo4
);Comment newComment6 = new Comment(
"댓글 내용입니다.",
newUser,
savedTodo1
);Comment newComment7 = new Comment(
"댓글 내용입니다.",
newUser,
savedTodo
);Comment newComment8 = new Comment(
"댓글 내용입니다.",
newUser,
savedTodo
);Comment newComment9 = new Comment(
"댓글 내용입니다.",
newUser,
savedTodo
);
Comment savedComment = commentRepository.save(newComment);
Comment savedComment1 = commentRepository.save(newComment1);
Comment savedComment2 = commentRepository.save(newComment2);
Comment savedComment3 = commentRepository.save(newComment3);
Comment savedComment4 = commentRepository.save(newComment4);
Comment savedComment5 = commentRepository.save(newComment5);
Comment savedComment6 = commentRepository.save(newComment6);
Comment savedComment7 = commentRepository.save(newComment7);
Comment savedComment8 = commentRepository.save(newComment8);
Comment savedComment9 = commentRepository.save(newComment9);
}
}