diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureService.java b/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureService.java index fac837d..fded3dc 100644 --- a/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureService.java +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureService.java @@ -22,14 +22,16 @@ public interface LectureService { List findAllLecture(); String getUserStatus(Long userId, Lecture lecture); - + LectureDetailResponse findLectureById(Long userId, long lectureId); List findMyLecture(long userId); Lecture findLectureByTitle(String title); - void changeState(Long lectureId); + void startClass(Long lectureId); + + void stopClass(Long lectureId); boolean getState(Long lectureId); diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureServiceImpl.java index 29e26ad..c434f54 100644 --- a/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/service/LectureServiceImpl.java @@ -225,7 +225,7 @@ public class LectureServiceImpl implements LectureService { } @Override - public void changeState(Long id) { + public void startClass(Long id) { Optional lecture = lectureRepository.findById(id); @@ -245,6 +245,26 @@ public class LectureServiceImpl implements LectureService { lectureRepository.save(l); } + @Override + public void stopClass(Long id) { + Optional lecture = lectureRepository.findById(id); + + + if (!lecture.isPresent()) { + throw new RuntimeException("Lecture not found with id: " + id); + + } + + Lecture l; + l = lecture.get(); + if (l.isOnline()) { + l.setOnline(false); + } + + + lectureRepository.save(l); + } + @Override public boolean getState(Long lectureId) { diff --git a/backend/src/main/java/com/edufocus/edufocus/video/controller/Controller.java b/backend/src/main/java/com/edufocus/edufocus/video/controller/Controller.java index cc7bb6c..efb4a64 100644 --- a/backend/src/main/java/com/edufocus/edufocus/video/controller/Controller.java +++ b/backend/src/main/java/com/edufocus/edufocus/video/controller/Controller.java @@ -136,6 +136,26 @@ public class Controller { } + + @PostMapping(value = "/deleteroom/{lecture_id}") + public ResponseEntity> deleteRooom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception { + String userToken = request.getHeader("Authorization"); + Long userId = Long.parseLong(jwtUtil.getUserId(userToken)); + + User findUser = userRepository.findById(userId).orElse(null); + if (findUser.getRole() == UserRole.ADMIN) { + + + videoSertvice.startOnline(userId, id); + + + } + + return ResponseEntity.ok(Map.of("token", " ")); + + } + + @PostMapping(value = "/livekit/webhook", consumes = "application/webhook+json") public ResponseEntity receiveWebhook(@RequestHeader("Authorization") String authHeader, @RequestBody String body) { WebhookReceiver webhookReceiver = new WebhookReceiver(LIVEKIT_API_KEY, LIVEKIT_API_SECRET); diff --git a/backend/src/main/java/com/edufocus/edufocus/video/service/VideoServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/video/service/VideoServiceImpl.java index 110de11..ce948a3 100644 --- a/backend/src/main/java/com/edufocus/edufocus/video/service/VideoServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/video/service/VideoServiceImpl.java @@ -24,12 +24,12 @@ public class VideoServiceImpl implements VideoSertvice { @Override public void startOnline(Long userId, Long lectureId) throws SQLException { - lectureService.changeState(lectureId); + lectureService.startClass(lectureId); } @Override public void stopOnline(Long userId, Long lectureId) throws SQLException { - lectureService.changeState(lectureId); + lectureService.startClass(lectureId); } @Override