noti retire
This commit is contained in:
parent
2fc1587d18
commit
b0062b57a1
3 changed files with 59 additions and 26 deletions
|
|
@ -12,7 +12,9 @@ using BMA.EHR.Placement.Service.Requests;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
|
|
@ -31,18 +33,21 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public NotifyController(PlacementRepository repository,
|
||||
ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
NotificationRepository repositoryNoti,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_repository = repository;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
|
@ -50,6 +55,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -79,14 +85,27 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
// if (profile == null)
|
||||
// return Error(GlobalMessages.DataNotFound);
|
||||
|
||||
await _repositoryNoti.PushNotificationAsync(
|
||||
req.ReceiverUserId,
|
||||
req.Subject,
|
||||
req.Body,
|
||||
req.Payload,
|
||||
req.IsSendInbox,
|
||||
req.IsSendMail
|
||||
);
|
||||
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.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)
|
||||
{
|
||||
await _repositoryNoti.PushNotificationAsync(
|
||||
Guid.Parse(org.result.profileId),
|
||||
req.Subject,
|
||||
req.Body,
|
||||
req.Payload,
|
||||
req.IsSendInbox,
|
||||
req.IsSendMail
|
||||
);
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue