Skip to content

Commit 43a7136

Browse files
committed
feat: mock 데이터 lessonParticipant 추가
1 parent d76574a commit 43a7136

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/main/java/com/threestar/trainus/global/config/MockDataInitializer.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.threestar.trainus.domain.coupon.user.repository.UserCouponRepository;
2121
import com.threestar.trainus.domain.lesson.teacher.entity.Category;
2222
import com.threestar.trainus.domain.lesson.teacher.entity.Lesson;
23+
import com.threestar.trainus.domain.lesson.teacher.entity.LessonParticipant;
24+
import com.threestar.trainus.domain.lesson.teacher.repository.LessonParticipantRepository;
2325
import com.threestar.trainus.domain.lesson.teacher.repository.LessonRepository;
2426
import com.threestar.trainus.domain.metadata.entity.ProfileMetadata;
2527
import com.threestar.trainus.domain.metadata.mapper.ProfileMetadataMapper;
@@ -50,6 +52,7 @@ public class MockDataInitializer implements CommandLineRunner {
5052
private final PasswordEncoder passwordEncoder;
5153
private final CouponRepository couponRepository;
5254
private final UserCouponRepository userCouponRepository;
55+
private final LessonParticipantRepository lessonParticipantRepository;
5356

5457
private final Random random = new Random();
5558

@@ -81,6 +84,9 @@ public void run(String... args) throws Exception {
8184
// 6. 유저쿠폰 생성 (사용자들이 쿠폰 발급받은 데이터)
8285
createUserCoupons(students, coupons);
8386

87+
// 7. 레슨 참여자 생성
88+
createLessonParticipants(students, lessons);
89+
8490
log.info("Mock 데이터 생성 완료!");
8591
log.info("생성된 데이터: 강사 {}명, 수강생 {}명, 레슨 {}개",
8692
instructors.size(), students.size(), lessons.size());
@@ -364,6 +370,37 @@ private void createUserCoupons(List<User> students, List<Coupon> coupons) {
364370
log.info("유저쿠폰 {}개 생성 완료", userCoupons.size());
365371
}
366372

373+
// lessonParticipant 테이블에 데이터 삽입
374+
private void createLessonParticipants(List<User> students, List<Lesson> lessons) {
375+
List<LessonParticipant> participants = new ArrayList<>();
376+
Random rand = new Random();
377+
for (User student : students) {
378+
// 각 학생당 1~4개의 레슨 참여
379+
int joinCount = rand.nextInt(4) + 1;
380+
381+
Set<Long> joinedLessonIds = new HashSet<>();
382+
383+
for (int i = 0; i < joinCount; i++) {
384+
Lesson lesson = lessons.get(rand.nextInt(lessons.size()));
385+
386+
// 중복 참여 방지
387+
if (joinedLessonIds.contains(lesson.getId()))
388+
continue;
389+
joinedLessonIds.add(lesson.getId());
390+
391+
LessonParticipant participant = LessonParticipant.builder()
392+
.lesson(lesson)
393+
.user(student)
394+
.build();
395+
396+
participants.add(participant);
397+
}
398+
}
399+
400+
lessonParticipantRepository.saveAll(participants);
401+
log.info("레슨 참여자 {}명 생성 완료", participants.size());
402+
}
403+
367404
// 최소 주문 금액 생성 (10000-50000원, 5000원 단위)
368405
private Integer generateMinOrderPrice() {
369406
return (random.nextInt(9) + 2) * 5000; // 10000-50000원

0 commit comments

Comments
 (0)