From 9c2abc6d6d651c0c0ce9db406f96534b6dc6bec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Fri, 26 Jul 2024 16:03:30 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20qna=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/qna/controller/QnaController.java | 4 ++-- .../edufocus/qna/repository/QnaRepository.java | 1 - .../edufocus/qna/service/QnaService.java | 2 +- .../edufocus/qna/service/QnaServiceImpl.java | 18 ++++++++++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java b/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java index 48cc08a..6ba7628 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java @@ -106,9 +106,9 @@ public class QnaController { } @GetMapping("/{id}") - public ResponseEntity getQna(@PathVariable Long id) { + public ResponseEntity getQna(@PathVariable Long id) { try{ - Qna findQna= qnaService.getQna(id); + QnaResponseDto findQna= qnaService.getQna(id); return new ResponseEntity<>(findQna, HttpStatus.ACCEPTED); } catch (SQLException e) { diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/repository/QnaRepository.java b/backend/src/main/java/com/edufocus/edufocus/qna/repository/QnaRepository.java index d2cbf7f..9d1c71e 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/repository/QnaRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/repository/QnaRepository.java @@ -13,7 +13,6 @@ import java.util.List; @Repository public interface QnaRepository extends JpaRepository { - List findByLectureId(Long lecturerId); Page findByLectureId(Long lectureId, Pageable pageable); } diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java index 2c84b6d..de97f93 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java @@ -16,7 +16,7 @@ public interface QnaService { QnaResponseDto createQna(Long id, QnaRequestDto qnaRequestDto, Long lecture_id) throws SQLException; QnaResponseDto updateQna(Long id,QnaRequestDto qnaRequestDto) throws SQLException; void deleteQna(Long id) throws SQLException; - Qna getQna(Long id) throws SQLException; + QnaResponseDto getQna(Long id) throws SQLException; List getAllQnasByLecture(Long lectureId,int pageNumber) throws SQLException; QnaResponseDto createAnswer(Long id,QnaRequestDto qnaRequestDto) throws SQLException; diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java index e53f585..bed4103 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java @@ -80,8 +80,22 @@ qnaRepository.deleteById(id); } @Override - public Qna getQna(Long id) { - return null; + public QnaResponseDto getQna(Long id) { + Optional qna; + try { + + qna= qnaRepository.findById(id); + + + } catch (Exception e) { + + throw new RuntimeException("Qna 없음 " + id, e); + } + + + + return QnaResponseDto.toEntity(qna.get()); + } @Override From 97a69ae3af6908dc0850c14b2852d0d21fc3f245 Mon Sep 17 00:00:00 2001 From: yulmam Date: Fri, 26 Jul 2024 16:29:58 +0900 Subject: [PATCH 2/8] =?UTF-8?q?feat=20:=20BoardSummaryDto=20create=20time?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/EdufocusApplication.java | 2 ++ .../entity/dto/ResponseBoardDetailDto.java | 6 ++--- .../entity/dto/ResponseBoardSummaryDto.java | 3 +++ .../board/entity/dto/ResponseCommentDto.java | 5 ++-- .../edufocus/board/entity/vo/Board.java | 15 +++++++---- .../edufocus/board/entity/vo/Comment.java | 6 ++--- .../src/main/resources/application.properties | 25 +++++++++++++++---- 7 files changed, 44 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/EdufocusApplication.java b/backend/src/main/java/com/edufocus/edufocus/EdufocusApplication.java index 556bff0..e80c9fd 100644 --- a/backend/src/main/java/com/edufocus/edufocus/EdufocusApplication.java +++ b/backend/src/main/java/com/edufocus/edufocus/EdufocusApplication.java @@ -2,7 +2,9 @@ package com.edufocus.edufocus; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +@EnableJpaAuditing @SpringBootApplication public class EdufocusApplication { diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java index 8cf6bc7..e050da7 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java @@ -5,7 +5,7 @@ import lombok.Builder; import lombok.Getter; import lombok.Setter; -import java.time.LocalTime; +import java.time.LocalDateTime; @Builder @Getter @@ -17,6 +17,6 @@ public class ResponseBoardDetailDto { private String title; private String content; private int viewCount; - private LocalTime createdAt; - private LocalTime modifiedAt; + private LocalDateTime createdAt; + private LocalDateTime modifiedAt; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java index d3e72a5..bcd1f11 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java @@ -5,6 +5,8 @@ import lombok.Builder; import lombok.Getter; import lombok.Setter; +import java.time.LocalDateTime; + @Builder @Getter @Setter @@ -12,4 +14,5 @@ public class ResponseBoardSummaryDto { private long id; private String name; private String title; + private LocalDateTime createdAt; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java index 92156ce..180c6b1 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java @@ -4,6 +4,7 @@ import lombok.Builder; import lombok.Getter; import lombok.Setter; +import java.time.LocalDateTime; import java.time.LocalTime; @Builder @@ -13,6 +14,6 @@ public class ResponseCommentDto { private long id; private String name; private String content; - private LocalTime createAt; - private LocalTime modifiedAt; + private LocalDateTime createAt; + private LocalDateTime modifiedAt; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java index 6272a17..6b283ec 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java @@ -8,8 +8,11 @@ import com.edufocus.edufocus.user.model.entity.User; import com.fasterxml.jackson.annotation.JsonAutoDetect; import jakarta.persistence.*; import lombok.*; -import org.hibernate.annotations.CreationTimestamp; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; @@ -18,6 +21,7 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor @Setter +@EntityListeners(AuditingEntityListener.class) @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) public class Board { @@ -37,11 +41,11 @@ public class Board { @Column(nullable = true) private int viewCount; - @CreationTimestamp - LocalTime createdAt; + @CreatedDate + LocalDateTime createdAt; - @CreationTimestamp - LocalTime modifiedAt; + @LastModifiedDate + LocalDateTime modifiedAt; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") @@ -60,6 +64,7 @@ public class Board { .id(id) .title(title) .name(user.getUserId()) + .createdAt(createdAt) .build(); } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java index 90c7ebf..667f678 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java @@ -10,7 +10,7 @@ import lombok.Builder; import lombok.NoArgsConstructor; import lombok.Setter; -import java.time.LocalTime; +import java.time.LocalDateTime; @Entity @Builder @@ -26,10 +26,10 @@ public class Comment { private String content; @Column - private LocalTime createdAt; + private LocalDateTime createdAt; @Column - private LocalTime modifiedAt; + private LocalDateTime modifiedAt; @ManyToOne @JoinColumn(name = "user_id") diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index f06afe6..e67341c 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -2,13 +2,15 @@ spring.application.name=edufocus server.port=8080 server.ssl.enabled=false +server.servlet.context-path=${CONTEXT_PATH} + # LiveKit configuration livekit.api.key=${LIVEKIT_API_KEY:devkey} livekit.api.secret=${LIVEKIT_API_SECRET:secret} # JWT Salt (??? ?? ???? ???) -jwt.salt=ssafy-screte-key-20240404-ssafy-screte-key-20240404-ssafy-screte-key-20240404 +jwt.salt=${SALT} # Access Token ?? ?? (??? ??) jwt.access-token.expiretime=3600000 @@ -16,11 +18,24 @@ jwt.access-token.expiretime=3600000 # Refresh Token ?? ?? (??? ??) jwt.refresh-token.expiretime=86400000 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.datasource.url=jdbc:mysql://localhost:3306/edufocus?useSSL=false -spring.datasource.username=root -spring.datasource.password=root +spring.datasource.url=${DATA_SOURCE_URL} +spring.datasource.username=${USER_NAME} +spring.datasource.password=${USER_PASSWORD} spring.mvc.pathmatch.matching-strategy=ant_path_matcher spring.jpa.database=mysql spring.jpa.hibernate.ddl-auto=create -spring.jpa.show-sql=true \ No newline at end of file +spring.jpa.show-sql=true + + + + +spring.mail.host=smtp.gmail.com +spring.mail.port=587 +#spring.mail.username=ssafytestpjt +#spring.mail.password=trpjbxqialufuzih +spring.mail.username=passfinder111@gmail.com +spring.mail.password=mnlyfkiprltjlsmw + +spring.mail.properties.mail.smtp.auth=true +spring.mail.properties.mail.smtp.starttls.enable=true \ No newline at end of file From 32a176b679c5acd02e0439897ce9aa458600a519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Mon, 29 Jul 2024 14:08:44 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=EA=B0=95=EC=9D=98=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91,=20=EA=B0=95=EC=9D=98=20=EC=B0=B8=EC=97=AC=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/lecture/entity/Lecture.java | 2 +- .../lecture/service/LectureService.java | 2 + .../lecture/service/LectureServiceImpl.java | 24 +++ .../service/RegistrationService.java | 2 + .../service/RegistrationServiceImpl.java | 7 + .../user/config/WebConfiguration.java | 4 +- .../edufocus/video/controller/Controller.java | 150 +++++++++++++----- .../edufocus/video/service/VideoSertvice.java | 8 + .../video/service/VideoServiceImpl.java | 21 +++ .../src/main/resources/application.properties | 3 + 10 files changed, 179 insertions(+), 44 deletions(-) create mode 100644 backend/src/main/java/com/edufocus/edufocus/video/service/VideoSertvice.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/video/service/VideoServiceImpl.java diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java index 0a9168a..f74d97f 100644 --- a/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java @@ -47,7 +47,7 @@ public class Lecture { @Column private String time; - @Column + @Column(columnDefinition = "boolean default false") private boolean online; } 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 962ed5d..65153a0 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 @@ -26,4 +26,6 @@ public interface LectureService { List findMyLecture(long userId); Lecture findLectureByTitle(String title); + + void changeState(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 52a8824..0f841ad 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 @@ -221,4 +221,28 @@ public class LectureServiceImpl implements LectureService { public Lecture findLectureByTitle(String title) { return lectureRepository.findByTitle(title); } + + @Override + public void changeState(Long id) { + + Optional lecture = lectureRepository.findById(id); + + Lecture l; + if(lecture.isPresent()) + { + l = lecture.get(); + + System.out.println(l.isOnline()); + l.setOnline(true); + System.out.println(l.isOnline()); + + + }else { + + throw new RuntimeException("Lecture not found with id: " + id); + } + lectureRepository.save(l); + } + + } diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java index 96d89f6..bc27b37 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java @@ -1,6 +1,7 @@ package com.edufocus.edufocus.registration.service; import com.edufocus.edufocus.registration.entity.Registration; +import com.edufocus.edufocus.registration.entity.RegistrationStatus; import org.springframework.stereotype.Service; @Service @@ -12,4 +13,5 @@ public interface RegistrationService { boolean deleteRegistration(long userId, long registrationId); + RegistrationStatus isOnline(Long userId , Long lectureId); } diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java index 7c156bf..0eca5b5 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java @@ -62,4 +62,11 @@ public class RegistrationServiceImpl implements RegistrationService { return true; } + @Override + public RegistrationStatus isOnline(Long userId, Long lectureId) { + + Registration registration = registrationRepository.findByUserIdAndLectureId(userId,lectureId); + return registration.getStatus(); + } + } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/config/WebConfiguration.java b/backend/src/main/java/com/edufocus/edufocus/user/config/WebConfiguration.java index 4bc3d83..58213a3 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/config/WebConfiguration.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/config/WebConfiguration.java @@ -26,7 +26,7 @@ public class WebConfiguration implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry) { registry .addMapping("/**") - .allowedOrigins("http://i11a701.p.ssafy.io/", "http://localhost:5173", "http://localhost:4173") + .allowedOrigins("http://i11a701.p.ssafy.io/", "http://localhost:5173", "http://localhost:4173","http://localhost:5080") .allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name(), HttpMethod.DELETE.name(), HttpMethod.HEAD.name(), HttpMethod.OPTIONS.name(), HttpMethod.PATCH.name()) @@ -45,7 +45,7 @@ public class WebConfiguration implements WebMvcConfigurer { registry.addInterceptor(jwtInterceptor) .addPathPatterns("/**") // 모든 경로에 대해 인터셉터 적용 - .excludePathPatterns("/v3/api-docs/**","/swagger-resources/**","/webjars/**","/swagger-ui/**","/auth/**", "/board/**", "/user/**","/lecture/**","/qna/**", "/quiz/**"); // 인증 없이 접근 가능한 경로 설정 + .excludePathPatterns("/v3/api-docs/**","/swagger-resources/**","/webjars/**","/swagger-ui/**","/auth/**", "/board/**", "/user/**","/lecture/**","/qna/**", "/quiz/**","/video/**"); // 인증 없이 접근 가능한 경로 설정 ///v3/api-docs/**, /swagger-resources/**, /webjars/** } 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 ed35745..36cadb8 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 @@ -1,20 +1,37 @@ package com.edufocus.edufocus.video.controller; -import io.livekit.server.AccessToken; -import io.livekit.server.RoomJoin; -import io.livekit.server.RoomName; -import io.livekit.server.WebhookReceiver; -import livekit.LivekitWebhook.WebhookEvent; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - import java.util.Map; -@CrossOrigin(origins = "*") -@RestController -public class Controller { +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.registration.entity.RegistrationStatus; +import com.edufocus.edufocus.registration.service.RegistrationService; +import com.edufocus.edufocus.user.model.service.UserService; +import com.edufocus.edufocus.user.util.JWTUtil; +import com.edufocus.edufocus.video.service.VideoSertvice; +import io.livekit.server.*; +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import livekit.LivekitWebhook.WebhookEvent; + +//@CrossOrigin(origins = "*") +@RestController +@RequestMapping("/video") +@Slf4j +@RequiredArgsConstructor +public class Controller { + private final JWTUtil jwtUtil; + private final UserService userService; + private final LectureService lectureService; + private final VideoSertvice videoSertvice; + private final RegistrationService registrationService; @Value("${livekit.api.key}") private String LIVEKIT_API_KEY; @@ -25,47 +42,98 @@ public class Controller { * @param params JSON object with roomName and participantName * @return JSON object with the JWT token */ - @PostMapping(value = "/token") - public ResponseEntity> createToken(@RequestBody Map params) { - String roomName = params.get("roomName"); - String participantName = params.get("participantName"); +// @PostMapping(value = "/token") +// public ResponseEntity> createToken(@RequestBody Map 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> startLecture(@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); + + String roomName = lecture.getTitle(); + String participantName = userService.getUserName(userId); - 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)); + token.addGrants(new RoomJoin(true), new RoomName(roomName),new RoomCreate(true)); + + videoSertvice.startOnline(userId,id); + - // 방이름으로 입장하는건데 - // 만약 수강생에 DB에 신청한 강의명이 없다면 들어갈수 없음 - // 검증 로직만 추가하면 될듯? return ResponseEntity.ok(Map.of("token", token.toJwt())); } - @PostMapping(value = "/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); - try { - WebhookEvent event = webhookReceiver.receive(body, authHeader); - System.out.println("LiveKit Webhook: " + event.toString()); - } catch (Exception e) { - System.err.println("Error validating webhook event: " + e.getMessage()); - } - return ResponseEntity.ok("ok"); + + @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); + try { + WebhookEvent event = webhookReceiver.receive(body, authHeader); + System.out.println("LiveKit Webhook: " + event.toString()); + } catch (Exception e) { + System.err.println("Error validating webhook event: " + e.getMessage()); + } + return ResponseEntity.ok("ok"); } } diff --git a/backend/src/main/java/com/edufocus/edufocus/video/service/VideoSertvice.java b/backend/src/main/java/com/edufocus/edufocus/video/service/VideoSertvice.java new file mode 100644 index 0000000..981c5c4 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/video/service/VideoSertvice.java @@ -0,0 +1,8 @@ +package com.edufocus.edufocus.video.service; + +import java.sql.SQLException; + +public interface VideoSertvice { + + void startOnline(Long userId,Long lectureId) throws SQLException; +} 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 new file mode 100644 index 0000000..af82559 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/video/service/VideoServiceImpl.java @@ -0,0 +1,21 @@ +package com.edufocus.edufocus.video.service; + +import com.edufocus.edufocus.lecture.entity.Lecture; +import com.edufocus.edufocus.lecture.service.LectureService; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.sql.SQLException; +@Service +@Transactional +@RequiredArgsConstructor +public class VideoServiceImpl implements VideoSertvice{ + + private final LectureService lectureService; + @Override + public void startOnline(Long userId,Long lectureId) throws SQLException { + + lectureService.changeState(lectureId); + } +} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 37b4488..b188226 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -4,6 +4,9 @@ server.port=8080 server.ssl.enabled=false server.servlet.context-path=${CONTEXT_PATH} +# openvidu +#server.port=${SERVER_PORT:6080} + # LiveKit configuration livekit.api.key=${LIVEKIT_API_KEY:devkey} From 16fd51641a126b1613be0850aef00da29ef533d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Mon, 29 Jul 2024 14:33:27 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20regisration=20cors=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/edufocus/edufocus/user/config/WebConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/user/config/WebConfiguration.java b/backend/src/main/java/com/edufocus/edufocus/user/config/WebConfiguration.java index 58213a3..9b421ef 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/config/WebConfiguration.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/config/WebConfiguration.java @@ -45,7 +45,7 @@ public class WebConfiguration implements WebMvcConfigurer { registry.addInterceptor(jwtInterceptor) .addPathPatterns("/**") // 모든 경로에 대해 인터셉터 적용 - .excludePathPatterns("/v3/api-docs/**","/swagger-resources/**","/webjars/**","/swagger-ui/**","/auth/**", "/board/**", "/user/**","/lecture/**","/qna/**", "/quiz/**","/video/**"); // 인증 없이 접근 가능한 경로 설정 + .excludePathPatterns("/v3/api-docs/**","/swagger-resources/**","/webjars/**","/swagger-ui/**","/auth/**", "/board/**", "/user/**","/lecture/**","/qna/**", "/quiz/**","/video/**","/registration/**"); // 인증 없이 접근 가능한 경로 설정 ///v3/api-docs/**, /swagger-resources/**, /webjars/** } From 32d2592841c32eb65e9259383aa4232c803bfb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Mon, 29 Jul 2024 14:58:44 +0900 Subject: [PATCH 5/8] feat: cors --- .../edufocus/edufocus/user/model/entity/InfoDto.java | 8 ++++++++ .../edufocus/user/model/service/UserService.java | 3 +++ .../edufocus/user/model/service/UserServiceImpl.java | 10 ++++++++++ .../edufocus/edufocus/video/controller/Controller.java | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/com/edufocus/edufocus/user/model/entity/InfoDto.java diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/InfoDto.java b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/InfoDto.java new file mode 100644 index 0000000..ed96b9c --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/InfoDto.java @@ -0,0 +1,8 @@ +package com.edufocus.edufocus.user.model.entity; + +public class InfoDto { + + String name; + String email; + +} diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java index f661fd1..2f63135 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java @@ -12,4 +12,7 @@ public interface UserService { void sendEamail(User user) throws Exception; void userCheck(Long id) throws Exception; String getUserName(Long id) throws Exception; + void changeuInfo(Long id) throws Exception; + void changePassword(Long id) throws Exception; + } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java index 554d971..66bb873 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java @@ -143,6 +143,16 @@ public class UserServiceImpl implements UserService{ return userRepository.findById(id).get().getName(); } + @Override + public void changeuInfo(Long id) throws Exception { + + } + + @Override + public void changePassword(Long id) throws Exception { + + } + public String getTempPassword() { char[] charSet = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; 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 36cadb8..b6c1493 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 @@ -21,11 +21,12 @@ import org.springframework.web.bind.annotation.*; import livekit.LivekitWebhook.WebhookEvent; -//@CrossOrigin(origins = "*") +@CrossOrigin(origins = "*") @RestController @RequestMapping("/video") @Slf4j @RequiredArgsConstructor + public class Controller { private final JWTUtil jwtUtil; private final UserService userService; From bcf36665f9eeaa85e8c40c5a34139f05aab1d42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Mon, 29 Jul 2024 15:11:25 +0900 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20cors=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/edufocus/edufocus/video/controller/Controller.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 b6c1493..b36b4d2 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 @@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.*; import livekit.LivekitWebhook.WebhookEvent; -@CrossOrigin(origins = "*") + @RestController @RequestMapping("/video") @Slf4j @@ -66,6 +66,8 @@ public class Controller { public ResponseEntity> startLecture(@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)); LectureDetailResponse lecture= lectureService.findLectureById(userId,id); From 764f5bd30db768bf0818a6daf3c89df0d122f763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Mon, 29 Jul 2024 15:18:37 +0900 Subject: [PATCH 7/8] feat: video --- .../edufocus/video/controller/Controller.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 b36b4d2..6ad9ef3 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 @@ -99,10 +99,10 @@ public class Controller { LectureDetailResponse lecture= lectureService.findLectureById(userId,id); - RegistrationStatus registrationStatus = registrationService.isOnline(userId,id); + //RegistrationStatus registrationStatus = registrationService.isOnline(userId,id); - if(registrationStatus==RegistrationStatus.ACCEPTED) - { +// if(registrationStatus==RegistrationStatus.ACCEPTED) +// { String roomName = lecture.getTitle(); String participantName = userService.getUserName(userId); @@ -112,16 +112,16 @@ public class Controller { token.setIdentity(participantName); token.addGrants(new RoomJoin(true), new RoomName(roomName)); - videoSertvice.startOnline(userId,id); + //videoSertvice.startOnline(userId,id); return ResponseEntity.ok(Map.of("token", token.toJwt())); - } - else{ - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Map.of("errorMessage", "Not accepted")); - - } +// } +// else{ +// return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Map.of("errorMessage", "Not accepted")); +// +// } From 78b37baf9f57b01a5e3bf94e4920efd3fd860af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Tue, 30 Jul 2024 09:32:37 +0900 Subject: [PATCH 8/8] =?UTF-8?q?feat:=20openvidu=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/edufocus/edufocus/video/controller/Controller.java | 2 ++ 1 file changed, 2 insertions(+) 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 6ad9ef3..c4fa32c 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 @@ -139,4 +139,6 @@ public class Controller { return ResponseEntity.ok("ok"); } + + }