hrms-api-backend/BMA.EHR.Command.Service/Controllers/MessageController.cs
2023-08-09 20:28:56 +07:00

90 lines
3.2 KiB
C#

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 "
/// <summary>
/// แสดงข้อมูล Inbox ของ user ที่ Login
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("my-inboxes")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetMyInboxAsync()
{
try
{
var inboxes = await _inboxRepository.GetMyInboxAsync();
return Success(inboxes);
}
catch
{
throw;
}
}
/// <summary>
/// แสดงข้อมูล Notification ของ user ที่ Login
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("my-notifications")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetMyNotificationAsync()
{
try
{
var noti = await _notificationRepository.GetMyNotificationAsync();
return Success(noti);
}
catch
{
throw;
}
}
#endregion
}
}