From 2ba9ef84fda7071e02a0a02ba4f76827c024a102 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 11 Sep 2023 12:02:01 +0700 Subject: [PATCH] api delete noti --- .../MessageQueue/InboxRepository.cs | 41 ++++++++++ .../MessageQueue/NotificationRepository.cs | 21 ++++++ .../Controllers/MessageController.cs | 75 +++++++++++++++++++ 3 files changed, 137 insertions(+) diff --git a/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs b/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs index 917ea815..1137deb2 100644 --- a/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs +++ b/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs @@ -43,6 +43,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue var data = await _dbContext.Set() .Where(x => x.ReceiverUserId == profile.Id) + .Where(x => x.IsOpen == false) .OrderByDescending(x => x.ReceiveDate) .ToListAsync(); @@ -54,6 +55,46 @@ namespace BMA.EHR.Application.Repositories.MessageQueue } } + public async Task DeleteMyInboxAsync(Guid id) + { + try + { + var inbox = await _dbContext.Set() + .FirstOrDefaultAsync(p => p.Id == id); + + if (inbox != null) + { + inbox.IsOpen = true; + // _dbContext.Set().Remove(inbox); + await _dbContext.SaveChangesAsync(); + } + } + catch + { + throw; + } + } + + public async Task GetByIdMyInboxAsync(Guid id) + { + try + { + var inbox = await _dbContext.Set() + .FirstOrDefaultAsync(p => p.Id == id); + + if (inbox != null) + { + inbox.OpenDate = DateTime.Now; + // _dbContext.Set().Remove(inbox); + await _dbContext.SaveChangesAsync(); + } + } + catch + { + throw; + } + } + #endregion } } diff --git a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs index 87023463..4a15c85a 100644 --- a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs +++ b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs @@ -43,6 +43,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue var data = await _dbContext.Set() .Where(x => x.ReceiverUserId == profile.Id) + .Where(x => x.IsOpen == false) .OrderByDescending(x => x.ReceiveDate) .ToListAsync(); @@ -54,6 +55,26 @@ namespace BMA.EHR.Application.Repositories.MessageQueue } } + public async Task DeleteMyNotificationAsync(Guid id) + { + try + { + var notification = await _dbContext.Set() + .FirstOrDefaultAsync(p => p.Id == id); + + if (notification != null) + { + notification.IsOpen = true; + // _dbContext.Set().Remove(notification); + await _dbContext.SaveChangesAsync(); + } + } + catch + { + throw; + } + } + public async Task PushNotificationAsync(Guid ReceiverUserId, string Subject, string Body, string Payload = "", bool IsSendInbox = false, bool IsSendMail = false) { try diff --git a/BMA.EHR.Command.Service/Controllers/MessageController.cs b/BMA.EHR.Command.Service/Controllers/MessageController.cs index 96282067..6e33170d 100644 --- a/BMA.EHR.Command.Service/Controllers/MessageController.cs +++ b/BMA.EHR.Command.Service/Controllers/MessageController.cs @@ -59,6 +59,56 @@ namespace BMA.EHR.Command.Service.Controllers } } + /// + /// ดูข้อมูล Inbox ของ user ที่ Login + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("my-inboxes/{id:length(36)}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetByIdMyInboxAsync(Guid id) + { + try + { + await _inboxRepository.GetByIdMyInboxAsync(id); + + return Success(); + } + catch + { + throw; + } + } + + /// + /// ลบข้อมูล Inbox ของ user ที่ Login + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpDelete("my-inboxes/{id:length(36)}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> DeleteMyInboxAsync(Guid id) + { + try + { + await _inboxRepository.DeleteMyInboxAsync(id); + + return Success(); + } + catch + { + throw; + } + } + /// /// แสดงข้อมูล Notification ของ user ที่ Login /// @@ -84,6 +134,31 @@ namespace BMA.EHR.Command.Service.Controllers } } + /// + /// ลบข้อมูล Notification ของ user ที่ Login + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpDelete("my-notifications/{id:length(36)}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> DeleteMyNotificationAsync(Guid id) + { + try + { + await _notificationRepository.DeleteMyNotificationAsync(id); + + return Success(); + } + catch + { + throw; + } + } + #endregion }