Merge branch 'BE/userinfo' into 'backend'

feat: 어드민,학생 방 입장 로직 변경

See merge request s11-webmobile1-sub2/S11P12A701!49
This commit is contained in:
박정민 2024-08-05 16:08:10 +09:00
commit 2a090a3016
4 changed files with 36 additions and 48 deletions

View File

@ -30,7 +30,7 @@ public class QuizController {
private final JWTUtil jwtUtil; private final JWTUtil jwtUtil;
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> createQuizSet(@RequestHeader("Authorization") String accessToken, @RequestPart QuizSetCreateRequest quizSetCreateRequest public ResponseEntity<?> createQuizSet(@RequestHeader("Authzation") String accessToken, @RequestPart QuizSetCreateRequest quizSetCreateRequest
, @RequestPart(value = "images", required = false) List<MultipartFile> images) throws IOException { , @RequestPart(value = "images", required = false) List<MultipartFile> images) throws IOException {
long userId = Long.parseLong(jwtUtil.getUserId(accessToken)); long userId = Long.parseLong(jwtUtil.getUserId(accessToken));

View File

@ -41,34 +41,33 @@ public class ReportServiceImpl implements ReportService {
QuizSet quizSet = quizSetService.findQuizSet(reportRequset.getQuizsetId()); QuizSet quizSet = quizSetService.findQuizSet(reportRequset.getQuizsetId());
System.out.println(quizSet.toString());
List<Quiz> quizList = quizSet.getQuizzes(); List<Quiz> quizList = quizSet.getQuizzes();
List<AnswerInput> answerInputList = reportRequset.getAnswerInputList(); List<AnswerInput> answerInputList = reportRequset.getAnswerInputList();
Report report = new Report(); Report report = new Report();
Long reportNum = report.getId(); Long reportNum = report.getId();
int allCount= quizList.size(); int allCount = quizList.size();
int correctCount =0 ; int correctCount = 0;
User testuser= userRepository.findById(reportRequset.getUserId()).orElse(null); User testuser = userRepository.findById(reportRequset.getUserId()).orElse(null);
for (Quiz quiz : quizList) { for (Quiz quiz : quizList) {
for (AnswerInput answerInput : answerInputList) { for (AnswerInput answerInput : answerInputList) {
if (quiz.getId() == answerInput.getAnswerinputID()) { if (quiz.getId() == answerInput.getAnswerinputID()) {
if(quiz.getAnswer().equals(answerInput.getAnswer())) { if (quiz.getAnswer().equals(answerInput.getAnswer())) {
correctCount++; correctCount++;
Answer answer = Answer.builder() Answer answer = Answer.builder()
.userAnswer(answerInput.getAnswer()) .userAnswer(answerInput.getAnswer())
.isCorrect(true) .isCorrect(true)
.report(report) .report(report)
.quiz(quiz) .quiz(quiz)
.build(); .build();
} } else {
else{
Answer answer = Answer.builder() Answer answer = Answer.builder()
.userAnswer(answerInput.getAnswer()) .userAnswer(answerInput.getAnswer())
.isCorrect(false) .isCorrect(false)
@ -77,7 +76,6 @@ public class ReportServiceImpl implements ReportService {
.build(); .build();
} }
} }
@ -86,11 +84,11 @@ public class ReportServiceImpl implements ReportService {
} }
report = Report.builder() report = Report.builder()
.user(testuser) .user(testuser)
.quizSet(quizSet) .quizSet(quizSet)
.allCount(allCount) .allCount(allCount)
.correctCount(correctCount) .correctCount(correctCount)
.testAt(new Date()).build(); .testAt(new Date()).build();
ReportResponse reportResponse = ReportResponse.builder() ReportResponse reportResponse = ReportResponse.builder()
.quizesetId(quizSet.getId()) .quizesetId(quizSet.getId())
.userId(testuser.getId()) .userId(testuser.getId())

View File

@ -21,13 +21,14 @@ public class WebConfiguration implements WebMvcConfigurer {
this.jwtInterceptor = jwtInterceptor; this.jwtInterceptor = jwtInterceptor;
} }
//
//
@Override @Override
public void addCorsMappings(CorsRegistry registry) { public void addCorsMappings(CorsRegistry registry) {
registry registry
.addMapping("/**") .addMapping("/**")
.allowedOriginPatterns("https://i11a701.p.ssafy.io/","https://localhost:5173", "http://localhost:5173", "http://localhost:4173","http://localhost:5080","http://192.168.*.*:5173") .allowedOriginPatterns("https://i11a701.p.ssafy.io/", "https://localhost:5173", "http://localhost:5173", "http://localhost:4173", "http://localhost:5080", "http://192.168.*.*:5173")
.allowedMethods("GET","POST",HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name(), .allowedMethods("GET", "POST", HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name(),
HttpMethod.DELETE.name(), HttpMethod.HEAD.name(), HttpMethod.OPTIONS.name(), HttpMethod.DELETE.name(), HttpMethod.HEAD.name(), HttpMethod.OPTIONS.name(),
HttpMethod.PATCH.name()) HttpMethod.PATCH.name())
.allowCredentials(true) .allowCredentials(true)
@ -41,10 +42,11 @@ public class WebConfiguration implements WebMvcConfigurer {
registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/assets/img/"); registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/assets/img/");
registry.addResourceHandler("/*.html**").addResourceLocations("classpath:/static/"); registry.addResourceHandler("/*.html**").addResourceLocations("classpath:/static/");
} }
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(jwtInterceptor) registry.addInterceptor(jwtInterceptor)
.addPathPatterns("/**") // 모든 경로에 대해 인터셉터 적용 .addPathPatterns("/**") // 모든 경로에 대해 인터셉터 적용
.excludePathPatterns("/v3/api-docs/**","/swagger-resources/**","/webjars/**","/swagger-ui/**","/auth/**", "/board/**", "/user/**","/lecture/**","/qna/**", "/quiz/**","/video/**","/registration/**"); // 인증 없이 접근 가능한 경로 설정 .excludePathPatterns("/v3/api-docs/**", "/swagger-resources/**", "/webjars/**", "/swagger-ui/**", "/auth/**", "/board/**", "/user/**", "/lecture/**", "/qna/**", "/quiz/**", "/video/**", "/registration/**", "/report/**"); // 인증 없이 접근 가능한 경로 설정
} }
} }

View File

@ -93,36 +93,9 @@ public class Controller {
} }
} } else if (findUser.getRole() == UserRole.ADMIN) {//&& lecture.isOnline() ) {
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 roomName = lecture.getTitle();
String participantName = userService.getUserName(userId);
System.out.println(participantName);
AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
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);
@ -137,11 +110,26 @@ public class Controller {
} }
return ResponseEntity.ok(Map.of("token", null)); 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));
videoSertvice.startOnline(userId, id);
return ResponseEntity.ok(Map.of("token", " "));
}
@PostMapping(value = "/livekit/webhook", consumes = "application/webhook+json") @PostMapping(value = "/livekit/webhook", consumes = "application/webhook+json")
public ResponseEntity<String> receiveWebhook(@RequestHeader("Authorization") String authHeader, @RequestBody String body) { public ResponseEntity<String> receiveWebhook(@RequestHeader("Authorization") String authHeader, @RequestBody String body) {
WebhookReceiver webhookReceiver = new WebhookReceiver(LIVEKIT_API_KEY, LIVEKIT_API_SECRET); WebhookReceiver webhookReceiver = new WebhookReceiver(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);