History paging
This commit is contained in:
parent
36678b25c7
commit
c9e595797d
|
@ -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<History, Long> {
|
|||
|
||||
List<History> findAllByProbeOrderByIdDesc(Probe probe);
|
||||
|
||||
Page<History> findAllByProbe(Probe probe, Pageable pageable);
|
||||
|
||||
@Query("SELECT h FROM History h WHERE h.probe.id = :#{#probe.id} and h.type.id = :#{#type.id}")
|
||||
List<History> findAllByProbeAndType(@Param("probe") Probe probe, @Param("type") MetaHistoryType type);
|
||||
}
|
||||
|
|
|
@ -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<History> readAllByProbe(Probe probe) {
|
||||
return this.historyDAO.findAllByProbeOrderByIdDesc(probe);
|
||||
}
|
||||
// public List<History> readAllByProbe(Probe probe) {
|
||||
// return this.historyDAO.findAllByProbeOrderByIdDesc(probe);
|
||||
// }
|
||||
|
||||
public List<History> readAllByProbeAndType(Probe probe, MetaHistoryType type) {
|
||||
return this.historyDAO.findAllByProbeAndType(probe, type);
|
||||
}
|
||||
|
||||
public Page<History> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,12 +41,6 @@ public class HistoryServiceTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void readAllHistoryByProbe() {
|
||||
List<History> result = this.historyService.readAllByProbe(new Probe(1));
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
|
@ -54,4 +48,10 @@ public class HistoryServiceTest {
|
|||
List<History> result = this.historyService.readAllByProbeAndType(new Probe(1), new MetaHistoryType(1));
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void readAllByProbeWithPaging() {
|
||||
// List<History> result = this.historyService.readAllByProbe(new Probe(1), 0, 10);
|
||||
// Assert.assertEquals(10, result.size());
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user