Merge branch 'be/Lecture' into 'backend'
refactor: Lecture 강의 상세조회 리팩토링 See merge request s11-webmobile1-sub2/S11P12A701!12
This commit is contained in:
commit
cc195bb447
@ -21,6 +21,8 @@ public interface LectureService {
|
|||||||
|
|
||||||
List<LectureSearchResponse> findAllLecture();
|
List<LectureSearchResponse> findAllLecture();
|
||||||
|
|
||||||
|
String getUserStatus(Long userId, Lecture lecture);
|
||||||
|
|
||||||
LectureDetailResponse findLectureById(Long userId, long lectureId);
|
LectureDetailResponse findLectureById(Long userId, long lectureId);
|
||||||
|
|
||||||
List<LectureSearchResponse> findMyLecture(long userId);
|
List<LectureSearchResponse> findMyLecture(long userId);
|
||||||
|
@ -134,55 +134,58 @@ public class LectureServiceImpl implements LectureService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LectureDetailResponse findLectureById(Long userId, long lectureId) {
|
public String getUserStatus(Long userId, Lecture lecture) {
|
||||||
Optional<Lecture> lecture = lectureRepository.findById(lectureId);
|
|
||||||
if (lecture.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String userStatus;
|
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
userStatus = String.valueOf(UserStatus.NOT_ENROLLED);
|
return String.valueOf(UserStatus.NOT_ENROLLED);
|
||||||
} else {
|
|
||||||
User user = userRepository.findById(userId).get();
|
|
||||||
|
|
||||||
if (user.getRole() == UserRole.ADMIN) {
|
|
||||||
if (lecture.get().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);
|
User user = userRepository.findById(userId).orElseThrow(NoSuchElementException::new);
|
||||||
|
UserRole userRole = user.getRole();
|
||||||
|
|
||||||
|
if (userRole == UserRole.ADMIN) {
|
||||||
|
if (lecture.getUser() == user) {
|
||||||
|
return String.valueOf(UserStatus.MANAGED_BY_ME);
|
||||||
|
}
|
||||||
|
return String.valueOf(UserStatus.MANAGED_BY_OTHERS);
|
||||||
|
}
|
||||||
|
|
||||||
|
Registration registration = registrationRepository.findByUserIdAndLectureId(userId, lecture.getId());
|
||||||
|
|
||||||
if (registration == null) {
|
if (registration == null) {
|
||||||
userStatus = String.valueOf(UserStatus.NOT_ENROLLED);
|
return String.valueOf(UserStatus.NOT_ENROLLED);
|
||||||
} else if (registration.getStatus() == RegistrationStatus.ACCEPTED) {
|
|
||||||
userStatus = String.valueOf(UserStatus.ENROLLED);
|
|
||||||
} else {
|
|
||||||
userStatus = String.valueOf(UserStatus.PENDING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (registration.getStatus() == RegistrationStatus.ACCEPTED) {
|
||||||
|
return String.valueOf(UserStatus.ENROLLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.valueOf(UserStatus.PENDING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LectureDetailResponse findLectureById(Long userId, long lectureId) {
|
||||||
|
Lecture lecture = lectureRepository.findById(lectureId).orElseThrow(NoSuchElementException::new);
|
||||||
|
|
||||||
|
String userStatus = getUserStatus(userId, lecture);
|
||||||
|
|
||||||
return LectureDetailResponse.builder()
|
return LectureDetailResponse.builder()
|
||||||
.id(lecture.get().getId())
|
.id(lecture.getId())
|
||||||
.title(lecture.get().getTitle())
|
.title(lecture.getTitle())
|
||||||
.description(lecture.get().getDescription())
|
.description(lecture.getDescription())
|
||||||
.plan(lecture.get().getPlan())
|
.plan(lecture.getPlan())
|
||||||
.image(lecture.get().getImage())
|
.image(lecture.getImage())
|
||||||
.startDate(lecture.get().getStartDate())
|
.startDate(lecture.getStartDate())
|
||||||
.endDate(lecture.get().getEndDate())
|
.endDate(lecture.getEndDate())
|
||||||
.time(lecture.get().getTime())
|
.time(lecture.getTime())
|
||||||
.online(lecture.get().isOnline())
|
.online(lecture.isOnline())
|
||||||
.teacherName(lecture.get().getUser().getName())
|
.teacherName(lecture.getUser().getName())
|
||||||
.status(userStatus)
|
.status(userStatus)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LectureSearchResponse> findMyLecture(long userId) {
|
public List<LectureSearchResponse> findMyLecture(long userId) {
|
||||||
User user = userRepository.findById(userId).get();
|
User user = userRepository.findById(userId).orElseThrow(NoSuchElementException::new);
|
||||||
|
|
||||||
List<LectureSearchResponse> myLectureList = new ArrayList<>();
|
List<LectureSearchResponse> myLectureList = new ArrayList<>();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user