no message

This commit is contained in:
Kittapath 2024-06-25 09:27:34 +07:00
parent c1cfaa3b6d
commit 468bd38e0b
9 changed files with 247 additions and 166 deletions

View file

@ -6,7 +6,9 @@ using BMA.EHR.Domain.Models.Notifications;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
namespace BMA.EHR.Application.Repositories.MessageQueue
@ -17,16 +19,19 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
#endregion
#region " Constructor and Destuctor "
public InboxRepository(IApplicationDBContext dbContext,
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
}
#endregion
@ -37,17 +42,35 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
{
try
{
var profile = await _dbContext.Set<Profile>()
.FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
// var profile = await _dbContext.Set<Profile>()
// .FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
if (profile == null)
// if (profile == null)
// {
// return new List<InboxResponse>();
// // throw new Exception(GlobalMessages.DataNotFound);
// }
var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position";
var profileId = "";
using (var client = new HttpClient())
{
return new List<InboxResponse>();
// throw new Exception(GlobalMessages.DataNotFound);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return new List<InboxResponse>();
profileId = org.result.rootId == null ? "" : org.result.profileId;
}
if (profileId == null || profileId == "")
return new List<InboxResponse>();
var data_search = await _dbContext.Set<Inbox>()
.Where(x => x.ReceiverUserId == profile.Id)
.Where(x => x.ReceiverUserId == Guid.Parse(profileId))
.Where(x => x.DeleteDate == null)
.OrderByDescending(x => x.ReceiveDate)
.Select(x => new InboxResponse

View file

@ -7,7 +7,9 @@ using BMA.EHR.Domain.Models.Notifications;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
namespace BMA.EHR.Application.Repositories.MessageQueue
@ -19,6 +21,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly EmailSenderService _emailSenderService;
private readonly IConfiguration _configuration;
#endregion
@ -26,11 +29,13 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
public NotificationRepository(IApplicationDBContext dbContext,
EmailSenderService emailSenderService,
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_emailSenderService = emailSenderService;
_configuration = configuration;
}
#endregion
@ -50,8 +55,26 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
// // throw new Exception(GlobalMessages.DataNotFound);
// }
var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position";
var profileId = "";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return new List<InboxResponse>();
profileId = org.result.rootId == null ? "" : org.result.profileId;
}
if (profileId == null || profileId == "")
return new List<InboxResponse>();
var data_search = await _dbContext.Set<Notification>()
.Where(x => x.KeycloakUserId == UserId)
.Where(x => x.ReceiverUserId == Guid.Parse(profileId))
.Where(x => x.DeleteDate == null)
.OrderByDescending(x => x.ReceiveDate)
.ToListAsync();
@ -107,9 +130,26 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
// {
// return 0;
// }
var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position";
var profileId = "";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return 0;
profileId = org.result.rootId == null ? "" : org.result.profileId;
}
if (profileId == null || profileId == "")
return 0;
var data_search = await _dbContext.Set<Notification>()
.Where(x => x.KeycloakUserId == UserId)
.Where(x => x.ReceiverUserId == Guid.Parse(profileId))
.Where(x => x.DeleteDate == null)
.Where(x => x.IsOpen == false)
.OrderByDescending(x => x.ReceiveDate)