feat : 수강신청 도메인 구성

This commit is contained in:
donghyeon-ka
2026-09-18 15:20:54 +09:00
parent 3e33388e02
commit 70d71008c6
61 changed files with 2835 additions and 258 deletions
@@ -1,91 +1,121 @@
package com.study.course_registration.seeder;
import org.springframework.context.annotation.Profile;
import java.time.Clock;
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.study.course_registration.entity.Lesson;
import com.study.course_registration.entity.LessonSchedule;
import com.study.course_registration.entity.Professor;
import com.study.course_registration.entity.Semester;
import com.study.course_registration.entity.Subject;
import com.study.course_registration.entity.User;
import com.study.course_registration.entity.UserLesson;
import com.study.course_registration.enums.UserRole;
import com.study.course_registration.repository.LessonRepository;
import com.study.course_registration.repository.UserRepository;
import com.study.course_registration.repository.SubjectRepository;
import com.study.course_registration.repository.LessonScheduleRepository;
import com.study.course_registration.repository.ProfessorRepository;
import com.study.course_registration.repository.UserLessonRepository;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import org.springframework.boot.CommandLineRunner;
import com.study.course_registration.repository.SemesterRepository;
import com.study.course_registration.repository.SubjectRepository;
import com.study.course_registration.repository.UserRepository;
@Component
@Profile ("local")
@ConditionalOnProperty(name = "app.seed.enabled", havingValue = "true")
public class DataSeeder implements CommandLineRunner {
public static final String SEMESTER_ID = "00000000-0000-0000-0000-000000000001";
public static final String STUDENT_GRADE_1_ID = "30000000-0000-0000-0000-000000000001";
public static final String STUDENT_GRADE_2_ID = "30000000-0000-0000-0000-000000000002";
public static final String POSTGRADUATE_ID = "30000000-0000-0000-0000-000000000003";
public static final String DATA_STRUCTURES_01_ID = "40000000-0000-0000-0000-000000000001";
public static final String DATA_STRUCTURES_02_ID = "40000000-0000-0000-0000-000000000002";
public static final String OVERLAP_OS_ID = "40000000-0000-0000-0000-000000000003";
public static final String CAPACITY_ONE_ID = "40000000-0000-0000-0000-000000000004";
public static final String MIN_GRADE_ID = "40000000-0000-0000-0000-000000000005";
public static final String POSTGRADUATE_ONLY_ID = "40000000-0000-0000-0000-000000000006";
public static final String BOUNDARY_LESSON_ID = "40000000-0000-0000-0000-000000000007";
private static final ZoneId KST = ZoneId.of("Asia/Seoul");
private final UserRepository userRepository;
private final LessonRepository lessonRepository;
private final SubjectRepository subjectRepository;
private final Clock clock;
private final SemesterRepository semesterRepository;
private final ProfessorRepository professorRepository;
private final UserLessonRepository userLessonRepository;
private final SubjectRepository subjectRepository;
private final LessonRepository lessonRepository;
private final LessonScheduleRepository lessonScheduleRepository;
private final UserRepository userRepository;
public DataSeeder(UserRepository userRepository, LessonRepository lessonRepository, SubjectRepository subjectRepository, ProfessorRepository professorRepository, UserLessonRepository userLessonRepository) {
this.userRepository = userRepository;
this.lessonRepository = lessonRepository;
this.subjectRepository = subjectRepository;
public DataSeeder(Clock clock,
SemesterRepository semesterRepository,
ProfessorRepository professorRepository,
SubjectRepository subjectRepository,
LessonRepository lessonRepository,
LessonScheduleRepository lessonScheduleRepository,
UserRepository userRepository) {
this.clock = clock;
this.semesterRepository = semesterRepository;
this.professorRepository = professorRepository;
this.userLessonRepository = userLessonRepository;
this.subjectRepository = subjectRepository;
this.lessonRepository = lessonRepository;
this.lessonScheduleRepository = lessonScheduleRepository;
this.userRepository = userRepository;
}
@Override
@Transactional
public void run(String... args) throws Exception {
if(userRepository.count() > 0) {
public void run(String... args) {
if (semesterRepository.existsById(SEMESTER_ID)) {
return;
}
Instant now = clock.instant();
LocalDate today = LocalDate.now(clock);
Semester semester = semesterRepository.save(new Semester(
SEMESTER_ID, "2026-1", today.minusDays(30), today.plusDays(120),
now.minusSeconds(86_400), now.plusSeconds(7 * 86_400), 18));
List<Professor> professors = professorRepository.saveAll(List.of(
new Professor("김영한"),
new Professor("최태영"),
new Professor("조재한")
));
new Professor("10000000-0000-0000-0000-000000000001", "김영한"),
new Professor("10000000-0000-0000-0000-000000000002", "최태영"),
new Professor("10000000-0000-0000-0000-000000000003", "조재한")));
List<Subject> subjects = subjectRepository.saveAll(List.of(
new Subject("자바 프로그래밍", "CS201", "자바 프로그래밍 기초"),
new Subject("자료구조", "CS202", "자료구조 및 알고리즘"),
new Subject("데이터베이스", "CS203", "데이터베이스 시스템")
));
new Subject("20000000-0000-0000-0000-000000000001", "자바 프로그래밍", "CS201", "자바 프로그래밍 기초", 3),
new Subject("20000000-0000-0000-0000-000000000002", "자료구조", "CS202", "자료구조 및 알고리즘", 3),
new Subject("20000000-0000-0000-0000-000000000003", "데이터베이스", "CS203", "데이터베이스 시스템", 3),
new Subject("20000000-0000-0000-0000-000000000004", "컴퓨터 네트워크", "CS204", "네트워크 기초", 3),
new Subject("20000000-0000-0000-0000-000000000005", "운영체제", "CS301", "운영체제 핵심", 3),
new Subject("20000000-0000-0000-0000-000000000006", "대학원 세미나", "CS401", "대학원 전용 세미나", 3)));
Instant base = Instant.now().truncatedTo(ChronoUnit.HOURS);
List<Lesson> lessons = lessonRepository.saveAll(List.of(
new Lesson("자바 프로그래밍", subjects.get(0), professors.get(0), kst(3, 2, 9), kst(3, 2, 11)),
new Lesson("자료구조", subjects.get(1), professors.get(1), kst(3, 2, 13), kst(3, 2, 17)),
new Lesson("데이터베이스", subjects.get(2), professors.get(2), kst(3, 3, 10), kst(3, 3, 14))
));
Lesson data01 = new Lesson(DATA_STRUCTURES_01_ID, "자료구조 01분반", subjects.get(1), professors.get(0), semester, 30, null, null);
Lesson data02 = new Lesson(DATA_STRUCTURES_02_ID, "자료구조 02분반", subjects.get(1), professors.get(1), semester, 30, null, null);
Lesson os = new Lesson(OVERLAP_OS_ID, "운영체제", subjects.get(4), professors.get(1), semester, 30, null, null);
Lesson capacityOne = new Lesson(CAPACITY_ONE_ID, "데이터베이스 소수정예", subjects.get(2), professors.get(2), semester, 1, null, null);
Lesson minGrade = new Lesson(MIN_GRADE_ID, "고급 네트워크", subjects.get(3), professors.get(2), semester, 30, 3L, null);
Lesson postgraduate = new Lesson(POSTGRADUATE_ONLY_ID, "대학원 세미나", subjects.get(5), professors.get(0), semester, 20, null, UserRole.POSTGRADUATE);
Lesson boundary = new Lesson(BOUNDARY_LESSON_ID, "자바 프로그래밍", subjects.get(0), professors.get(0), semester, 30, null, null);
lessonRepository.saveAll(List.of(data01, data02, os, capacityOne, minGrade, postgraduate, boundary));
List<User> users = userRepository.saveAll(List.of(
new User("학생1", 1L, UserRole.STUDENT),
new User("학생2", 2L, UserRole.STUDENT),
new User("대학원생", 3L, UserRole.POSTGRADUATE)
));
lessonScheduleRepository.saveAll(List.of(
schedule("50000000-0000-0000-0000-000000000001", data01, DayOfWeek.MONDAY, 9, 11),
schedule("50000000-0000-0000-0000-000000000002", data02, DayOfWeek.TUESDAY, 9, 11),
schedule("50000000-0000-0000-0000-000000000003", os, DayOfWeek.MONDAY, 10, 12),
schedule("50000000-0000-0000-0000-000000000004", capacityOne, DayOfWeek.WEDNESDAY, 9, 11),
schedule("50000000-0000-0000-0000-000000000005", minGrade, DayOfWeek.THURSDAY, 9, 11),
schedule("50000000-0000-0000-0000-000000000006", postgraduate, DayOfWeek.FRIDAY, 9, 11),
schedule("50000000-0000-0000-0000-000000000007", boundary, DayOfWeek.MONDAY, 11, 13)));
List<UserLesson> userLessons = userLessonRepository.saveAll(List.of(
new UserLesson(users.get(0), lessons.get(0)),
new UserLesson(users.get(0), lessons.get(1)),
new UserLesson(users.get(1), lessons.get(1)),
new UserLesson(users.get(2), lessons.get(2))
));
userRepository.saveAll(List.of(
new User(STUDENT_GRADE_1_ID, "학생1", 1L, UserRole.STUDENT),
new User(STUDENT_GRADE_2_ID, "학생2", 2L, UserRole.STUDENT),
new User(POSTGRADUATE_ID, "대학원생", 3L, UserRole.POSTGRADUATE)));
}
private Instant kst(int month, int day, int hour) {
return ZonedDateTime.of(2026, month, day, hour, 0, 0, 0, KST).toInstant();
private static LessonSchedule schedule(String id, Lesson lesson, DayOfWeek day, int startHour, int endHour) {
return new LessonSchedule(id, lesson, day, LocalTime.of(startHour, 0), LocalTime.of(endHour, 0));
}
}