using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; namespace BMA.EHR.Command.Service.Controllers { [Route("api/v{version:apiVersion}/message")] [ApiVersion("1.0")] [ApiController] [Produces("application/json")] [Authorize] [SwaggerTag("API ระบบ Inbox และ Notification")] public class MessageController : BaseController { #region " Fields " private readonly InboxRepository _inboxRepository; private readonly NotificationRepository _notificationRepository; #endregion #region " Constuctor and Destructor " public MessageController(InboxRepository inboxRepository, NotificationRepository notificationRepository) { _inboxRepository = inboxRepository; _notificationRepository = notificationRepository; } #endregion #region " Methods " /// /// แสดงข้อมูล Inbox ของ user ที่ Login /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("my-inboxes")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetMyInboxAsync(int page = 1, int pageSize = 20) { try { var inboxes = await _inboxRepository.GetMyInboxAsync(page, pageSize); return Success(inboxes); } catch { throw; } } /// /// ดูข้อมูล 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 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("my-notifications")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetMyNotificationAsync(int page = 1, int pageSize = 20) { try { var noti = await _notificationRepository.GetMyNotificationAsync(page, pageSize); return Success(noti); } catch { throw; } } /// /// แสดงข้อมูล Notification ของ user ที่ Login ที่ยังไม่ได้อ่าน /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("my-notifications/noread")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetMyNotificationAsyncNoread() { try { var noti = await _notificationRepository.GetMyNotificationAsyncNoread(); return Success(noti); } catch { throw; } } /// /// ลบข้อมูล 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 } }