Added Read/Unread filter in notification API.

This commit is contained in:
piyushkag
2024-12-30 15:25:32 +05:30
parent 172c2bec62
commit 8fba9a1c81
5 changed files with 26 additions and 18 deletions

View File

@@ -253,19 +253,26 @@ public class NotificationDao {
notificationRepository.save(notificationEntity);
}
public List<NotificationResponse> getNotificationByCompanyIdAndUserId(Long userId, Long companyId) {
public List<NotificationResponse> getNotificationByCompanyIdAndUserId(Long userId, Long companyId, List<NotificationEnum> statuses) {
companyDao.validateCompany(companyId);
userDao.validateUser(userId);
UserWithCompanyEntity userWithCompanyData = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalseForNotification(userId, companyId);
if (userWithCompanyData == null) {
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.USER_MUST_BE_ASSOCIATED_WITH_COMPANY);
List<NotificationEntity> notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalse(userId);
UserWithCompanyEntity userWithCompany = null;
List<String> statusStrings;
if (companyId != null) {
userWithCompany = companyDao.validateUserWithCompny(userId, companyId);
}
List<NotificationEntity> notifications = notificationRepository.findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(userWithCompanyData.getId(),
userWithCompanyData.getUserId());
return notifications.stream().map(this::convertNotificationEntityToNotificationResponse).toList();
if (statuses != null) {
statusStrings = statuses.stream().map(NotificationEnum::name)
.toList();
notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId, statusStrings);
if (userWithCompany != null) {
notificationEntities = notificationRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(userId, userWithCompany.getId(), statusStrings);
}
}
return notificationEntities.stream().map(this::convertNotificationEntityToNotificationResponse).toList();
}
}