Merge branch 'BE/userinfo' into 'backend'
feat: 강의 만들기/입장 로직 추가 See merge request s11-webmobile1-sub2/S11P12A701!36
This commit is contained in:
commit
3baad15fdd
@ -235,8 +235,14 @@ public class LectureServiceImpl implements LectureService {
|
|||||||
|
|
||||||
Lecture l;
|
Lecture l;
|
||||||
l = lecture.get();
|
l = lecture.get();
|
||||||
|
if(l.isOnline())
|
||||||
|
{
|
||||||
|
l.setOnline(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
l.setOnline(true);
|
l.setOnline(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
lectureRepository.save(l);
|
lectureRepository.save(l);
|
||||||
|
@ -41,6 +41,7 @@ public class Controller {
|
|||||||
private final RegistrationService registrationService;
|
private final RegistrationService registrationService;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final LectureRepository lectureRepository;
|
private final LectureRepository lectureRepository;
|
||||||
|
|
||||||
@Value("${livekit.api.key}")
|
@Value("${livekit.api.key}")
|
||||||
private String LIVEKIT_API_KEY;
|
private String LIVEKIT_API_KEY;
|
||||||
|
|
||||||
@ -48,53 +49,15 @@ public class Controller {
|
|||||||
private String LIVEKIT_API_SECRET;
|
private String LIVEKIT_API_SECRET;
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
/**
|
|
||||||
* @param params JSON object with roomName and participantName
|
|
||||||
* @return JSON object with the JWT token
|
|
||||||
*/
|
|
||||||
// @PostMapping(value = "/token")
|
|
||||||
// public ResponseEntity<Map<String, String>> createToken(@RequestBody Map<String, String> params) {
|
|
||||||
// String roomName = params.get("roomName");
|
|
||||||
// String participantName = params.get("participantName");
|
|
||||||
//
|
|
||||||
// if (roomName == null || participantName == null) {
|
|
||||||
// return ResponseEntity.badRequest().body(Map.of("errorMessage", "roomName and participantName are required"));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
|
||||||
// token.setName(participantName);
|
|
||||||
// token.setIdentity(participantName);
|
|
||||||
// token.addGrants(new RoomJoin(true), new RoomName(roomName));
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// return ResponseEntity.ok(Map.of("token", token.toJwt()));
|
|
||||||
// }
|
|
||||||
|
|
||||||
@PostMapping(value = "/makeroom/{lecture_id}")
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
public static String serializeIdentityData(IdentityData identityData) throws JsonProcessingException, JsonProcessingException {
|
public static String serializeIdentityData(IdentityData identityData) throws JsonProcessingException, JsonProcessingException {
|
||||||
return objectMapper.writeValueAsString(identityData);
|
return objectMapper.writeValueAsString(identityData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/joinroom/{lecture_id}")
|
@PostMapping(value = "/joinroom/{lecture_id}")
|
||||||
public ResponseEntity<Map<String, String>> joinRoom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception
|
public ResponseEntity<Map<String, String>> joinRoom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception {
|
||||||
{
|
|
||||||
|
|
||||||
// 방 조인할떄 고려해야할점
|
|
||||||
// 1. 신청됀 강의인지
|
|
||||||
// 2. 그 강의기 On인지
|
|
||||||
String userToken = request.getHeader("Authorization");
|
String userToken = request.getHeader("Authorization");
|
||||||
|
|
||||||
|
|
||||||
@ -103,12 +66,50 @@ public class Controller {
|
|||||||
Lecture lecture = lectureRepository.findById(id).orElse(null);
|
Lecture lecture = lectureRepository.findById(id).orElse(null);
|
||||||
|
|
||||||
|
|
||||||
Random random = new Random();
|
String roomName = lecture.getTitle();
|
||||||
|
String participantName = userService.getUserName(userId);
|
||||||
|
System.out.println(participantName);
|
||||||
|
|
||||||
System.out.println();
|
AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
||||||
int randomNumber = 10000 + random.nextInt(80000);
|
|
||||||
|
|
||||||
|
if (findUser.getRole() == UserRole.STUDENT) {
|
||||||
|
|
||||||
|
if (videoSertvice.isRoomAccessible(id, userId)) {
|
||||||
|
IdentityData identityData = new IdentityData(participantName, "학생");
|
||||||
|
String jsonIdentity = serializeIdentityData(identityData);
|
||||||
|
|
||||||
|
|
||||||
|
token.setIdentity(jsonIdentity);
|
||||||
|
token.setName(participantName);
|
||||||
|
|
||||||
|
token.addGrants(new RoomJoin(true), new RoomName(roomName));
|
||||||
|
|
||||||
|
|
||||||
|
return ResponseEntity.ok(Map.of("token", token.toJwt()));
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||||
|
.body(Map.of("error", "방에 들어갈 수 없습니다."));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return ResponseEntity.ok(Map.of("token", null));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = "/makeroom/{lecture_id}")
|
||||||
|
public ResponseEntity<Map<String, String>> makeRoom(@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);
|
||||||
|
Lecture lecture = lectureRepository.findById(id).orElse(null);
|
||||||
|
|
||||||
String randStr = String.valueOf(randomNumber);
|
|
||||||
|
|
||||||
String roomName = lecture.getTitle();
|
String roomName = lecture.getTitle();
|
||||||
String participantName = userService.getUserName(userId);
|
String participantName = userService.getUserName(userId);
|
||||||
@ -120,80 +121,25 @@ public class Controller {
|
|||||||
if (findUser.getRole() == UserRole.ADMIN) {//&& lecture.isOnline() ) {
|
if (findUser.getRole() == UserRole.ADMIN) {//&& lecture.isOnline() ) {
|
||||||
|
|
||||||
|
|
||||||
|
videoSertvice.startOnline(userId, id);
|
||||||
|
|
||||||
IdentityData identityData = new IdentityData(participantName, "강사");
|
IdentityData identityData = new IdentityData(participantName, "강사");
|
||||||
String jsonIdentity = serializeIdentityData(identityData);
|
String jsonIdentity = serializeIdentityData(identityData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
token.setIdentity(jsonIdentity);
|
token.setIdentity(jsonIdentity);
|
||||||
token.setName(participantName);
|
token.setName(participantName);
|
||||||
|
|
||||||
token.addGrants(new RoomJoin(true), new RoomName(roomName), new RoomCreate(true));
|
token.addGrants(new RoomJoin(true), new RoomName(roomName), new RoomCreate(true));
|
||||||
|
|
||||||
videoSertvice.startOnline(userId, id);
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
return ResponseEntity.ok(Map.of("token", token.toJwt()));
|
return ResponseEntity.ok(Map.of("token", token.toJwt()));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(findUser.getRole()==UserRole.STUDENT )// && lecture.isOnline() )
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
IdentityData identityData = new IdentityData(participantName, "학생");
|
|
||||||
String jsonIdentity = serializeIdentityData(identityData);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
token.setIdentity(jsonIdentity);
|
|
||||||
token.setName(participantName);
|
|
||||||
|
|
||||||
token.addGrants(new RoomJoin(true), new RoomName(roomName));
|
|
||||||
|
|
||||||
|
|
||||||
videoSertvice.startOnline(userId, id);
|
|
||||||
|
|
||||||
|
|
||||||
return ResponseEntity.ok(Map.of("token", token.toJwt()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return ResponseEntity.ok(Map.of("token", null));
|
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 = "/livekit/webhook", consumes = "application/webhook+json")
|
@PostMapping(value = "/livekit/webhook", consumes = "application/webhook+json")
|
||||||
@ -205,9 +151,10 @@ public class Controller {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Error validating webhook event: " + e.getMessage());
|
System.err.println("Error validating webhook event: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return ResponseEntity.ok("ok");
|
return ResponseEntity.ok("ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,4 +5,7 @@ import java.sql.SQLException;
|
|||||||
public interface VideoSertvice {
|
public interface VideoSertvice {
|
||||||
|
|
||||||
void startOnline(Long userId,Long lectureId) throws SQLException;
|
void startOnline(Long userId,Long lectureId) throws SQLException;
|
||||||
|
|
||||||
|
boolean isRoomAccessible(Long lectureId,Long userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.edufocus.edufocus.video.service;
|
package com.edufocus.edufocus.video.service;
|
||||||
|
|
||||||
import com.edufocus.edufocus.lecture.entity.Lecture;
|
import com.edufocus.edufocus.lecture.entity.Lecture;
|
||||||
|
import com.edufocus.edufocus.lecture.entity.LectureDetailResponse;
|
||||||
import com.edufocus.edufocus.lecture.service.LectureService;
|
import com.edufocus.edufocus.lecture.service.LectureService;
|
||||||
|
import com.edufocus.edufocus.registration.entity.RegistrationStatus;
|
||||||
|
import com.edufocus.edufocus.registration.service.RegistrationService;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -13,9 +16,31 @@ import java.sql.SQLException;
|
|||||||
public class VideoServiceImpl implements VideoSertvice{
|
public class VideoServiceImpl implements VideoSertvice{
|
||||||
|
|
||||||
private final LectureService lectureService;
|
private final LectureService lectureService;
|
||||||
|
private final RegistrationService registrationService;
|
||||||
@Override
|
@Override
|
||||||
public void startOnline(Long userId,Long lectureId) throws SQLException {
|
public void startOnline(Long userId,Long lectureId) throws SQLException {
|
||||||
|
|
||||||
lectureService.changeState(lectureId);
|
lectureService.changeState(lectureId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRoomAccessible(Long lectureId, Long userId) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LectureDetailResponse lecture= lectureService.findLectureById(userId,userId);
|
||||||
|
|
||||||
|
|
||||||
|
RegistrationStatus registrationStatus = registrationService.getStatus(userId,lectureId);
|
||||||
|
|
||||||
|
|
||||||
|
if(registrationStatus==RegistrationStatus.ACCEPTED && lecture.isOnline())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ jwt.salt=${SALT}
|
|||||||
jwt.access-token.expiretime=3000000
|
jwt.access-token.expiretime=3000000
|
||||||
|
|
||||||
# Refresh Token ?? ?? (??? ??)
|
# Refresh Token ?? ?? (??? ??)
|
||||||
jwt.refresh-token.expiretime=50400000
|
jwt.refresh-token.expiretime=504000000
|
||||||
#jwt.refresh-token.expiretime=4000
|
#jwt.refresh-token.expiretime=4000
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
spring.datasource.url=${DATA_SOURCE_URL}
|
spring.datasource.url=${DATA_SOURCE_URL}
|
||||||
|
Loading…
Reference in New Issue
Block a user