Skip to content

Commit

Permalink
#7 [feat] 강의 등록 시 같은 요일, 같은 시간에 한 강사에게 중복 등록 불가하도록 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
soo01234 committed Mar 26, 2024
1 parent 4093196 commit 39f1223
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/src/domain/AmsApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,15 +548,26 @@ public void registerLecture() throws IOException {
String teacherId = "";
String teacherName = "";
boolean isTeacherExist = false;
boolean isExistLecture = adminService.isExistTeacher(teacherId);

// // 해당 시간에 이미 강의가 있는지 확인
// if (isExist) {
// System.out.println("강사가 이미 같은 요일과 같은 시간에 강의를 가지고 있습니다.");
// }

while (!isTeacherExist) {
System.out.print("[담당 강사 아이디]: ");
teacherId = scanner.nextLine();
isTeacherExist = adminService.isExistTeacher(teacherId);
//lectureRepository있으면,
// lectureRepository있으면,
// teacherFound = lectureRepository.isExist(teacherId);

if (isTeacherExist) {
// 해당 시간과 요일에 이미 강의가 있는지 확인
if (adminService.isExistSameTimeLecture(teacherId, day, time)) {
System.out.println("강사가 이미 같은 요일과 같은 시간에 강의를 가지고 있습니다.");
return;
}
teacherName = adminService.getTeacherName(teacherId);
adminService.registerLecture(name, day, time, teacherName, teacherId);
System.out.println("강의가 성공적으로 등록되었습니다!");
Expand Down
17 changes: 17 additions & 0 deletions src/src/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ public boolean isExistTeacher(String teacherId) {
return teacherRepository.isExist(teacherId);
}

// 동일한 요일, 시간의 강의가 존재하는지
public boolean isExistSameTimeLecture(String teacherId, int day, int time) throws IOException {
Teacher teacher = teacherRepository.findById(teacherId);

List<Lecture> lectureList = teacher.getLectureList();
if(lectureList.isEmpty()){
return false;
}
for (Lecture lecture : lectureList) {
if (lecture.getLectureDay() == day && lecture.getLectureTime() == time) {
return true;
}
}
return false;
}


//강사 아이디로 강사 이름반환
public String getTeacherName(String teacherId) throws IOException {

Expand Down

0 comments on commit 39f1223

Please sign in to comment.