diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/repository/LectureRepository.java b/backend/src/main/java/com/edufocus/edufocus/lecture/repository/LectureRepository.java index eb708fd..34edc2a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/lecture/repository/LectureRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/repository/LectureRepository.java @@ -14,7 +14,7 @@ public interface LectureRepository extends JpaRepository { List findAllByUserId(Long userId); - List findLecturesByUserId(Long userId); + List findLecturesByUserIdOrderById(Long userId); Lecture findByIdAndUserId(long id, 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 c434f54..acddb48 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 @@ -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 findAllLecture() { - List lectureList = lectureRepository.findAll(); + List lectureList = lectureRepository.findAll(Sort.by(Sort.Direction.DESC, "id")); List lectureSearchResponseList = new ArrayList<>(); for (Lecture lecture : lectureList) { @@ -190,7 +191,7 @@ public class LectureServiceImpl implements LectureService { List myLectureList = new ArrayList<>(); if (user.getRole() == UserRole.ADMIN) { - List lectureList = lectureRepository.findLecturesByUserId(userId); + List 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() { + @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;