|
20 | 20 | import com.threestar.trainus.domain.coupon.user.repository.UserCouponRepository; |
21 | 21 | import com.threestar.trainus.domain.lesson.teacher.entity.Category; |
22 | 22 | 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; |
23 | 25 | import com.threestar.trainus.domain.lesson.teacher.repository.LessonRepository; |
24 | 26 | import com.threestar.trainus.domain.metadata.entity.ProfileMetadata; |
25 | 27 | import com.threestar.trainus.domain.metadata.mapper.ProfileMetadataMapper; |
@@ -50,6 +52,7 @@ public class MockDataInitializer implements CommandLineRunner { |
50 | 52 | private final PasswordEncoder passwordEncoder; |
51 | 53 | private final CouponRepository couponRepository; |
52 | 54 | private final UserCouponRepository userCouponRepository; |
| 55 | + private final LessonParticipantRepository lessonParticipantRepository; |
53 | 56 |
|
54 | 57 | private final Random random = new Random(); |
55 | 58 |
|
@@ -81,6 +84,9 @@ public void run(String... args) throws Exception { |
81 | 84 | // 6. 유저쿠폰 생성 (사용자들이 쿠폰 발급받은 데이터) |
82 | 85 | createUserCoupons(students, coupons); |
83 | 86 |
|
| 87 | + // 7. 레슨 참여자 생성 |
| 88 | + createLessonParticipants(students, lessons); |
| 89 | + |
84 | 90 | log.info("Mock 데이터 생성 완료!"); |
85 | 91 | log.info("생성된 데이터: 강사 {}명, 수강생 {}명, 레슨 {}개", |
86 | 92 | instructors.size(), students.size(), lessons.size()); |
@@ -364,6 +370,37 @@ private void createUserCoupons(List<User> students, List<Coupon> coupons) { |
364 | 370 | log.info("유저쿠폰 {}개 생성 완료", userCoupons.size()); |
365 | 371 | } |
366 | 372 |
|
| 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 | + |
367 | 404 | // 최소 주문 금액 생성 (10000-50000원, 5000원 단위) |
368 | 405 | private Integer generateMinOrderPrice() { |
369 | 406 | return (random.nextInt(9) + 2) * 5000; // 10000-50000원 |
|
0 commit comments