diff --git a/EduManager/src/main/java/controller/lecture/ViewLectureController.java b/EduManager/src/main/java/controller/lecture/ViewLectureController.java index b09148e..f821a29 100644 --- a/EduManager/src/main/java/controller/lecture/ViewLectureController.java +++ b/EduManager/src/main/java/controller/lecture/ViewLectureController.java @@ -53,6 +53,8 @@ public String execute(HttpServletRequest request, HttpServletResponse response) boolean isConflict = lectureManager. isLectureConflict(stuId, lectureId); // 인스턴스를 통해 호출 request.setAttribute("isConflict", isConflict); + int availableSeats = lectureManager.getAvailableSeatsByLectureId(lectureId); + request.setAttribute("availableSeats", availableSeats); // 로그인한 사용자 ID를 request에 저장 request.setAttribute("userId", MemberSessionUtils.getLoginMemberId(request.getSession())); diff --git a/EduManager/src/main/java/controller/studyGroup/ViewStudyGroupController.java b/EduManager/src/main/java/controller/studyGroup/ViewStudyGroupController.java index 4e6a99e..0a3cef7 100644 --- a/EduManager/src/main/java/controller/studyGroup/ViewStudyGroupController.java +++ b/EduManager/src/main/java/controller/studyGroup/ViewStudyGroupController.java @@ -68,6 +68,9 @@ public String execute(HttpServletRequest request, HttpServletResponse response) System.out.println("요청 상태: "+ requestStatus); request.setAttribute("requestStatus", requestStatus); + int studyAvailableSeats = manager.getAvailableSeatsByStudyGroupId(groupId); + request.setAttribute("studyAvailableSeats",studyAvailableSeats); + // 강의 상세 페이지로 이동 return "/study/study_overview.jsp"; } diff --git a/EduManager/src/main/java/model/dao/lecture/LectureDao.java b/EduManager/src/main/java/model/dao/lecture/LectureDao.java index e3597ce..1a47cc6 100644 --- a/EduManager/src/main/java/model/dao/lecture/LectureDao.java +++ b/EduManager/src/main/java/model/dao/lecture/LectureDao.java @@ -627,5 +627,25 @@ public List findMonthSchedule(int lectureId, int month, int year) { return null; } + public int getAvailableSeatsByLectureId(long lectureId) { + String sql = "SELECT (l.CAPACITY - COUNT(le.ENROLLMENTID)) AS AVAILABLE_SEATS " + + "FROM LECTURE l " + + "LEFT JOIN LECTUREENROLLMENT le ON l.LECTUREID = le.LECTUREID " + + "WHERE l.LECTUREID = ? " + + "GROUP BY l.CAPACITY"; + jdbcUtil.setSqlAndParameters(sql, new Object[] { lectureId }); // SQL과 파라미터 설정 + try { + ResultSet rs = jdbcUtil.executeQuery(); // 쿼리 실행 + if (rs.next()) { + return rs.getInt("AVAILABLE_SEATS"); // 잔여 좌석 수 반환 + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + jdbcUtil.close(); // 자원 해제 + } + return -1; // 강의가 없거나 에러 발생 시 -1 반환 + } + } diff --git a/EduManager/src/main/java/model/dao/studygroup/StudyGroupDao.java b/EduManager/src/main/java/model/dao/studygroup/StudyGroupDao.java index 4cd465b..2df502f 100644 --- a/EduManager/src/main/java/model/dao/studygroup/StudyGroupDao.java +++ b/EduManager/src/main/java/model/dao/studygroup/StudyGroupDao.java @@ -741,4 +741,27 @@ WHEN EXISTS ( jdbcUtil.close(); // 리소스 해제 } } + + + public int getAvailableSeatsByStudyGroupId(long studyGroupId) { + String sql = "SELECT (sg.capacity - COUNT(sga.studygroupapplicationid)) AS available_seats " + + "FROM studygroup sg " + + "LEFT JOIN studygroupapplication sga " + + "ON sg.studygroupid = sga.studygroupid AND sga.status = '수락' " + + "WHERE sg.studygroupid = ? " + + "GROUP BY sg.capacity"; + jdbcUtil.setSqlAndParameters(sql, new Object[] { studyGroupId }); // SQL과 파라미터 설정 + try { + ResultSet rs = jdbcUtil.executeQuery(); // 쿼리 실행 + if (rs.next()) { + return rs.getInt("available_seats"); // 잔여 좌석 수 반환 + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + jdbcUtil.close(); // 자원 해제 + } + return -1; // 스터디 그룹이 없거나 에러 발생 시 -1 반환 + } + } \ No newline at end of file diff --git a/EduManager/src/main/java/model/domain/lecture/LectureAvailability.java b/EduManager/src/main/java/model/domain/lecture/LectureAvailability.java new file mode 100644 index 0000000..3dbffc7 --- /dev/null +++ b/EduManager/src/main/java/model/domain/lecture/LectureAvailability.java @@ -0,0 +1,53 @@ +package model.domain.lecture; + +public class LectureAvailability { + private long lectureId; // 강의 ID + private String name; // 강의 이름 + private int availableSeats; // 잔여 좌석 수 + + // 기본 생성자 + public LectureAvailability() { + } + + // 매개변수 있는 생성자 + public LectureAvailability(long lectureId, String name, int availableSeats) { + this.lectureId = lectureId; + this.name = name; + this.availableSeats = availableSeats; + } + + // Getter 및 Setter + public long getLectureId() { + return lectureId; + } + + public void setLectureId(long lectureId) { + this.lectureId = lectureId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAvailableSeats() { + return availableSeats; + } + + public void setAvailableSeats(int availableSeats) { + this.availableSeats = availableSeats; + } + + // toString 메서드 (디버깅 및 로깅 용도) + @Override + public String toString() { + return "LectureAvailability{" + + "lectureId=" + lectureId + + ", name='" + name + '\'' + + ", availableSeats=" + availableSeats + + '}'; + } +} diff --git a/EduManager/src/main/java/model/domain/studyGroup/StudyGroupAvailability.java b/EduManager/src/main/java/model/domain/studyGroup/StudyGroupAvailability.java new file mode 100644 index 0000000..9fbc5eb --- /dev/null +++ b/EduManager/src/main/java/model/domain/studyGroup/StudyGroupAvailability.java @@ -0,0 +1,53 @@ +package model.domain.studyGroup; + +public class StudyGroupAvailability { + private long studyGroupId; // 강의 ID + private String name; // 강의 이름 + private int availableSeats; // 잔여 좌석 수 + + // 기본 생성자 + public StudyGroupAvailability() { + } + + // 매개변수 있는 생성자 + public StudyGroupAvailability(long studyGroupId, String name, int availableSeats) { + this.studyGroupId = studyGroupId; + this.name = name; + this.availableSeats = availableSeats; + } + + // Getter 및 Setter + public long getStudyGroupId() { + return studyGroupId; + } + + public void setStudyGroupId(long studyGroupId) { + this.studyGroupId = studyGroupId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAvailableSeats() { + return availableSeats; + } + + public void setAvailableSeats(int availableSeats) { + this.availableSeats = availableSeats; + } + + // toString 메서드 (디버깅 및 로깅 용도) + @Override + public String toString() { + return "LectureAvailability{" + + "lectureId=" + studyGroupId + + ", name='" + name + '\'' + + ", availableSeats=" + availableSeats + + '}'; + } +} diff --git a/EduManager/src/main/java/model/service/LectureManager.java b/EduManager/src/main/java/model/service/LectureManager.java index 5064cf9..ea4db58 100644 --- a/EduManager/src/main/java/model/service/LectureManager.java +++ b/EduManager/src/main/java/model/service/LectureManager.java @@ -22,208 +22,210 @@ import java.time.LocalDate; public class LectureManager { - private static LectureManager instance = new LectureManager(); - private LectureDao lectureDao; - private LectureScheduleDao scheduleDao; - private LectureNoticeDao noticeDao; - private LectureAssignmentDao assignmentDao; - private LectureLikeDao lectureLikeDao; - private LectureReviewDao lectureReviewDao; - - private LectureManager() { - lectureDao = new LectureDao(); - scheduleDao = new LectureScheduleDao(); - noticeDao = new LectureNoticeDao(); - assignmentDao = new LectureAssignmentDao(); - lectureLikeDao = new LectureLikeDao(); - lectureReviewDao = new LectureReviewDao(); - - } - - public static LectureManager getInstance() { - return instance; - } - - /* - * public List findLectureList() throws SQLException{ return - * lectureDao.getAllLectures(); } - */ - // 특정 연도와 월의 데이터를 캘린더에 띄우기 - public List getScheduleCalendarList(int year, int month) { - - List schedules = scheduleDao.findSchedulesByDate(year, month); - - return schedules; - } - - public List getNoticeCalendarList(int year, int month) { - - List notices = noticeDao.findNoticesByDate(year, month); - - return notices; - } - - public List getAssignmentCalendarList(int year, int month) { - - List assignments = assignmentDao.findAssignmentsByDate(year, month); - - return assignments; - } - - public Lecture findLectureById(long lectureId) throws SQLException { - return lectureDao.findLectureById(lectureId); - } - - public Lecture createLecture(Lecture lecture) throws SQLException { - return lectureDao.createLecture(lecture); - } - - public int updateLecture(Lecture lecture) throws SQLException {// , LectureNotFoundException { - return lectureDao.updateLecture(lecture); - } - - public Lecture getLectureById(long lectureId) throws SQLException { - return lectureDao.getLectureById(lectureId); - } - - public List getLecturesExcludingStudent(String stuId) throws SQLException { - return lectureDao.getLecturesExcludingStudent(stuId); - } - - public List getLecturesSearch(String stuId, String searchName) throws SQLException { - return lectureDao.getLecturesSearch(stuId, searchName); - } - - public List MyLectureList(String stuId) throws SQLException { - return lectureDao.getMyLectureList(stuId); - } - - public List getMyLectureListByTeacher(String teacherId) { - return lectureDao.getMyLectureListByTeacher(teacherId); - } - - public boolean isLikedByUser(String memberId, long lectureId) throws SQLException { - return lectureLikeDao.isLikedByUser(memberId, lectureId); - } - - public void toggleLectureLike(String memberId, long lectureId) throws SQLException { - boolean isLiked = isLikedByUser(memberId, lectureId); - if (isLiked) { - // 좋아요가 있다면 삭제 - lectureLikeDao.removeLike(memberId, lectureId); - } else { - // 좋아요가 없다면 추가 - lectureLikeDao.addLike(memberId, lectureId); - } - } - - public List LectureLikeList(String stuId) throws SQLException { - return lectureLikeDao.getLikedLectures(stuId); - } - - // 현재 수강중인 강의인지 확인 - public boolean isEnrolledInLecture(String memberId, long lectureId) throws SQLException { - return lectureReviewDao.isEnrolledInLecture(memberId, lectureId); - } - - // 강의 후기 작성 - public LectureReview createLectureReview(LectureReview lectureReview) throws SQLException { - return lectureReviewDao.insertReview(lectureReview); - } - - // 강의 후기 가져오기 - public List getReviewsByLectureId(Long lectureId) throws SQLException { - return lectureReviewDao.getReviewsByLectureId(lectureId); - } + private static LectureManager instance = new LectureManager(); + private LectureDao lectureDao; + private LectureScheduleDao scheduleDao; + private LectureNoticeDao noticeDao; + private LectureAssignmentDao assignmentDao; + private LectureLikeDao lectureLikeDao; + private LectureReviewDao lectureReviewDao; + + private LectureManager() { + lectureDao = new LectureDao(); + scheduleDao = new LectureScheduleDao(); + noticeDao = new LectureNoticeDao(); + assignmentDao = new LectureAssignmentDao(); + lectureLikeDao = new LectureLikeDao(); + lectureReviewDao = new LectureReviewDao(); - // 정기 일정 - public int createSchedule(Schedule schedule) throws SQLException { - return scheduleDao.createSchedule(schedule); - } + } + + public static LectureManager getInstance() { + return instance; + } + + /* + * public List findLectureList() throws SQLException{ return + * lectureDao.getAllLectures(); } + */ + // 특정 연도와 월의 데이터를 캘린더에 띄우기 + public List getScheduleCalendarList(int year, int month) { + + List schedules = scheduleDao.findSchedulesByDate(year, month); + + return schedules; + } + + public List getNoticeCalendarList(int year, int month) { + + List notices = noticeDao.findNoticesByDate(year, month); + + return notices; + } + + public List getAssignmentCalendarList(int year, int month) { + + List assignments = assignmentDao.findAssignmentsByDate(year, month); + + return assignments; + } + + public Lecture findLectureById(long lectureId) throws SQLException { + return lectureDao.findLectureById(lectureId); + } + + public Lecture createLecture(Lecture lecture) throws SQLException { + return lectureDao.createLecture(lecture); + } + + public int updateLecture(Lecture lecture) throws SQLException {// , LectureNotFoundException { + return lectureDao.updateLecture(lecture); + } + + public Lecture getLectureById(long lectureId) throws SQLException { + return lectureDao.getLectureById(lectureId); + } + + public List getLecturesExcludingStudent(String stuId) throws SQLException { + return lectureDao.getLecturesExcludingStudent(stuId); + } + + public List getLecturesSearch(String stuId, String searchName) throws SQLException { + return lectureDao.getLecturesSearch(stuId, searchName); + } - public List findScheduleById(long lectureId) throws SQLException { - return scheduleDao.findSchedulesBylectureId(lectureId); - } + public List MyLectureList(String stuId) throws SQLException { + return lectureDao.getMyLectureList(stuId); + } - public void updateSchedule(Schedule schedule) throws SQLException { - scheduleDao.updateSchedule(schedule); - } + public List getMyLectureListByTeacher(String teacherId) { + return lectureDao.getMyLectureListByTeacher(teacherId); + } - public List findScheduleIdsBylectureId(long lectureId) throws SQLException { - return scheduleDao.findScheduleIdsBylectureId(lectureId); - } + public boolean isLikedByUser(String memberId, long lectureId) throws SQLException { + return lectureLikeDao.isLikedByUser(memberId, lectureId); + } - public void deleteScheduleById(int scheduleId) { - scheduleDao.deleteScheduleById(scheduleId); - } + public void toggleLectureLike(String memberId, long lectureId) throws SQLException { + boolean isLiked = isLikedByUser(memberId, lectureId); + if (isLiked) { + // 좋아요가 있다면 삭제 + lectureLikeDao.removeLike(memberId, lectureId); + } else { + // 좋아요가 없다면 추가 + lectureLikeDao.addLike(memberId, lectureId); + } + } - // 수강 신청 - - public LectureEnrollment createLectureEnrollment(String memberId, long lectureId) throws SQLException { - return lectureDao.createLectureEnrollment(memberId, lectureId); - } - - public boolean isLectureConflict(String memberId, long lectureId) throws SQLException { - return lectureDao.isLectureConflict(memberId, lectureId); - } - - public boolean isLectureConflict(String teacherId, String newDayOfWeek, LocalTime newStartTime, - LocalTime newEndTime) throws SQLException { - return lectureDao.isLectureConflict(teacherId, newDayOfWeek, newStartTime, newEndTime); - } - - public boolean isEnrollmentExists(String memberId, long lectureId) throws SQLException { - return lectureDao.isEnrollmentExists(memberId, lectureId); - } - - // 스터디 과제 목록 조회(특정 날짜) - public List findAssignmentsByLectureIdAndDueDate(int lectureId, LocalDate dueDate) { - return assignmentDao.findAssignmentsByLectureIdAndDueDate(lectureId, dueDate); - } - - // 스터디 공지 목록 조회(특정 날짜) - public List findNoticesByLectureIdAndDate(int lectureId, LocalDate createdAt) { - return noticeDao.findNoticesByLectureIdAndDate(lectureId, createdAt); - } - - // 스터디 일정 목록 조회 - public List findSchedulesByFilters(long lectureId, LocalDate startDate, String type, String dayOfWeek) { - return scheduleDao.findSchedulesByFilters(lectureId, startDate, type, dayOfWeek); - } + public List LectureLikeList(String stuId) throws SQLException { + return lectureLikeDao.getLikedLectures(stuId); + } + + // 현재 수강중인 강의인지 확인 + public boolean isEnrolledInLecture(String memberId, long lectureId) throws SQLException { + return lectureReviewDao.isEnrolledInLecture(memberId, lectureId); + } + + // 강의 후기 작성 + public LectureReview createLectureReview(LectureReview lectureReview) throws SQLException { + return lectureReviewDao.insertReview(lectureReview); + } + + // 강의 후기 가져오기 + public List getReviewsByLectureId(Long lectureId) throws SQLException { + return lectureReviewDao.getReviewsByLectureId(lectureId); + } + + // 정기 일정 + public int createSchedule(Schedule schedule) throws SQLException { + return scheduleDao.createSchedule(schedule); + } + + public List findScheduleById(long lectureId) throws SQLException { + return scheduleDao.findSchedulesBylectureId(lectureId); + } + + public void updateSchedule(Schedule schedule) throws SQLException { + scheduleDao.updateSchedule(schedule); + } + + public List findScheduleIdsBylectureId(long lectureId) throws SQLException { + return scheduleDao.findScheduleIdsBylectureId(lectureId); + } + + public void deleteScheduleById(int scheduleId) { + scheduleDao.deleteScheduleById(scheduleId); + } + + // 수강 신청 + + public LectureEnrollment createLectureEnrollment(String memberId, long lectureId) throws SQLException { + return lectureDao.createLectureEnrollment(memberId, lectureId); + } + + public boolean isLectureConflict(String memberId, long lectureId) throws SQLException { + return lectureDao.isLectureConflict(memberId, lectureId); + } + + public boolean isLectureConflict(String teacherId, String newDayOfWeek, LocalTime newStartTime, + LocalTime newEndTime) throws SQLException { + return lectureDao.isLectureConflict(teacherId, newDayOfWeek, newStartTime, newEndTime); + } + + public boolean isEnrollmentExists(String memberId, long lectureId) throws SQLException { + return lectureDao.isEnrollmentExists(memberId, lectureId); + } + + // 스터디 과제 목록 조회(특정 날짜) + public List findAssignmentsByLectureIdAndDueDate(int lectureId, LocalDate dueDate) { + return assignmentDao.findAssignmentsByLectureIdAndDueDate(lectureId, dueDate); + } + + // 스터디 공지 목록 조회(특정 날짜) + public List findNoticesByLectureIdAndDate(int lectureId, LocalDate createdAt) { + return noticeDao.findNoticesByLectureIdAndDate(lectureId, createdAt); + } + + // 스터디 일정 목록 조회 + public List findSchedulesByFilters(long lectureId, LocalDate startDate, String type, String dayOfWeek) { + return scheduleDao.findSchedulesByFilters(lectureId, startDate, type, dayOfWeek); + } public List findNoticesByLectureId(int lectureId) { - return noticeDao.findNoticesByLectureId(lectureId); + return noticeDao.findNoticesByLectureId(lectureId); } - + public List searchNotices(int lectureId, String searchParam) { return noticeDao.searchNotices(lectureId, searchParam); } - + public List findAssignmentsByLectureId(int lectureId) { return assignmentDao.findAssignmentsByLectureId(lectureId); } + // 스터디 공지 추가 + public void createNotice(Notice notice) { + noticeDao.createNotice(notice.getLectureId(), notice.getTitle(), notice.getDescription(), notice.getCreateat()); + } - // 스터디 공지 추가 - public void createNotice(Notice notice) { - noticeDao.createNotice(notice.getLectureId(), notice.getTitle(), notice.getDescription(), notice.getCreateat()); - } - - public void createAssignment(Assignment ass) { - assignmentDao.createAssignment(ass.getLectureId(), ass.getTitle(), ass.getDescription(), ass.getDueDate(), ""); - } + public void createAssignment(Assignment ass) { + assignmentDao.createAssignment(ass.getLectureId(), ass.getTitle(), ass.getDescription(), ass.getDueDate(), ""); + } - // 스터디 멤버 조회 - public List findLectureMembers(int lectureId) throws SQLException { - return lectureDao.findLectureMembers(lectureId); + // 스터디 멤버 조회 + public List findLectureMembers(int lectureId) throws SQLException { + return lectureDao.findLectureMembers(lectureId); - } + } - // 월 단위 일정 유무 확인. - public List findMonthSchedule(int lectureId, int month, int year) throws SQLException { - return lectureDao.findMonthSchedule(lectureId, month, year); + // 월 단위 일정 유무 확인. + public List findMonthSchedule(int lectureId, int month, int year) throws SQLException { + return lectureDao.findMonthSchedule(lectureId, month, year); - } + } + public int getAvailableSeatsByLectureId(long lectureId) { + return lectureDao.getAvailableSeatsByLectureId(lectureId); + } } diff --git a/EduManager/src/main/java/model/service/StudyGroupManager.java b/EduManager/src/main/java/model/service/StudyGroupManager.java index d29d451..c85d5a8 100644 --- a/EduManager/src/main/java/model/service/StudyGroupManager.java +++ b/EduManager/src/main/java/model/service/StudyGroupManager.java @@ -112,6 +112,11 @@ public List< StudyGroupReview> getReviewsByGroupId(Long groupId) throws SQLExcep return studyGroupDao.getReviewsByGroupId(groupId); } + public int getAvailableSeatsByStudyGroupId(long studyGroupId) { + return studyGroupDao.getAvailableSeatsByStudyGroupId(studyGroupId); + } + + diff --git a/EduManager/src/main/webapp/WEB-INF/study/study_details.jsp b/EduManager/src/main/webapp/WEB-INF/study/study_details.jsp index 3b5fe2e..57bdaf1 100644 --- a/EduManager/src/main/webapp/WEB-INF/study/study_details.jsp +++ b/EduManager/src/main/webapp/WEB-INF/study/study_details.jsp @@ -66,7 +66,7 @@
members - 스터디원 (${fn:length(members) + 1}/${studyInfo.capacity}) + 스터디원 (${fn:length(members) + 1}/${studyInfo.capacity+1})
  • diff --git a/EduManager/src/main/webapp/WEB-INF/study/study_overview.jsp b/EduManager/src/main/webapp/WEB-INF/study/study_overview.jsp index 03e2407..7f67984 100644 --- a/EduManager/src/main/webapp/WEB-INF/study/study_overview.jsp +++ b/EduManager/src/main/webapp/WEB-INF/study/study_overview.jsp @@ -13,7 +13,7 @@ -
    스터디 그룹 가입
    +
    스터디그룹 가입
    @@ -70,8 +70,16 @@ - + + + + + + + +