Merge pull request #147 from TeamBNBN/BE/userinfo

BE/userinfo
This commit is contained in:
Jungmin 2024-07-31 10:38:12 +09:00 committed by GitHub
commit a98e2c73eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 67 additions and 47 deletions

View File

@ -28,4 +28,5 @@ public interface LectureService {
Lecture findLectureByTitle(String title);
void changeState(Long lectureId);
boolean getState(Long lectureId);
}

View File

@ -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();
}
}

View File

@ -19,8 +19,6 @@ public class GlobalExceptionHandler {
@ExceptionHandler(ExpriedTokenException.class)
public ResponseEntity<String> handleInvalidTokenException(ExpriedTokenException e) {
// 로그 남기기 (선택 사항)
// log.error("Invalid token", e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.UNAUTHORIZED);
}

View File

@ -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<Map<String, String>> startLecture(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception {
public ResponseEntity<String> 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<Map<String, String>> 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<Map<String, String>> 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<String> receiveWebhook(@RequestHeader("Authorization") String authHeader, @RequestBody String body) {
WebhookReceiver webhookReceiver = new WebhookReceiver(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);