feat: Lecture 강의 상세조회 수정
강의 상세조회시 유저정보를 확인해 수강중인지 여부를 추가로 전달
This commit is contained in:
parent
be1d1293ed
commit
f3859e6a65
@ -67,13 +67,21 @@ public class LectureController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{lectureId}")
|
@GetMapping("/{lectureId}")
|
||||||
public ResponseEntity<?> findById(@PathVariable long lectureId) {
|
public ResponseEntity<?> findById(@RequestHeader(value = "Authorization", required = false) String accessToken, @PathVariable long lectureId) {
|
||||||
LectureDetailResponse lectureDetailResponse = lectureService.findLectureById(lectureId);
|
Long userId = null;
|
||||||
|
|
||||||
|
if (accessToken != null) {
|
||||||
|
userId = Long.parseLong(jwtUtil.getUserId(accessToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
LectureDetailResponse lectureDetailResponse = lectureService.findLectureById(userId, lectureId);
|
||||||
|
|
||||||
if (lectureDetailResponse == null) {
|
if (lectureDetailResponse == null) {
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return new ResponseEntity<>(lectureDetailResponse, HttpStatus.OK);
|
return new ResponseEntity<>(lectureDetailResponse, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,4 +30,6 @@ public class LectureDetailResponse {
|
|||||||
private String plan;
|
private String plan;
|
||||||
|
|
||||||
private boolean online;
|
private boolean online;
|
||||||
|
|
||||||
|
private String status;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.edufocus.edufocus.lecture.entity;
|
||||||
|
|
||||||
|
public enum UserStatus {
|
||||||
|
MANAGED_BY_ME, // 내가 관리하는 강의 - 강사
|
||||||
|
MANAGED_BY_OTHERS, // 내가 관리하지 않은 강의 - 강사
|
||||||
|
ENROLLED, // 내가 수강 중인 강의 - 학생
|
||||||
|
PENDING, // 내가 수강신청하고 승인 대기 중인 강의 - 학생
|
||||||
|
NOT_ENROLLED // 내가 수강신청하지 않은 강의 - 학생/비로그인
|
||||||
|
}
|
@ -19,7 +19,7 @@ public interface LectureService {
|
|||||||
|
|
||||||
List<LectureSearchResponse> findAllLecture();
|
List<LectureSearchResponse> findAllLecture();
|
||||||
|
|
||||||
LectureDetailResponse findLectureById(long lectureId);
|
LectureDetailResponse findLectureById(Long userId, long lectureId);
|
||||||
|
|
||||||
List<LectureSearchResponse> findMyLecture(long userId);
|
List<LectureSearchResponse> findMyLecture(long userId);
|
||||||
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package com.edufocus.edufocus.lecture.service;
|
package com.edufocus.edufocus.lecture.service;
|
||||||
|
|
||||||
import com.edufocus.edufocus.lecture.entity.Lecture;
|
import com.edufocus.edufocus.lecture.entity.*;
|
||||||
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.repository.LectureRepository;
|
import com.edufocus.edufocus.lecture.repository.LectureRepository;
|
||||||
import com.edufocus.edufocus.registration.entity.Registration;
|
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.registration.repository.RegistrationRepository;
|
||||||
import com.edufocus.edufocus.user.model.entity.User;
|
import com.edufocus.edufocus.user.model.entity.User;
|
||||||
import com.edufocus.edufocus.user.model.entity.UserRole;
|
import com.edufocus.edufocus.user.model.entity.UserRole;
|
||||||
@ -110,14 +108,38 @@ public class LectureServiceImpl implements LectureService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LectureDetailResponse findLectureById(long lectureId) {
|
public LectureDetailResponse findLectureById(Long userId, long lectureId) {
|
||||||
|
|
||||||
Lecture lecture = lectureRepository.findById(lectureId).get();
|
Lecture lecture = lectureRepository.findById(lectureId).get();
|
||||||
|
|
||||||
if (lecture == null) {
|
if (lecture == null) {
|
||||||
return 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()
|
LectureDetailResponse lectureDetailResponse = new LectureDetailResponse().builder()
|
||||||
.id(lecture.getId())
|
.id(lecture.getId())
|
||||||
.title(lecture.getTitle())
|
.title(lecture.getTitle())
|
||||||
@ -128,6 +150,7 @@ public class LectureServiceImpl implements LectureService {
|
|||||||
.plan(lecture.getPlan())
|
.plan(lecture.getPlan())
|
||||||
.online(lecture.isOnline())
|
.online(lecture.isOnline())
|
||||||
.teacherName(lecture.getUser().getName())
|
.teacherName(lecture.getUser().getName())
|
||||||
|
.status(userStatus)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return lectureDetailResponse;
|
return lectureDetailResponse;
|
||||||
|
@ -10,4 +10,6 @@ import java.util.List;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface RegistrationRepository extends JpaRepository<Registration, Long> {
|
public interface RegistrationRepository extends JpaRepository<Registration, Long> {
|
||||||
List<Registration> findAllByUserId(@Param("userId") Long userId);
|
List<Registration> findAllByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
|
Registration findByUserIdAndLectureId(Long userId, Long lectureId);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user