diff --git a/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java b/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java index 763f5c5..24d4842 100644 --- a/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java +++ b/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java @@ -3,6 +3,8 @@ package com.loafle.overflow.module.history.dao; import com.loafle.overflow.module.history.model.History; import com.loafle.overflow.module.meta.model.MetaHistoryType; import com.loafle.overflow.module.probe.model.Probe; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -18,6 +20,8 @@ public interface HistoryDAO extends JpaRepository { List findAllByProbeOrderByIdDesc(Probe probe); + Page findAllByProbe(Probe probe, Pageable pageable); + @Query("SELECT h FROM History h WHERE h.probe.id = :#{#probe.id} and h.type.id = :#{#type.id}") List findAllByProbeAndType(@Param("probe") Probe probe, @Param("type") MetaHistoryType type); } diff --git a/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java b/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java index e9dc35e..8200d55 100644 --- a/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java +++ b/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java @@ -5,6 +5,10 @@ import com.loafle.overflow.module.history.model.History; import com.loafle.overflow.module.meta.model.MetaHistoryType; import com.loafle.overflow.module.probe.model.Probe; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import java.util.List; @@ -19,11 +23,17 @@ public class HistoryService { return this.historyDAO.save(history); } - public List readAllByProbe(Probe probe) { - return this.historyDAO.findAllByProbeOrderByIdDesc(probe); - } +// public List readAllByProbe(Probe probe) { +// return this.historyDAO.findAllByProbeOrderByIdDesc(probe); +// } public List readAllByProbeAndType(Probe probe, MetaHistoryType type) { return this.historyDAO.findAllByProbeAndType(probe, type); } + + public Page readAllByProbe(Probe probe, int pageNo, int countPerPage) { + Pageable pageRequest = + new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id")); + return this.historyDAO.findAllByProbe(probe, pageRequest); + } } diff --git a/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java b/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java index 4e1afcf..b62da4d 100644 --- a/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java @@ -41,12 +41,6 @@ public class HistoryServiceTest { } } - @Test - @Ignore - public void readAllHistoryByProbe() { - List result = this.historyService.readAllByProbe(new Probe(1)); - Assert.assertNotNull(result); - } @Test @Ignore @@ -54,4 +48,10 @@ public class HistoryServiceTest { List result = this.historyService.readAllByProbeAndType(new Probe(1), new MetaHistoryType(1)); Assert.assertNotNull(result); } + +// @Test +// public void readAllByProbeWithPaging() { +// List result = this.historyService.readAllByProbe(new Probe(1), 0, 10); +// Assert.assertEquals(10, result.size()); +// } }