From 879748d985684ebc7c9ef8eca8b11b238eaf12d6 Mon Sep 17 00:00:00 2001 From: yulmam <70622601+yulmam@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:58:23 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20lecture=20=EC=97=AD=EC=A0=95?= =?UTF-8?q?=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lecture/repository/LectureRepository.java | 2 +- .../lecture/service/LectureServiceImpl.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) 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;