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 65153a0..e8483d4 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 @@ -28,4 +28,5 @@ public interface LectureService { Lecture findLectureByTitle(String title); void changeState(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 90da51c..e770f55 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 @@ -239,5 +239,13 @@ public class LectureServiceImpl implements LectureService { lectureRepository.save(l); } + @Override + public boolean getState(Long lectureId) { + + Lecture lecture= lectureRepository.findById(lectureId).orElse(null); + return lecture.isOnline(); + + } + } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/exception/GlobalExceptionHandler.java b/backend/src/main/java/com/edufocus/edufocus/user/model/exception/GlobalExceptionHandler.java index 526e6ae..81042dc 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/exception/GlobalExceptionHandler.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/exception/GlobalExceptionHandler.java @@ -19,8 +19,6 @@ public class GlobalExceptionHandler { @ExceptionHandler(ExpriedTokenException.class) public ResponseEntity handleInvalidTokenException(ExpriedTokenException e) { - // 로그 남기기 (선택 사항) - // log.error("Invalid token", e); return new ResponseEntity<>(e.getMessage(), HttpStatus.UNAUTHORIZED); } 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 40b206a..1fe7492 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 @@ -4,6 +4,7 @@ import java.util.Map; import com.edufocus.edufocus.lecture.entity.Lecture; import com.edufocus.edufocus.lecture.entity.LectureDetailResponse; +import com.edufocus.edufocus.lecture.repository.LectureRepository; import com.edufocus.edufocus.lecture.service.LectureService; import com.edufocus.edufocus.registration.entity.RegistrationStatus; import com.edufocus.edufocus.registration.service.RegistrationService; @@ -37,6 +38,7 @@ public class Controller { private final VideoSertvice videoSertvice; private final RegistrationService registrationService; private final UserRepository userRepository; + private final LectureRepository lectureRepository; @Value("${livekit.api.key}") private String LIVEKIT_API_KEY; @@ -67,18 +69,37 @@ public class Controller { // } @PostMapping(value = "/makeroom/{lecture_id}") - public ResponseEntity> startLecture(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception { + public ResponseEntity startLecture(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception { + + + String userToken = request.getHeader("Authorization"); + Long userId = Long.parseLong(jwtUtil.getUserId(userToken)); + + + videoSertvice.startOnline(userId, id); + + return new ResponseEntity<>("방만들기 성공",HttpStatus.OK); + + } + + + @PostMapping(value = "/joinroom/{lecture_id}") + public ResponseEntity> joinRoom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception + { String userToken = request.getHeader("Authorization"); - log.info("userToekn : ", userToken); Long userId = Long.parseLong(jwtUtil.getUserId(userToken)); User findUser= userRepository.findById(userId).orElse(null); + Lecture lecture= lectureRepository.findById(id).orElse(null); - if(findUser.getRole()==UserRole.ADMIN) { - LectureDetailResponse lecture = lectureService.findLectureById(userId, id); + + + + if(findUser.getRole()==UserRole.ADMIN && lecture.isOnline() ) { + String roomName = lecture.getTitle(); @@ -96,9 +117,8 @@ public class Controller { return ResponseEntity.ok(Map.of("token", token.toJwt())); } - else if(findUser.getRole()==UserRole.STUDENT) + else if(findUser.getRole()==UserRole.STUDENT && lecture.isOnline() ) { - LectureDetailResponse lecture = lectureService.findLectureById(userId, id); String roomName = lecture.getTitle(); @@ -108,7 +128,8 @@ public class Controller { AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET); token.setName(participantName); token.setIdentity(participantName); - token.addGrants(new RoomJoin(true), new RoomName(roomName), new RoomCreate(true)); + token.addGrants(new RoomJoin(true), new RoomName(roomName)); + videoSertvice.startOnline(userId, id); @@ -119,48 +140,40 @@ public class Controller { return ResponseEntity.ok(Map.of("token", null)); +// String userToken = request.getHeader("Authorization"); +// +// Long userId = Long.parseLong(jwtUtil.getUserId(userToken)); +// LectureDetailResponse lecture= lectureService.findLectureById(userId,id); +// +// +// //RegistrationStatus registrationStatus = registrationService.isOnline(userId,id); +// +// if(registrationStatus==RegistrationStatus.ACCEPTED) +// { +// String roomName = lecture.getTitle(); +// String participantName = userService.getUserName(userId); +// +// +// AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET); +// token.setName(participantName); +// token.setIdentity(participantName); +// token.addGrants(new RoomJoin(true), new RoomName(roomName)); +// +// //videoSertvice.startOnline(userId,id); +// +// +// +// return ResponseEntity.ok(Map.of("token", token.toJwt())); +// } +// else{ +// return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Map.of("errorMessage", "Not accepted")); +// +// } + } - -// @PostMapping(value = "/joinroom/{lecture_id}") -// public ResponseEntity> joinRoom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception { -// -//// String userToken = request.getHeader("Authorization"); -//// -//// Long userId = Long.parseLong(jwtUtil.getUserId(userToken)); -//// LectureDetailResponse lecture= lectureService.findLectureById(userId,id); -//// -//// -//// //RegistrationStatus registrationStatus = registrationService.isOnline(userId,id); -//// -////// if(registrationStatus==RegistrationStatus.ACCEPTED) -////// { -//// String roomName = lecture.getTitle(); -//// String participantName = userService.getUserName(userId); -//// -//// -//// AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET); -//// token.setName(participantName); -//// token.setIdentity(participantName); -//// token.addGrants(new RoomJoin(true), new RoomName(roomName)); -//// -//// //videoSertvice.startOnline(userId,id); -//// -//// -//// -//// return ResponseEntity.ok(Map.of("token", token.toJwt())); -////// } -////// else{ -////// return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Map.of("errorMessage", "Not accepted")); -////// -////// } -//// -// -// -// } - @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);