Merge branch 'Be/Lecture' into 'backend'
[Back-End] feat : lecture 역정렬 See merge request s11-webmobile1-sub2/S11P12A701!157
This commit is contained in:
commit
e4d8ae4046
@ -14,7 +14,7 @@ public interface LectureRepository extends JpaRepository<Lecture, Long> {
|
||||
|
||||
List<Lecture> findAllByUserId(Long userId);
|
||||
|
||||
List<Lecture> findLecturesByUserId(Long userId);
|
||||
List<Lecture> findLecturesByUserIdOrderById(Long userId);
|
||||
|
||||
Lecture findByIdAndUserId(long id, long userId);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.edufocus.edufocus.user.model.entity.vo.UserRole;
|
||||
import com.edufocus.edufocus.user.model.repository.UserRepository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -118,7 +119,7 @@ public class LectureServiceImpl implements LectureService {
|
||||
|
||||
@Override
|
||||
public List<LectureSearchResponse> findAllLecture() {
|
||||
List<Lecture> lectureList = lectureRepository.findAll();
|
||||
List<Lecture> lectureList = lectureRepository.findAll(Sort.by(Sort.Direction.DESC, "id"));
|
||||
|
||||
List<LectureSearchResponse> lectureSearchResponseList = new ArrayList<>();
|
||||
for (Lecture lecture : lectureList) {
|
||||
@ -190,7 +191,7 @@ public class LectureServiceImpl implements LectureService {
|
||||
List<LectureSearchResponse> myLectureList = new ArrayList<>();
|
||||
|
||||
if (user.getRole() == UserRole.ADMIN) {
|
||||
List<Lecture> lectureList = lectureRepository.findLecturesByUserId(userId);
|
||||
List<Lecture> lectureList = lectureRepository.findLecturesByUserIdOrderById(userId);
|
||||
for (Lecture lecture : lectureList) {
|
||||
LectureSearchResponse lectureSearchResponse = LectureSearchResponse.builder()
|
||||
.id(lecture.getId())
|
||||
@ -214,6 +215,18 @@ public class LectureServiceImpl implements LectureService {
|
||||
myLectureList.add(lectureSearchResponse);
|
||||
}
|
||||
}
|
||||
Collections.sort(myLectureList, new Comparator<LectureSearchResponse>() {
|
||||
@Override
|
||||
public int compare(LectureSearchResponse lsr1, LectureSearchResponse lsr2) {
|
||||
long lsr1Id = lsr1.getId();
|
||||
long lsr2Id = lsr2.getId();
|
||||
if(lsr2Id > lsr1Id)
|
||||
return 1;
|
||||
else if(lsr2Id == lsr1Id)
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return myLectureList;
|
||||
|
Loading…
Reference in New Issue
Block a user