Added Read/Unread filter in notification API.
This commit is contained in:
@@ -253,19 +253,26 @@ public class NotificationDao {
|
|||||||
notificationRepository.save(notificationEntity);
|
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);
|
List<NotificationEntity> notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalse(userId);
|
||||||
userDao.validateUser(userId);
|
UserWithCompanyEntity userWithCompany = null;
|
||||||
|
List<String> statusStrings;
|
||||||
UserWithCompanyEntity userWithCompanyData = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalseForNotification(userId, companyId);
|
if (companyId != null) {
|
||||||
if (userWithCompanyData == null) {
|
userWithCompany = companyDao.validateUserWithCompny(userId, companyId);
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.USER_MUST_BE_ASSOCIATED_WITH_COMPANY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<NotificationEntity> notifications = notificationRepository.findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(userWithCompanyData.getId(),
|
if (statuses != null) {
|
||||||
userWithCompanyData.getUserId());
|
statusStrings = statuses.stream().map(NotificationEnum::name)
|
||||||
return notifications.stream().map(this::convertNotificationEntityToNotificationResponse).toList();
|
.toList();
|
||||||
|
notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId, statusStrings);
|
||||||
|
|
||||||
|
if (userWithCompany != null) {
|
||||||
|
notificationEntities = notificationRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(userId, userWithCompany.getId(), statusStrings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return notificationEntities.stream().map(this::convertNotificationEntityToNotificationResponse).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ public interface NotificationService {
|
|||||||
|
|
||||||
public void deleteNotification(HttpServletRequest request, Long id);
|
public void deleteNotification(HttpServletRequest request, Long id);
|
||||||
|
|
||||||
public List<NotificationResponse> getNotificationsByCompanyIdAndUserId(Long userId, Long companyId);
|
public List<NotificationResponse> getNotificationsByCompanyIdAndUserId(Long userId, Long companyId, List<NotificationEnum> statuses);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class NotificationServiceImpl implements NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<NotificationResponse> getNotificationsByCompanyIdAndUserId(Long userId, Long companyId) {
|
public List<NotificationResponse> getNotificationsByCompanyIdAndUserId(Long userId, Long companyId, List<NotificationEnum> statuses) {
|
||||||
return notificationDao.getNotificationByCompanyIdAndUserId(userId, companyId);
|
return notificationDao.getNotificationByCompanyIdAndUserId(userId, companyId, statuses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,8 +33,8 @@ public interface NotificationApi {
|
|||||||
ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) })
|
ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) })
|
||||||
@PostMapping(value = "/user/{userId}/sent", consumes = "application/json", produces = "application/json")
|
@PostMapping(value = "/user/{userId}/sent", consumes = "application/json", produces = "application/json")
|
||||||
ResponseEntity<Response<NotificationResponse>> sendNotification(HttpServletRequest request, @RequestBody NotificationReq notificationReq,
|
ResponseEntity<Response<NotificationResponse>> sendNotification(HttpServletRequest request, @RequestBody NotificationReq notificationReq,
|
||||||
@Parameter(description = "The company id", required = false) @RequestParam(value = "companyId", required = false) Long companyId,
|
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId,
|
||||||
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId);
|
@Parameter(description = "The company id", required = false) @RequestParam(value = "companyId", required = false) Long companyId);
|
||||||
|
|
||||||
@Operation(summary = "Api to get notification by id", responses = { @ApiResponse(responseCode = "200", description = "OK"),
|
@Operation(summary = "Api to get notification by id", responses = { @ApiResponse(responseCode = "200", description = "OK"),
|
||||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
@@ -93,7 +93,8 @@ public interface NotificationApi {
|
|||||||
@GetMapping(value = "/user/{userId}/company/{companyId}/notifications", produces = "application/json")
|
@GetMapping(value = "/user/{userId}/company/{companyId}/notifications", produces = "application/json")
|
||||||
ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,
|
ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,
|
||||||
@Parameter(description = "The user id", required = true) @PathVariable(value = "userId") Long userId,
|
@Parameter(description = "The user id", required = true) @PathVariable(value = "userId") Long userId,
|
||||||
@Parameter(description = "The company ID", required = true) @PathVariable(value = "companyId") Long companyId);
|
@Parameter(description = "The company ID", required = true) @PathVariable(value = "companyId") Long companyId,
|
||||||
|
@Parameter(description = "The notification status", required = false) @RequestParam(value = "status", required = false) List<NotificationEnum> statuses);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ public class NotificationApiController implements NotificationApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,Long userId, Long companyId) {
|
public ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,Long userId, Long companyId, List<NotificationEnum> statuses) {
|
||||||
List<NotificationResponse> notificationResponses = notificationService.getNotificationsByCompanyIdAndUserId(userId, companyId);
|
List<NotificationResponse> notificationResponses = notificationService.getNotificationsByCompanyIdAndUserId(userId, companyId, statuses);
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(new Response<>(notificationResponses, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY)));
|
.body(new Response<>(notificationResponses, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user