Skip to content

Commit

Permalink
fix: 🐛 datatable list page out of order (#25)
Browse files Browse the repository at this point in the history
* fix: 🐛 datatable list page out of order

* refactor: ♻️ change calculation for total

* refactor: ♻️ remove commented out code

* refactor: ♻️ removed unnecessary condition
  • Loading branch information
prakhar-s authored Feb 28, 2024
1 parent 9812de8 commit 3608f76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/strandls/dataTable/dao/DataTableDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public DataTable findById(Long id) {
}

@SuppressWarnings("unchecked")
public List<DataTable> getDataTableListByIds(String dataTableType, String orderBy, List<Long> dataTableIds) {
public List<DataTable> getDataTableListByIds(String dataTableType, String orderBy, List<Long> dataTableIds,
Integer offset, Integer limit) {
String qry = orderBy == null
? "from DataTable where id IN :dataTableIds and dataTableType = :dataTableType and isRemoved = false order by lastRevised desc"
: "from DataTable where id IN :dataTableIds and dataTableType = :dataTableType and isRemoved = false order by createdOn desc";
Expand All @@ -55,6 +56,9 @@ public List<DataTable> getDataTableListByIds(String dataTableType, String orderB
Query<DataTable> query = session.createQuery(qry);
query.setParameter("dataTableIds", dataTableIds);
query.setParameter("dataTableType", dataTableType);
query.setFirstResult(offset);
query.setMaxResults(limit);

result = query.getResultList();
} catch (Exception e) {
logger.error(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,16 @@ public DataTableList dataTableList(String orderBy, Integer limit, Integer offset
if (ugId != null && !ugId.isEmpty()) {
UserGroupDatatableFetch userGroupDatatableFetch = new UserGroupDatatableFetch();
userGroupDatatableFetch.setUserGroupId(Long.parseLong(ugId));
userGroupDatatableFetch.setOffset(offset);
userGroupDatatableFetch.setLimit(limit);
userGroupDatatableFetch.setOffset(null);
userGroupDatatableFetch.setLimit(null);

UserGroupDatatableMapping res = userGroupService.getDataTablebyUserGroupId(userGroupDatatableFetch);
if (res != null && res.getTotal() > 0) {
orderBy = orderBy != null && orderBy.contains("lastRevised") ? null : orderBy;
List<Long> dataTableIds = res.getUserGroupDataTableList().stream()
.map((item) -> item.getDataTableId()).collect(Collectors.toList());
datatableList = dataTableDao.getDataTableListByIds("OBSERVATIONS", orderBy, dataTableIds);
total = datatableList.size() != dataTableIds.size()
? res.getTotal() - (dataTableIds.size() - datatableList.size())
: res.getTotal();
datatableList = dataTableDao.getDataTableListByIds("OBSERVATIONS", orderBy, dataTableIds, offset,
limit);
total = res.getTotal();
}

} else {
Expand Down

0 comments on commit 3608f76

Please sign in to comment.