From a4ae42f072a0d480fa75d04d2592d77720180a5d Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 21 Apr 2019 15:03:31 +0400 Subject: [PATCH] #60 added sorting --- .../ru/ulstu/conference/repository/ConferenceRepository.java | 5 +++-- .../java/ru/ulstu/conference/service/ConferenceService.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 99f311e..1c58883 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -9,6 +9,7 @@ import ru.ulstu.user.model.User; import java.util.List; public interface ConferenceRepository extends JpaRepository { - @Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) AND (YEAR(c.beginDate) = :year OR :year IS NULL)") - List filter(@Param("user") User user, @Param("year") Integer year); + @Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " + + "AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC") + List findByUserAndYear(@Param("user") User user, @Param("year") Integer year); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index b03e9d3..490d05e 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -1,6 +1,7 @@ package ru.ulstu.conference.service; import org.apache.commons.lang3.StringUtils; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.conference.model.Conference; @@ -59,7 +60,7 @@ public class ConferenceService { public List findAll() { - return conferenceRepository.findAll(); + return conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate")); } public List findAllDto() { @@ -158,7 +159,7 @@ public class ConferenceService { } public List filter(ConferenceFilterDto conferenceFilterDto) { - return convert(conferenceRepository.filter( + return convert(conferenceRepository.findByUserAndYear( conferenceFilterDto.getFilterUserId() == null ? null : userService.findById(conferenceFilterDto.getFilterUserId()), conferenceFilterDto.getYear()), ConferenceDto::new);