diff --git a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java index ef8abb7..5bd154d 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java @@ -129,7 +129,7 @@ public class BoardController { @ExceptionHandler() - public ResponseEntity NoContentException(Exception exception){ + public ResponseEntity NoContentException(Exception e){ return new ResponseEntity<>(HttpStatus.NO_CONTENT); } } 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 6b283ec..0277c7c 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 @@ -4,7 +4,7 @@ package com.edufocus.edufocus.board.entity.vo; import com.edufocus.edufocus.board.entity.dto.ResponseBoardDetailDto; import com.edufocus.edufocus.board.entity.dto.ResponseBoardSummaryDto; import com.edufocus.edufocus.lecture.entity.Lecture; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.fasterxml.jackson.annotation.JsonAutoDetect; import jakarta.persistence.*; import lombok.*; @@ -13,7 +13,6 @@ 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; @Entity 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 667f678..ef311a0 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 @@ -2,7 +2,7 @@ package com.edufocus.edufocus.board.entity.vo; import com.edufocus.edufocus.board.entity.dto.ResponseCommentDto; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.fasterxml.jackson.annotation.JsonAutoDetect; import jakarta.persistence.*; import lombok.AllArgsConstructor; diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java index 4e047f9..f471fed 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java @@ -8,7 +8,7 @@ import com.edufocus.edufocus.board.repository.BoardRepository; import com.edufocus.edufocus.board.repository.CommentRepository; import com.edufocus.edufocus.lecture.entity.Lecture; import com.edufocus.edufocus.lecture.repository.LectureRepository; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.repository.UserRepository; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -72,7 +72,7 @@ public class BoardServiceImpl implements BoardService { @Transactional public void updateBoard(long boardId, RequestBoardUpdateDto requestBoardUpdateDto) { - Board board = boardRepository.findById(boardId).orElseThrow(IllegalArgumentException::new); + Board board = boardRepository.getReferenceById(boardId); board.setTitle(requestBoardUpdateDto.getTitle()); board.setContent(requestBoardUpdateDto.getContent()); @@ -113,7 +113,7 @@ public class BoardServiceImpl implements BoardService { @Transactional public void updateComment(long commentId, RequestCommentDto requestCommentDto) { - Comment comment = commentRepository.findById(commentId).orElseThrow(IllegalArgumentException::new); + Comment comment = commentRepository.getReferenceById(commentId); comment.setContent(requestCommentDto.getContent()); 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 f74d97f..5db4488 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 @@ -1,7 +1,7 @@ package com.edufocus.edufocus.lecture.entity; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import jakarta.persistence.*; import lombok.*; 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 b97246c..125bad0 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 @@ -6,8 +6,8 @@ import com.edufocus.edufocus.lecture.repository.LectureRepository; import com.edufocus.edufocus.registration.entity.Registration; import com.edufocus.edufocus.registration.entity.RegistrationStatus; import com.edufocus.edufocus.registration.repository.RegistrationRepository; -import com.edufocus.edufocus.user.model.entity.User; -import com.edufocus.edufocus.user.model.entity.UserRole; +import com.edufocus.edufocus.user.model.entity.vo.User; +import com.edufocus.edufocus.user.model.entity.vo.UserRole; import com.edufocus.edufocus.user.model.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; @@ -235,8 +235,14 @@ public class LectureServiceImpl implements LectureService { Lecture l; l = lecture.get(); - l.setOnline(true); - + if(l.isOnline()) + { + l.setOnline(false); + } + else + { + l.setOnline(true); + } lectureRepository.save(l); diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/entity/Qna.java b/backend/src/main/java/com/edufocus/edufocus/qna/entity/Qna.java index 993484e..901afd3 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/entity/Qna.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/entity/Qna.java @@ -1,10 +1,9 @@ package com.edufocus.edufocus.qna.entity; import com.edufocus.edufocus.lecture.entity.Lecture; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import jakarta.persistence.*; import lombok.*; -import org.checkerframework.checker.units.qual.C; import java.util.Date; 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 d583346..80ea7ae 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 @@ -6,19 +6,16 @@ import com.edufocus.edufocus.qna.entity.Qna; import com.edufocus.edufocus.qna.entity.QnaRequestDto; import com.edufocus.edufocus.qna.entity.QnaResponseDto; import com.edufocus.edufocus.qna.repository.QnaRepository; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; -import lombok.Setter; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Optional; diff --git a/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java b/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java index 816638c..90d13ac 100644 --- a/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java +++ b/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java @@ -1,12 +1,11 @@ package com.edufocus.edufocus.quiz.entity; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonManagedReference; import jakarta.persistence.*; import lombok.*; -import java.util.ArrayList; import java.util.List; @Entity diff --git a/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetServiceImpl.java index 419c0c6..b3b2b59 100644 --- a/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetServiceImpl.java @@ -2,7 +2,7 @@ package com.edufocus.edufocus.quiz.service; import com.edufocus.edufocus.quiz.entity.*; import com.edufocus.edufocus.quiz.repository.QuizSetRepository; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java index 38cfe35..88af158 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java @@ -1,7 +1,7 @@ package com.edufocus.edufocus.registration.entity; import com.edufocus.edufocus.lecture.entity.Lecture; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import jakarta.persistence.*; import lombok.*; 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 4e69660..26ac48d 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 @@ -1,13 +1,12 @@ package com.edufocus.edufocus.registration.service; -import com.edufocus.edufocus.lecture.entity.Lecture; import com.edufocus.edufocus.lecture.repository.LectureRepository; import com.edufocus.edufocus.registration.entity.Registration; import com.edufocus.edufocus.registration.entity.RegistrationSearchResponse; import com.edufocus.edufocus.registration.entity.RegistrationStatus; import com.edufocus.edufocus.registration.repository.RegistrationRepository; -import com.edufocus.edufocus.user.model.entity.User; -import com.edufocus.edufocus.user.model.entity.UserRole; +import com.edufocus.edufocus.user.model.entity.vo.User; +import com.edufocus.edufocus.user.model.entity.vo.UserRole; import com.edufocus.edufocus.user.model.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java index 6165358..a9e2222 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java @@ -1,7 +1,7 @@ package com.edufocus.edufocus.report.entity.vo; import com.edufocus.edufocus.quiz.entity.QuizSet; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import jakarta.persistence.*; import lombok.*; diff --git a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java index 1d6449d..104e626 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java @@ -11,7 +11,7 @@ import com.edufocus.edufocus.report.entity.dto.AnswerInput; import com.edufocus.edufocus.report.entity.vo.Report; import com.edufocus.edufocus.report.entity.dto.ReportRequset; import com.edufocus.edufocus.report.repository.ReportRepository; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java b/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java index 55306a5..c077839 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java @@ -1,12 +1,10 @@ package com.edufocus.edufocus.user.controller; -import com.edufocus.edufocus.user.model.entity.InfoDto; -import com.edufocus.edufocus.user.model.entity.PasswordDto; -import com.edufocus.edufocus.user.model.entity.User; -import com.edufocus.edufocus.user.model.exception.ExpriedTokenException; +import com.edufocus.edufocus.user.model.entity.dto.InfoDto; +import com.edufocus.edufocus.user.model.entity.dto.PasswordDto; +import com.edufocus.edufocus.user.model.entity.dto.RequestJoinDto; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.exception.InvalidTokenException; -import com.edufocus.edufocus.user.model.exception.RefreshTokenExpiredException; -import com.edufocus.edufocus.user.model.exception.UnAuthorizedException; import com.edufocus.edufocus.user.model.service.UserService; import com.edufocus.edufocus.user.util.JWTUtil; import io.swagger.v3.oas.annotations.Operation; @@ -16,7 +14,6 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -35,34 +32,30 @@ public class UserController { private final JWTUtil jwtUtil; @PostMapping("/join") - public ResponseEntity join(@RequestBody User user) throws Exception { - userService.join(user); + public ResponseEntity join(@RequestBody RequestJoinDto requestJoinDto){ + + if(userService.isUserIdExist(requestJoinDto.getUserId())) + return new ResponseEntity<>("아이디가 중복 됐습니다.", HttpStatus.CONFLICT); + + userService.join(requestJoinDto); + return ResponseEntity.ok("User registered successfully"); } -// @PostMapping("/findpassword/{user_id}") -// public ResponseEntity findpassword(@PathVariable("user_id") Long user_id) throws Exception { -// userService.userCheck(user_id); -// return ResponseEntity.ok("임시 비밀번호가 이메일로 전송되었습니다."); -// } @PutMapping("/updateinfo") - public ResponseEntity updateUserInfo( - @RequestBody InfoDto infoDto, HttpServletRequest request) { - try { - String token = request.getHeader("Authorization"); - Long userId = Long.parseLong(jwtUtil.getUserId(token)); - userService.changeUserInfo(infoDto, userId); - return ResponseEntity.ok("User info updated successfully"); - } catch (Exception e) { - return ResponseEntity.badRequest().body(e.getMessage()); - } + public ResponseEntity updateUserInfo(@RequestBody InfoDto infoDto, HttpServletRequest request) { + String token = request.getHeader("Authorization"); + Long userId = Long.parseLong(jwtUtil.getUserId(token)); + + userService.changeUserInfo(infoDto, userId); + + return new ResponseEntity<>(HttpStatus.OK); } // 비밀번호 변경 @PutMapping("/updatepassword") public ResponseEntity updatePassword(@RequestBody PasswordDto passwordDto, HttpServletRequest request) { - try - { + try { String token = request.getHeader("Authorization"); Long userId = Long.parseLong(jwtUtil.getUserId(token)); @@ -72,79 +65,50 @@ public class UserController { return ResponseEntity.badRequest().body(e.getMessage()); } } + @Operation(summary = "로그인", description = "아이디와 비밀번호를 이용하여 로그인 처리.") @PostMapping("/login") public ResponseEntity> login( @RequestBody @Parameter(description = "로그인 시 필요한 회원정보(아이디, 비밀번호).", required = true) User user, HttpServletRequest request, HttpServletResponse response) { - String token = request.getHeader("Authorization"); - Map resultMap = new HashMap<>(); HttpStatus status = HttpStatus.ACCEPTED; - try { - User loginUser = userService.login(user); - if (loginUser != null) { + User loginUser = userService.login(user); + if (loginUser == null) + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + + String accessToken = jwtUtil.createAccessToken(String.valueOf(loginUser.getId())); + String refreshToken = jwtUtil.createRefreshToken(String.valueOf(loginUser.getId())); + + userService.saveRefreshToken(loginUser.getId(), refreshToken); + + resultMap.put("name",loginUser.getName()); + resultMap.put("role",loginUser.getRole()); + resultMap.put("access-token", accessToken); + + setCookies(response, refreshToken); + + status = HttpStatus.CREATED; - String accessToken = jwtUtil.createAccessToken(String.valueOf(loginUser.getId())); - String refreshToken = jwtUtil.createRefreshToken(String.valueOf(loginUser.getId())); - - userService.saveRefreshToken(loginUser.getId(), refreshToken); - - resultMap.put("name",loginUser.getName()); - resultMap.put("role",loginUser.getRole()); - resultMap.put("access-token", accessToken); - - Cookie refreshCookie = new Cookie("refresh-token", refreshToken); - refreshCookie.setPath("/"); - refreshCookie.setHttpOnly(true); - refreshCookie.setSecure(true); // HTTPS에서만 전송되도록 설정 - //refreshCookie.setSameSite(Cookie.SameSite.NONE); // Cross-Origin 요청에 대해 모두 전송 - //refreshCookie.setSameSite("None"); // Cross-Origin 요청에 대해 모두 전송 - - String cookieHeader = String.format("refresh-token=%s; Path=/; HttpOnly; Secure; SameSite=None", refreshToken); - response.setHeader("Set-Cookie", cookieHeader); - - // refreshCookie.setSameSite("None"); // Cross-Origin 요청에 대해 모두 전송 - response.addCookie(refreshCookie); - - status = HttpStatus.CREATED; - } else { - resultMap.put("message", "아이디 또는 패스워드를 확인해 주세요."); - status = HttpStatus.UNAUTHORIZED; - } - } catch (Exception e) { - resultMap.put("message", e.getMessage()); - status = HttpStatus.INTERNAL_SERVER_ERROR; - } return new ResponseEntity<>(resultMap, status); } @PostMapping("/logout") public ResponseEntity removeToken(HttpServletRequest request) { - Map resultMap = new HashMap<>(); - HttpStatus status = HttpStatus.ACCEPTED; - try { + String token = request.getHeader("Authorization"); + Long userId = Long.parseLong(jwtUtil.getUserId(token)); - String token = request.getHeader("Authorization"); - Long userId = Long.parseLong(jwtUtil.getUserId(token)); + userService.deleteRefreshToken(userId); - userService.deleteRefreshToken(userId); - status = HttpStatus.OK; - } catch (Exception e) { - log.error("로그아웃 실패 : {}", e); - resultMap.put("message", e.getMessage()); - status = HttpStatus.UNAUTHORIZED; - } - return new ResponseEntity>(resultMap, status); + return new ResponseEntity>(HttpStatus.ACCEPTED); } @Operation(summary = "Access Token 재발급", description = "만료된 access token 을 재발급 받는다.") @PostMapping("/refresh") - public ResponseEntity refreshToken(HttpServletRequest request,HttpServletResponse response) - throws Exception { + public ResponseEntity refreshToken(HttpServletRequest request,HttpServletResponse response) { Cookie[] cookies = request.getCookies(); String token = null; if (cookies != null) { @@ -178,11 +142,7 @@ public class UserController { userService.saveRefreshToken(userId,refreshToken); - Cookie refreshCookie = new Cookie("refresh-token", refreshToken); - refreshCookie.setPath("/"); - refreshCookie.setHttpOnly(true); - refreshCookie.setSecure(true); - response.addCookie(refreshCookie); + setCookies(response, refreshToken); return new ResponseEntity>(resultMap, HttpStatus.CREATED); } @@ -215,7 +175,13 @@ public class UserController { } - + private void setCookies(HttpServletResponse response, String refreshToken){ + Cookie refreshCookie = new Cookie("refresh-token", refreshToken); + refreshCookie.setPath("/"); + refreshCookie.setHttpOnly(true); + refreshCookie.setSecure(true); + response.addCookie(refreshCookie); + } } \ No newline at end of file diff --git a/backend/src/main/java/com/edufocus/edufocus/user/intercepter/JWTInterceptor.java b/backend/src/main/java/com/edufocus/edufocus/user/intercepter/JWTInterceptor.java index c1c6003..55ec605 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/intercepter/JWTInterceptor.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/intercepter/JWTInterceptor.java @@ -26,9 +26,7 @@ public class JWTInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){ final String token = request.getHeader(HEADER_AUTH); - jwtUtil.checkToken(token); - return true; } } \ No newline at end of file diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/UserRole.java b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/UserRole.java deleted file mode 100644 index 48f8cc1..0000000 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/UserRole.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.edufocus.edufocus.user.model.entity; - -public enum UserRole { - STUDENT,ADMIN -} 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/dto/InfoDto.java similarity index 70% rename from backend/src/main/java/com/edufocus/edufocus/user/model/entity/InfoDto.java rename to backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/InfoDto.java index 52b1f08..6c67119 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/InfoDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/InfoDto.java @@ -1,4 +1,4 @@ -package com.edufocus.edufocus.user.model.entity; +package com.edufocus.edufocus.user.model.entity.dto; import lombok.Getter; import lombok.Setter; diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/MemberChangeDto.java b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/MemberChangeDto.java similarity index 84% rename from backend/src/main/java/com/edufocus/edufocus/user/model/entity/MemberChangeDto.java rename to backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/MemberChangeDto.java index 5576813..3f965c6 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/MemberChangeDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/MemberChangeDto.java @@ -1,4 +1,4 @@ -package com.edufocus.edufocus.user.model.entity; +package com.edufocus.edufocus.user.model.entity.dto; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/PasswordDto.java b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/PasswordDto.java similarity index 69% rename from backend/src/main/java/com/edufocus/edufocus/user/model/entity/PasswordDto.java rename to backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/PasswordDto.java index a77f73e..c2f6790 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/PasswordDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/PasswordDto.java @@ -1,13 +1,11 @@ -package com.edufocus.edufocus.user.model.entity; +package com.edufocus.edufocus.user.model.entity.dto; -import lombok.Generated; import lombok.Getter; import lombok.Setter; @Setter @Getter public class PasswordDto { - String currentPassword; String newPassword; String newPasswordCheck; diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/RefreshTokenDto.java b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/RefreshTokenDto.java new file mode 100644 index 0000000..8f22764 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/RefreshTokenDto.java @@ -0,0 +1,11 @@ +package com.edufocus.edufocus.user.model.entity.dto; + + +import lombok.AllArgsConstructor; +import lombok.Setter; + +@Setter +@AllArgsConstructor +public class RefreshTokenDto { + private String Token; +} diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/RequestJoinDto.java b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/RequestJoinDto.java new file mode 100644 index 0000000..6983d90 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/dto/RequestJoinDto.java @@ -0,0 +1,17 @@ +package com.edufocus.edufocus.user.model.entity.dto; + +import com.edufocus.edufocus.user.model.entity.vo.UserRole; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@AllArgsConstructor +public class RequestJoinDto { + private String userId; + private String email; + private String password; + private UserRole role; + private String name; +} diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/User.java b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/vo/User.java similarity index 76% rename from backend/src/main/java/com/edufocus/edufocus/user/model/entity/User.java rename to backend/src/main/java/com/edufocus/edufocus/user/model/entity/vo/User.java index f0403f8..02e409e 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/User.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/vo/User.java @@ -1,21 +1,14 @@ -package com.edufocus.edufocus.user.model.entity; +package com.edufocus.edufocus.user.model.entity.vo; -import com.edufocus.edufocus.qna.entity.Qna; import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.checkerframework.checker.units.qual.A; - -import java.util.ArrayList; -import java.util.List; +import lombok.*; @Entity @Getter @Setter +@Builder @NoArgsConstructor @AllArgsConstructor public class User { diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/vo/UserRole.java b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/vo/UserRole.java new file mode 100644 index 0000000..41602af --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/vo/UserRole.java @@ -0,0 +1,5 @@ +package com.edufocus.edufocus.user.model.entity.vo; + +public enum UserRole { + STUDENT,ADMIN +} 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 b3b2608..fed4131 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,4 +19,8 @@ public class GlobalExceptionHandler { return new ResponseEntity<>(e.getMessage(), HttpStatus.UNAUTHORIZED); } + @ExceptionHandler(UserException.class) + public ResponseEntity handleUserException(UserException e) { + return new ResponseEntity<>(e.getMessage(), HttpStatus.FORBIDDEN);//수정해야함 + } } \ No newline at end of file diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/repository/UserRepository.java b/backend/src/main/java/com/edufocus/edufocus/user/model/repository/UserRepository.java index 026c4aa..10e9f87 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/repository/UserRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/repository/UserRepository.java @@ -1,6 +1,6 @@ package com.edufocus.edufocus.user.model.repository; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import jakarta.transaction.Transactional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; 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 9252869..7b2d101 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 @@ -1,18 +1,28 @@ package com.edufocus.edufocus.user.model.service; -import com.edufocus.edufocus.user.model.entity.InfoDto; -import com.edufocus.edufocus.user.model.entity.PasswordDto; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.dto.InfoDto; +import com.edufocus.edufocus.user.model.entity.dto.PasswordDto; +import com.edufocus.edufocus.user.model.entity.dto.RequestJoinDto; +import com.edufocus.edufocus.user.model.entity.vo.User; public interface UserService { - void join(User user) throws Exception; - User login(User user) throws Exception; - void saveRefreshToken(Long id, String refreshToken) throws Exception; - String getRefreshToken(Long id) throws Exception; - void deleteRefreshToken(Long id) throws Exception; - User userInfo(Long id) throws Exception; - String getUserName(Long id) throws Exception; - void changeUserInfo(InfoDto infoDto,Long id) throws Exception; - void changePassword(PasswordDto passwordDto,Long id) throws Exception; + void join(RequestJoinDto requestJoinDto); + User login(User user); + + void saveRefreshToken(Long id, String refreshToken); + + String getRefreshToken(Long id); + + void deleteRefreshToken(Long id); + + User userInfo(Long id); + + String getUserName(Long id); + + void changeUserInfo(InfoDto infoDto,Long id); + + void changePassword(PasswordDto passwordDto,Long id); + + boolean isUserIdExist(String userId); } 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 c6301c0..77fd4ca 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 @@ -1,19 +1,17 @@ package com.edufocus.edufocus.user.model.service; -import com.edufocus.edufocus.user.model.entity.*; +import com.edufocus.edufocus.user.model.entity.dto.InfoDto; +import com.edufocus.edufocus.user.model.entity.dto.PasswordDto; +import com.edufocus.edufocus.user.util.PasswordUtils; +import com.edufocus.edufocus.user.model.entity.dto.RequestJoinDto; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.exception.UserException; import com.edufocus.edufocus.user.model.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.mail.SimpleMailMessage; -import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Service; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; import java.util.Optional; @Service @@ -25,16 +23,20 @@ public class UserServiceImpl implements UserService { private final UserRepository userRepository; - public void join(User user) + public void join(RequestJoinDto requestJoinDto) { - System.out.println(user.getRole().getClass()); - user.setPassword(PasswordUtils.hashPassword(user.getPassword())); - + User user = User.builder() + .userId(requestJoinDto.getUserId()) + .email(requestJoinDto.getEmail()) + .password(PasswordUtils.hashPassword(requestJoinDto.getPassword())) + .role(requestJoinDto.getRole()) + .name(requestJoinDto.getName()) + .build(); userRepository.save(user); } - public User login(User user) throws SQLException { + public User login(User user){ Optional findUser = userRepository.findByUserId(user.getUserId()); if (findUser.isEmpty()) { @@ -65,14 +67,13 @@ public class UserServiceImpl implements UserService { @Override - public String getUserName(Long id) throws Exception { - + public String getUserName(Long id){ return userRepository.findById(id).get().getName(); } @Override - public void changeUserInfo(InfoDto infoDto, Long id) throws Exception { + public void changeUserInfo(InfoDto infoDto, Long id){ User user = userRepository.findById(id).orElseThrow(IllegalArgumentException::new); @@ -87,18 +88,18 @@ public class UserServiceImpl implements UserService { @Override - public void changePassword(PasswordDto passwordDto, Long id) throws Exception { + public void changePassword(PasswordDto passwordDto, Long id){ User user = userRepository.findById(id).orElse(null); if (user == null) { - throw new Exception("User not found"); + throw new UserException("User not found"); } if (!PasswordUtils.checkPassword(passwordDto.getCurrentPassword(), user.getPassword())) { - throw new Exception("Current password is incorrect"); + throw new UserException("Current password is incorrect"); } else { if (!passwordDto.getNewPassword().equals(passwordDto.getNewPasswordCheck())) { - throw new Exception("New password confirmation does not match"); + throw new UserException("New password confirmation does not match"); } } @@ -106,6 +107,12 @@ public class UserServiceImpl implements UserService { user.setPassword(PasswordUtils.hashPassword(passwordDto.getNewPassword())); userRepository.save(user); } + + @Override + public boolean isUserIdExist(String userId) { + return userRepository.findByUserId(userId).isPresent(); + } + 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'}; @@ -119,17 +126,17 @@ public class UserServiceImpl implements UserService { return str; } @Override - public void saveRefreshToken(Long id, String refreshToken) throws Exception { + public void saveRefreshToken(Long id, String refreshToken){ userRepository.saveRefreshToken(id, refreshToken); } @Override - public String getRefreshToken(Long id) throws Exception { + public String getRefreshToken(Long id){ return userRepository.getRefreshToken(id); } @Override - public void deleteRefreshToken(Long id) throws Exception { + public void deleteRefreshToken(Long id){ userRepository.deleteRefreshToken(id); } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/util/JWTUtil.java b/backend/src/main/java/com/edufocus/edufocus/user/util/JWTUtil.java index e7d4f8c..c6630d9 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/util/JWTUtil.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/util/JWTUtil.java @@ -79,7 +79,7 @@ public class JWTUtil { Map value = claims.getBody(); log.info("value : {}", value); return (String) value.get("id"); - }catch ( ExpiredJwtException e) + }catch (ExpiredJwtException e) { System.out.println("expired token"); throw new ExpriedTokenException(); diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/PasswordUtils.java b/backend/src/main/java/com/edufocus/edufocus/user/util/PasswordUtils.java similarity index 89% rename from backend/src/main/java/com/edufocus/edufocus/user/model/entity/PasswordUtils.java rename to backend/src/main/java/com/edufocus/edufocus/user/util/PasswordUtils.java index aa61d1f..1abbd98 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/PasswordUtils.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/util/PasswordUtils.java @@ -1,4 +1,4 @@ -package com.edufocus.edufocus.user.model.entity; +package com.edufocus.edufocus.user.util; import org.mindrot.jbcrypt.BCrypt; public class PasswordUtils { 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 a94758e..6bfa21a 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,13 +4,11 @@ import java.util.Map; import java.util.Random; 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; -import com.edufocus.edufocus.user.model.entity.User; -import com.edufocus.edufocus.user.model.entity.UserRole; +import com.edufocus.edufocus.user.model.entity.vo.User; +import com.edufocus.edufocus.user.model.entity.vo.UserRole; import com.edufocus.edufocus.user.model.repository.UserRepository; import com.edufocus.edufocus.user.model.service.UserService; import com.edufocus.edufocus.user.util.JWTUtil; @@ -36,180 +34,127 @@ import livekit.LivekitWebhook.WebhookEvent; @RequiredArgsConstructor public class Controller { - private final JWTUtil jwtUtil; - private final UserService userService; - private final LectureService lectureService; - 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; + private final JWTUtil jwtUtil; + private final UserService userService; + private final LectureService lectureService; + private final VideoSertvice videoSertvice; + private final RegistrationService registrationService; + private final UserRepository userRepository; + private final LectureRepository lectureRepository; - @Value("${livekit.api.secret}") - private String LIVEKIT_API_SECRET; - private static final ObjectMapper objectMapper = new ObjectMapper(); + @Value("${livekit.api.key}") + private String LIVEKIT_API_KEY; - /** - * @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"); -// -// 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 { + @Value("${livekit.api.secret}") + private String LIVEKIT_API_SECRET; + private static final ObjectMapper objectMapper = new ObjectMapper(); - String userToken = request.getHeader("Authorization"); - Long userId = Long.parseLong(jwtUtil.getUserId(userToken)); + public static String serializeIdentityData(IdentityData identityData) throws JsonProcessingException, JsonProcessingException { + return objectMapper.writeValueAsString(identityData); + } + + @PostMapping(value = "/joinroom/{lecture_id}") + public ResponseEntity> joinRoom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception { - videoSertvice.startOnline(userId, id); - - return new ResponseEntity<>("방만들기 성공",HttpStatus.OK); - - } - public static String serializeIdentityData(IdentityData identityData) throws JsonProcessingException, JsonProcessingException { - return objectMapper.writeValueAsString(identityData); - } - - @PostMapping(value = "/joinroom/{lecture_id}") - public ResponseEntity> joinRoom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception - { - - // 방 조인할떄 고려해야할점 - // 1. 신청됀 강의인지 - // 2. 그 강의기 On인지 - String userToken = request.getHeader("Authorization"); + 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); + Long userId = Long.parseLong(jwtUtil.getUserId(userToken)); + User findUser = userRepository.findById(userId).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(); - int randomNumber = 10000 + random.nextInt(80000); - - String randStr = String.valueOf(randomNumber); - - String roomName = lecture.getTitle(); - String participantName = userService.getUserName(userId); - System.out.println(participantName); - - AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET); + AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET); - if(findUser.getRole()==UserRole.ADMIN ){//&& lecture.isOnline() ) { + 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); - IdentityData identityData = new IdentityData(participantName, "강사"); - String jsonIdentity = serializeIdentityData(identityData); + token.addGrants(new RoomJoin(true), new RoomName(roomName)); - - token.setIdentity(jsonIdentity); - token.setName(participantName); - - 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())); - - } - else if(findUser.getRole()==UserRole.STUDENT )// && lecture.isOnline() ) - { + return ResponseEntity.ok(Map.of("token", token.toJwt())); + } else { + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Map.of("error", "방에 들어갈 수 없습니다.")); + } - IdentityData identityData = new IdentityData(participantName, "학생"); - String jsonIdentity = serializeIdentityData(identityData); + } + return ResponseEntity.ok(Map.of("token", null)); - token.setIdentity(jsonIdentity); - token.setName(participantName); - - token.addGrants(new RoomJoin(true), new RoomName(roomName)); + } - videoSertvice.startOnline(userId, id); + @PostMapping(value = "/makeroom/{lecture_id}") + public ResponseEntity> makeRoom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception { + String userToken = request.getHeader("Authorization"); - return ResponseEntity.ok(Map.of("token", token.toJwt())); - } + Long userId = Long.parseLong(jwtUtil.getUserId(userToken)); + User findUser = userRepository.findById(userId).orElse(null); + Lecture lecture = lectureRepository.findById(id).orElse(null); - return ResponseEntity.ok(Map.of("token", null)); + String roomName = lecture.getTitle(); + String participantName = userService.getUserName(userId); + System.out.println(participantName); -// 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")); -// -// } + AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET); + if (findUser.getRole() == UserRole.ADMIN) {//&& lecture.isOnline() ) { - } - @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"); - } + videoSertvice.startOnline(userId, id); + + IdentityData identityData = new IdentityData(participantName, "강사"); + String jsonIdentity = serializeIdentityData(identityData); + + + token.setIdentity(jsonIdentity); + token.setName(participantName); + + token.addGrants(new RoomJoin(true), new RoomName(roomName), new RoomCreate(true)); + + + return ResponseEntity.ok(Map.of("token", token.toJwt())); + + } + + + return ResponseEntity.ok(Map.of("token", null)); + + } + + @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 index 981c5c4..71b34d9 100644 --- a/backend/src/main/java/com/edufocus/edufocus/video/service/VideoSertvice.java +++ b/backend/src/main/java/com/edufocus/edufocus/video/service/VideoSertvice.java @@ -4,5 +4,10 @@ import java.sql.SQLException; public interface VideoSertvice { - void startOnline(Long userId,Long lectureId) throws SQLException; + void startOnline(Long userId, Long lectureId) throws SQLException; + + void stopOnline(Long userId, Long lectureId) throws SQLException; + + boolean isRoomAccessible(Long lectureId, Long userId); + } 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 index af82559..cf9714e 100644 --- a/backend/src/main/java/com/edufocus/edufocus/video/service/VideoServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/video/service/VideoServiceImpl.java @@ -1,21 +1,49 @@ package com.edufocus.edufocus.video.service; 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 jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.sql.SQLException; + @Service @Transactional @RequiredArgsConstructor -public class VideoServiceImpl implements VideoSertvice{ +public class VideoServiceImpl implements VideoSertvice { + + private final LectureService lectureService; + private final RegistrationService registrationService; - private final LectureService lectureService; @Override - public void startOnline(Long userId,Long lectureId) throws SQLException { + public void startOnline(Long userId, Long lectureId) throws SQLException { lectureService.changeState(lectureId); } + + @Override + public void stopOnline(Long userId, Long lectureId) throws SQLException { + 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; + } + } } diff --git a/backend/src/main/java/com/edufocus/edufocus/ws/entity/vo/ChatUser.java b/backend/src/main/java/com/edufocus/edufocus/ws/entity/vo/ChatUser.java index 7a1d8d6..1a2a06a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/ws/entity/vo/ChatUser.java +++ b/backend/src/main/java/com/edufocus/edufocus/ws/entity/vo/ChatUser.java @@ -1,7 +1,7 @@ package com.edufocus.edufocus.ws.entity.vo; import com.edufocus.edufocus.lecture.entity.Lecture; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.ws.entity.dto.ChatUserDto; import jakarta.persistence.*; import lombok.*; diff --git a/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatServiceImpl.java index 7cc7866..29071cf 100644 --- a/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatServiceImpl.java @@ -3,7 +3,7 @@ package com.edufocus.edufocus.ws.service; import com.edufocus.edufocus.lecture.entity.Lecture; import com.edufocus.edufocus.lecture.repository.LectureRepository; -import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.repository.UserRepository; import com.edufocus.edufocus.ws.entity.dto.ChatUserDto; import com.edufocus.edufocus.ws.entity.vo.ChatUser; diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index a888094..aa22dc0 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1,47 +1,32 @@ spring.application.name=edufocus 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} livekit.api.secret=${LIVEKIT_API_SECRET:secret} # JWT Salt (??? ?? ???? ???) - jwt.salt=${SALT} - # Access Token ?? ?? (??? ??) #jwt.access-token.expiretime=3600000 -jwt.access-token.expiretime=360000 - +jwt.access-token.expiretime=3000000 # Refresh Token ?? ?? (??? ??) -jwt.refresh-token.expiretime=50400000 +jwt.refresh-token.expiretime=504000000 #jwt.refresh-token.expiretime=4000 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 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.hibernate.ddl-auto=update spring.jpa.show-sql=true - - management.endpoints.web.exposure.include=health,info management.endpoint.health.show-details=always - - - spring.rabbitmq.host=${RABBITMQ_HOST} spring.rabbitmq.port=${RABBITMQ_PORT} spring.rabbitmq.username=${RABBITMQ_USERNAME} spring.rabbitmq.password=${RABBITMQ_PASSWORD} - - image.path=${IMAGE_PATH} \ No newline at end of file diff --git a/backend/src/test/java/com/edufocus/edufocus/user/model/service/UserServiceImplTest.java b/backend/src/test/java/com/edufocus/edufocus/user/model/service/UserServiceImplTest.java index 2986703..a399bd8 100644 --- a/backend/src/test/java/com/edufocus/edufocus/user/model/service/UserServiceImplTest.java +++ b/backend/src/test/java/com/edufocus/edufocus/user/model/service/UserServiceImplTest.java @@ -1,8 +1,8 @@ //package com.edufocus.edufocus.user.model.service; // -//import com.edufocus.edufocus.user.model.entity.PasswordDto; -//import com.edufocus.edufocus.user.model.entity.User; -//import com.edufocus.edufocus.user.model.entity.UserRole; +//import com.edufocus.edufocus.user.model.entity.dto.PasswordDto; +//import com.edufocus.edufocus.user.model.entity.vo.User; +//import com.edufocus.edufocus.user.model.entity.vo.UserRole; //import com.edufocus.edufocus.user.model.exception.UserException; //import com.edufocus.edufocus.user.model.repository.UserRepository; //import org.junit.jupiter.api.BeforeEach;