แก้บั้ก และเพิ่ม api inbox noti

This commit is contained in:
Suphonchai Phoonsawat 2023-08-09 20:28:56 +07:00
parent 060765d373
commit aacbcfee32
6 changed files with 220 additions and 5 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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
}
}

View file

@ -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
}
}