diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/controller/LectureController.java b/backend/src/main/java/com/edufocus/edufocus/lecture/controller/LectureController.java index ec71557..6c4e0f8 100644 --- a/backend/src/main/java/com/edufocus/edufocus/lecture/controller/LectureController.java +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/controller/LectureController.java @@ -67,13 +67,21 @@ public class LectureController { } @GetMapping("/{lectureId}") - public ResponseEntity findById(@PathVariable long lectureId) { - LectureDetailResponse lectureDetailResponse = lectureService.findLectureById(lectureId); + public ResponseEntity findById(@RequestHeader(value = "Authorization", required = false) String accessToken, @PathVariable long lectureId) { + Long userId = null; + + if (accessToken != null) { + userId = Long.parseLong(jwtUtil.getUserId(accessToken)); + } + + LectureDetailResponse lectureDetailResponse = lectureService.findLectureById(userId, lectureId); if (lectureDetailResponse == null) { return new ResponseEntity<>(HttpStatus.NO_CONTENT); } + + return new ResponseEntity<>(lectureDetailResponse, HttpStatus.OK); } diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/entity/LectureDetailResponse.java b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/LectureDetailResponse.java index 08f9558..9c14a49 100644 --- a/backend/src/main/java/com/edufocus/edufocus/lecture/entity/LectureDetailResponse.java +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/LectureDetailResponse.java @@ -30,4 +30,6 @@ public class LectureDetailResponse { private String plan; private boolean online; + + private String status; } diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/entity/UserStatus.java b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/UserStatus.java new file mode 100644 index 0000000..3fbf6ba --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/UserStatus.java @@ -0,0 +1,9 @@ +package com.edufocus.edufocus.lecture.entity; + +public enum UserStatus { + MANAGED_BY_ME, // 내가 관리하는 강의 - 강사 + MANAGED_BY_OTHERS, // 내가 관리하지 않은 강의 - 강사 + ENROLLED, // 내가 수강 중인 강의 - 학생 + PENDING, // 내가 수강신청하고 승인 대기 중인 강의 - 학생 + NOT_ENROLLED // 내가 수강신청하지 않은 강의 - 학생/비로그인 +} 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 29eb908..e82bd25 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 @@ -19,7 +19,7 @@ public interface LectureService { List findAllLecture(); - LectureDetailResponse findLectureById(long lectureId); + LectureDetailResponse findLectureById(Long userId, long lectureId); List findMyLecture(long userId); 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 1e808ac..1971488 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 @@ -1,11 +1,9 @@ package com.edufocus.edufocus.lecture.service; -import com.edufocus.edufocus.lecture.entity.Lecture; -import com.edufocus.edufocus.lecture.entity.LectureCreateRequest; -import com.edufocus.edufocus.lecture.entity.LectureSearchResponse; -import com.edufocus.edufocus.lecture.entity.LectureDetailResponse; +import com.edufocus.edufocus.lecture.entity.*; 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; @@ -110,14 +108,38 @@ public class LectureServiceImpl implements LectureService { } @Override - public LectureDetailResponse findLectureById(long lectureId) { - + public LectureDetailResponse findLectureById(Long userId, long lectureId) { Lecture lecture = lectureRepository.findById(lectureId).get(); if (lecture == null) { return null; } + String userStatus; + if (userId == null) { + userStatus = String.valueOf(UserStatus.NOT_ENROLLED); + } else { + User user = userRepository.findById(userId).get(); + + if (user.getRole() == UserRole.ADMIN) { + if (lecture.getUser().getId() == user.getId()) { + userStatus = String.valueOf(UserStatus.MANAGED_BY_ME); + } else{ + userStatus = String.valueOf(UserStatus.MANAGED_BY_OTHERS); + } + } else { + Registration registration = registrationRepository.findByUserIdAndLectureId(userId, lectureId); + + if (registration == null) { + userStatus = String.valueOf(UserStatus.NOT_ENROLLED); + } else if (registration.getStatus() == RegistrationStatus.ACCEPTED) { + userStatus = String.valueOf(UserStatus.ENROLLED); + } else { + userStatus = String.valueOf(UserStatus.PENDING); + } + } + } + LectureDetailResponse lectureDetailResponse = new LectureDetailResponse().builder() .id(lecture.getId()) .title(lecture.getTitle()) @@ -128,6 +150,7 @@ public class LectureServiceImpl implements LectureService { .plan(lecture.getPlan()) .online(lecture.isOnline()) .teacherName(lecture.getUser().getName()) + .status(userStatus) .build(); return lectureDetailResponse; diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java b/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java index 34358a2..251acaf 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java @@ -10,4 +10,6 @@ import java.util.List; @Repository public interface RegistrationRepository extends JpaRepository { List findAllByUserId(@Param("userId") Long userId); + + Registration findByUserIdAndLectureId(Long userId, Long lectureId); }