Added API for getting notifications by compnayId and userId.

This commit is contained in:
piyushkag
2024-12-28 12:19:39 +05:30
parent 5d32e19dd4
commit 8074d5d73d
6 changed files with 48 additions and 3 deletions

View File

@@ -61,6 +61,9 @@ public class NotificationDao {
@Autowired
private ApplicationService applicationService;
@Autowired
private UserDao userDao;
public NotificationResponse sendNotification(NotificationReq notificationReq) {
// Ensure userId is properly set in notificationReq if not already
@@ -249,4 +252,20 @@ public class NotificationDao {
notificationEntity.setIsDeleted(true);
notificationRepository.save(notificationEntity);
}
public List<NotificationResponse> getNotificationByCompanyIdAndUserId(Long userId, Long companyId) {
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> notifications = notificationRepository.findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(userWithCompanyData.getId(),
userWithCompanyData.getUserId());
return notifications.stream().map(this::convertNotificationEntityToNotificationResponse).toList();
}
}