แก้บั้ก และเพิ่ม api inbox noti
This commit is contained in:
parent
060765d373
commit
aacbcfee32
6 changed files with 220 additions and 5 deletions
|
|
@ -20,6 +20,8 @@ namespace BMA.EHR.Application
|
|||
services.AddTransient<RetirementRepository>();
|
||||
services.AddTransient<UserProfileRepository>();
|
||||
services.AddTransient<OrganizationCommonRepository>();
|
||||
services.AddTransient<InboxRepository>();
|
||||
services.AddTransient<NotificationRepository>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1007,15 +1007,21 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
}
|
||||
|
||||
public async Task UpdatePlacementSalaryAsync(Guid placementProfileId, UpdatePlacementSalaryRequest req)
|
||||
public async Task UpdatePlacementSalaryAsync(Guid personalId, UpdatePlacementSalaryRequest req)
|
||||
{
|
||||
try
|
||||
{
|
||||
var current = await _dbContext.Set<CommandReceiver>()
|
||||
.FirstOrDefaultAsync(x => x.Id == personalId);
|
||||
|
||||
if (current == null)
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
||||
var placementProfile = await _dbContext.Set<PlacementProfile>()
|
||||
.FirstOrDefaultAsync(p => p.Id == placementProfileId);
|
||||
.FirstOrDefaultAsync(p => p.Id == current.RefPlacementProfileId);
|
||||
|
||||
if (placementProfile == null)
|
||||
throw new Exception($"Invalid placement profile: {placementProfileId}");
|
||||
throw new Exception($"Invalid placement profile: {current.RefPlacementProfileId}");
|
||||
|
||||
placementProfile.Amount = req.SalaryAmount;
|
||||
placementProfile.PositionSalaryAmount = req.PositionSalaryAmount;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Domain.Models.HR;
|
||||
using BMA.EHR.Domain.Models.Notifications;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories.MessageQueue
|
||||
{
|
||||
public class InboxRepository : GenericRepository<Guid, Inbox>
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destuctor "
|
||||
|
||||
public InboxRepository(IApplicationDBContext dbContext,
|
||||
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
public async Task<List<Inbox>> GetMyInboxAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile = await _dbContext.Set<Profile>()
|
||||
.FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
|
||||
|
||||
if (profile == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
var data = await _dbContext.Set<Inbox>()
|
||||
.Where(x => x.ReceiverUserId == profile.Id)
|
||||
.OrderByDescending(x => x.ReceiveDate)
|
||||
.ToListAsync();
|
||||
|
||||
return data;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Domain.Models.HR;
|
||||
using BMA.EHR.Domain.Models.Notifications;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories.MessageQueue
|
||||
{
|
||||
public class NotificationRepository : GenericRepository<Guid, Notification>
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destuctor "
|
||||
|
||||
public NotificationRepository(IApplicationDBContext dbContext,
|
||||
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
public async Task<List<Notification>> GetMyNotificationAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile = await _dbContext.Set<Profile>()
|
||||
.FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
|
||||
|
||||
if (profile == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
var data = await _dbContext.Set<Notification>()
|
||||
.Where(x => x.ReceiverUserId == profile.Id)
|
||||
.OrderByDescending(x => x.ReceiveDate)
|
||||
.ToListAsync();
|
||||
|
||||
return data;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
90
BMA.EHR.Command.Service/Controllers/MessageController.cs
Normal file
90
BMA.EHR.Command.Service/Controllers/MessageController.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using Amazon.S3.Model.Internal.MarshallTransformations;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Application.Requests.Commands;
|
||||
using BMA.EHR.Command.Service.Requests;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue