Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into feature/GEPAFINBE-167

This commit is contained in:
rajesh
2025-02-25 12:14:10 +05:30
74 changed files with 1508 additions and 195 deletions

View File

@@ -4,6 +4,7 @@ import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
@@ -426,4 +427,47 @@ public class NotificationDao {
sendNotification(notificationReq);
}
public PageableResponseBean<List<NotificationResponse>> getNotificationsByUserIdAndCompanyIdByPagination(Long userId, Long companyId, NotificationRequestBean notificationRequestBean) {
UserWithCompanyEntity userWithCompany;
if (companyId != null) {
userWithCompany = companyDao.validateUserWithCompny(userId, companyId);
}else {
userWithCompany=null;
}
Integer pageNo = null;
Integer pageLimit = null;
if (notificationRequestBean.getGlobalFilters() != null) {
pageNo = notificationRequestBean.getGlobalFilters().getPage();
pageLimit = notificationRequestBean.getGlobalFilters().getLimit();
}
if (pageLimit == null || pageLimit <= 0) {
pageLimit = GepafinConstant.DEFAULT_PAGE_LIMIT;
}
if (pageNo == null || pageNo <= 0) {
pageNo = GepafinConstant.DEFAULT_PAGE;
}
Specification<NotificationEntity> spec = search(userId, notificationRequestBean);
if(userWithCompany!=null){
spec = spec.and((root, query, criteriaBuilder) ->
criteriaBuilder.equal(root.get("userWithCompany").get("id"), userWithCompany.getId()));
}
Page<NotificationEntity> entityPage = notificationRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
// Prepare the response
List<NotificationResponse> notificationResponses = entityPage.getContent().stream()
.map(notification -> {
NotificationResponse response = convertNotificationEntityToNotificationResponse(notification);
return response;
})
.collect(Collectors.toList());
PageableResponseBean<List<NotificationResponse>> pageableResponseBean = new PageableResponseBean<>();
pageableResponseBean.setBody(notificationResponses);
pageableResponseBean.setCurrentPage(entityPage.getNumber() + 1); // Page numbers typically start from 0, so add 1 for user-friendly indexing
pageableResponseBean.setTotalPages(entityPage.getTotalPages());
pageableResponseBean.setTotalRecords(entityPage.getTotalElements());
pageableResponseBean.setPageSize(entityPage.getSize());
return pageableResponseBean;
}
}