Merge pull request #68 from TeamBNBN/be/Lecture
feat: Lecture 강의 상세조회 수정
This commit is contained in:
commit
16fc14a19d
@ -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);
|
||||
}
|
||||
|
||||
|
@ -30,4 +30,6 @@ public class LectureDetailResponse {
|
||||
private String plan;
|
||||
|
||||
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();
|
||||
|
||||
LectureDetailResponse findLectureById(long lectureId);
|
||||
LectureDetailResponse findLectureById(Long userId, long lectureId);
|
||||
|
||||
List<LectureSearchResponse> findMyLecture(long userId);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -10,4 +10,6 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface RegistrationRepository extends JpaRepository<Registration, Long> {
|
||||
List<Registration> findAllByUserId(@Param("userId") Long userId);
|
||||
|
||||
Registration findByUserIdAndLectureId(Long userId, Long lectureId);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user