Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
20 changes: 20 additions & 0 deletions EduManager/src/main/java/model/dao/lecture/LectureDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,5 +627,25 @@ public List<LocalDate> 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 반환
}

}

23 changes: 23 additions & 0 deletions EduManager/src/main/java/model/dao/studygroup/StudyGroupDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 반환
}

}
Original file line number Diff line number Diff line change
@@ -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 +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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 +
'}';
}
}
Loading