From 957bdc03ac7f40b9a0a7a8796fe3ab8a29426166 Mon Sep 17 00:00:00 2001 From: Freddy Rodriguez Date: Mon, 8 May 2017 12:45:59 -0600 Subject: [PATCH] #11451 Send total number of notifications in getNotifications end point (#11523) --- .../business/NewNotificationCacheImpl.java | 2 +- .../api/v1/notification/NotificationResource.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/notifications/business/NewNotificationCacheImpl.java b/dotCMS/src/main/java/com/dotcms/notifications/business/NewNotificationCacheImpl.java index 2d6032c1ad15..54dff5212f36 100644 --- a/dotCMS/src/main/java/com/dotcms/notifications/business/NewNotificationCacheImpl.java +++ b/dotCMS/src/main/java/com/dotcms/notifications/business/NewNotificationCacheImpl.java @@ -224,7 +224,7 @@ protected Long getUserCount(final String userId) { Long count = null; final String primaryKey = - this.getUserCountPrimaryKey(userId); + this.getAllNotificationsPrimaryKey(userId); try { diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/notification/NotificationResource.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/notification/NotificationResource.java index 6756caefbca5..247947feda15 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/notification/NotificationResource.java +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/notification/NotificationResource.java @@ -117,8 +117,12 @@ public Response getNotifications (@Context final HttpServletRequest request, //notificationAPI.markNotificationsAsRead(user.getUserId()); // Let's get the total count - final Long total = allUsers ? - this.notificationAPI.getNotificationsCount(): + Long notificationsCount = allUsers ? + this.notificationAPI.getNotificationsCount() : + this.notificationAPI.getNotificationsCount(user.getUserId()); + + final Long totalUnreadNotifications = allUsers ? + this.notificationAPI.getNotificationsCount() : this.notificationAPI.getNewNotificationsCount(user.getUserId()); final List notifications = allUsers ? @@ -139,8 +143,9 @@ public Response getNotifications (@Context final HttpServletRequest request, }); } - return Response.ok(new ResponseEntityView(map("count", total, "notifications", notificationsResult))) - .header("Content-Range", "items " + offset + "-" + limit + "/" + total) + return Response.ok(new ResponseEntityView(map("totalUnreadNotifications", totalUnreadNotifications, + "notifications", notificationsResult, "total", notificationsCount))) + .header("Content-Range", "items " + offset + "-" + limit + "/" + totalUnreadNotifications) .build(); // 200 } catch (Exception e) { // this is an unknown error, so we report as a 500.