From 73ece9ee40bef81cc58febc3e4ae04a2cc752d65 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Jan 2024 16:39:47 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=20paging=20noti?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/MessageQueue/InboxRepository.cs | 12 ++++++++---- .../MessageQueue/NotificationRepository.cs | 12 ++++++++---- .../Controllers/MessageController.cs | 8 ++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs b/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs index 1b3d8dc1..c28def82 100644 --- a/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs +++ b/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs @@ -33,7 +33,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue #region " Methods " - public async Task> GetMyInboxAsync() + public async Task GetMyInboxAsync(int page = 1, int pageSize = 25) { try { @@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue // throw new Exception(GlobalMessages.DataNotFound); } - var data = await _dbContext.Set() + var data_search = await _dbContext.Set() .Where(x => x.ReceiverUserId == profile.Id) .Where(x => x.IsOpen == false) .OrderByDescending(x => x.ReceiveDate) @@ -61,10 +61,14 @@ namespace BMA.EHR.Application.Repositories.MessageQueue OpenDate = x.OpenDate, Payload = x.Payload == "" ? null : JsonConvert.DeserializeObject(Regex.Unescape(x.Payload)) }) - .Take(20) .ToListAsync(); - return data; + var data = data_search + .Skip((page - 1) * pageSize) + .Take(pageSize) + .ToList(); + var _data = new { data, total = data_search.Count() }; + return _data; } catch { diff --git a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs index 1d95e591..e0a0fe9d 100644 --- a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs +++ b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs @@ -37,7 +37,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue #region " Methods " - public async Task> GetMyNotificationAsync() + public async Task GetMyNotificationAsync(int page = 1, int pageSize = 25) { try { @@ -50,7 +50,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue // throw new Exception(GlobalMessages.DataNotFound); } - var data = await _dbContext.Set() + var data_search = await _dbContext.Set() .Where(x => x.ReceiverUserId == profile.Id) .Where(x => x.IsOpen == false) .OrderByDescending(x => x.ReceiveDate) @@ -65,10 +65,14 @@ namespace BMA.EHR.Application.Repositories.MessageQueue OpenDate = x.OpenDate, Payload = x.Payload == "" ? null : JsonConvert.DeserializeObject(Regex.Unescape(x.Payload)) }) - .Take(20) .ToListAsync(); - return data; + var data = data_search + .Skip((page - 1) * pageSize) + .Take(pageSize) + .ToList(); + var _data = new { data, total = data_search.Count() }; + return _data; } catch { diff --git a/BMA.EHR.Command.Service/Controllers/MessageController.cs b/BMA.EHR.Command.Service/Controllers/MessageController.cs index 6e33170d..cde70c46 100644 --- a/BMA.EHR.Command.Service/Controllers/MessageController.cs +++ b/BMA.EHR.Command.Service/Controllers/MessageController.cs @@ -45,11 +45,11 @@ namespace BMA.EHR.Command.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task> GetMyInboxAsync() + public async Task> GetMyInboxAsync(int page = 1, int pageSize = 20) { try { - var inboxes = await _inboxRepository.GetMyInboxAsync(); + var inboxes = await _inboxRepository.GetMyInboxAsync(page, pageSize); return Success(inboxes); } @@ -120,11 +120,11 @@ namespace BMA.EHR.Command.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task> GetMyNotificationAsync() + public async Task> GetMyNotificationAsync(int page = 1, int pageSize = 20) { try { - var noti = await _notificationRepository.GetMyNotificationAsync(); + var noti = await _notificationRepository.GetMyNotificationAsync(page, pageSize); return Success(noti); }