noti report
This commit is contained in:
parent
85d9754db6
commit
037435b3bc
5 changed files with 83 additions and 26 deletions
|
|
@ -233,6 +233,54 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
|
|||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PushNotificationsAsync(Guid[] ReceiverUserIds, string Subject, string Body, string Payload = "", bool IsSendInbox = false, bool IsSendMail = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var ReceiverUserId in ReceiverUserIds)
|
||||
{
|
||||
_dbContext.Set<Notification>().Add(new Notification
|
||||
{
|
||||
Body = Body,
|
||||
ReceiverUserId = ReceiverUserId,
|
||||
Type = "",
|
||||
Payload = Payload,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
if (IsSendInbox == true)
|
||||
{
|
||||
_dbContext.Set<Inbox>().Add(new Inbox
|
||||
{
|
||||
Subject = Subject,
|
||||
Body = Body,
|
||||
ReceiverUserId = ReceiverUserId,
|
||||
Payload = Payload,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
}
|
||||
if (IsSendMail == true)
|
||||
{
|
||||
_emailSenderService.SendMail(Subject, Body, "kittapath@frappet.com");
|
||||
}
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public async Task PushNotificationAsyncV2(string? ReceiverUserId, string Subject, string Body, string Payload = "", bool IsSendInbox = false, bool IsSendMail = false)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -62,10 +62,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
[HttpPost()]
|
||||
public async Task<ActionResult<ResponseObject>> UpdatePropertyByUser([FromBody] NotiRequest req)
|
||||
{
|
||||
// var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.Id == req.ReceiverUserId);
|
||||
// if (profile == null)
|
||||
// return Error(GlobalMessages.DataNotFound);
|
||||
|
||||
await _repositoryNoti.PushNotificationAsync(
|
||||
Guid.Parse(req.ReceiverUserId),
|
||||
req.Subject,
|
||||
|
|
@ -81,10 +77,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
[HttpPost("keycloak")]
|
||||
public async Task<ActionResult<ResponseObject>> UpdatePropertyByUserKeycloak([FromBody] NotiRequest req)
|
||||
{
|
||||
// var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == req.ReceiverUserId);
|
||||
// if (profile == null)
|
||||
// return Error(GlobalMessages.DataNotFound);
|
||||
|
||||
var apiUrl = $"{_configuration["API"]}/org/profile/keycloakid/position/" + req.ReceiverUserId;
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
|
|
@ -112,18 +104,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
[HttpPost("profile")]
|
||||
public async Task<ActionResult<ResponseObject>> UpdatePropertyByUserProfile([FromBody] NotiRequest req)
|
||||
{
|
||||
// var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == req.ReceiverUserId);
|
||||
// if (profile == null)
|
||||
// return Error(GlobalMessages.DataNotFound);
|
||||
|
||||
// var apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/" + req.ReceiverUserId;
|
||||
// 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 (req.ReceiverUserId != null)
|
||||
{
|
||||
await _repositoryNoti.PushNotificationAsync(
|
||||
|
|
@ -136,7 +116,20 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
);
|
||||
}
|
||||
return Success();
|
||||
// }
|
||||
}
|
||||
|
||||
[HttpPost("profiles")]
|
||||
public async Task<ActionResult<ResponseObject>> UpdatePropertyByUserProfiles([FromBody] NotisRequest req)
|
||||
{
|
||||
await _repositoryNoti.PushNotificationsAsync(
|
||||
req.ReceiverUserIds.Select(x => Guid.Parse(x)).ToArray(),
|
||||
req.Subject,
|
||||
req.Body,
|
||||
req.Payload,
|
||||
req.IsSendInbox,
|
||||
req.IsSendMail
|
||||
);
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpPut("{id:length(36)}")]
|
||||
|
|
@ -170,11 +163,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
}
|
||||
return Success();
|
||||
}
|
||||
// var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(inbox.CreatedUserId));
|
||||
// if (profile == null)
|
||||
// return Error(GlobalMessages.DataNotFound);
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpPost("cronjob")]
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
{
|
||||
Id = x.Id,
|
||||
PersonalId = x.Id,
|
||||
x.profileId,
|
||||
Avatar = x.ProfileImg == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.ProfileImg.Id,
|
||||
FullName = $"{x.Prefix}{x.Firstname} {x.Lastname}",
|
||||
Prefix = x.Prefix,
|
||||
|
|
@ -203,6 +204,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
p.Lastname,
|
||||
p.IdCard,
|
||||
p.CitizenId,
|
||||
p.profileId,
|
||||
p.ExamNumber,
|
||||
p.posmasterId,
|
||||
p.root,
|
||||
|
|
@ -282,6 +284,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
{
|
||||
Id = x.Id,
|
||||
PersonalId = x.Id,
|
||||
x.profileId,
|
||||
Avatar = x.ProfileImg == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.ProfileImg.Id,
|
||||
FullName = $"{x.Prefix}{x.Firstname} {x.Lastname}",
|
||||
Prefix = x.Prefix,
|
||||
|
|
@ -341,6 +344,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
p.Lastname,
|
||||
p.IdCard,
|
||||
p.CitizenId,
|
||||
p.profileId,
|
||||
p.ExamNumber,
|
||||
p.posmasterId,
|
||||
p.root,
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
{
|
||||
p.Id,
|
||||
p.citizenId,
|
||||
p.profileId,
|
||||
p.prefix,
|
||||
p.firstName,
|
||||
p.lastName,
|
||||
|
|
|
|||
16
BMA.EHR.Placement.Service/Requests/NotisRequest.cs
Normal file
16
BMA.EHR.Placement.Service/Requests/NotisRequest.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Placement.Service.Requests
|
||||
{
|
||||
public class NotisRequest
|
||||
{
|
||||
public string Subject { get; set; }
|
||||
public string Body { get; set; }
|
||||
public string Payload { get; set; }
|
||||
public string[] ReceiverUserIds { get; set; }
|
||||
public bool IsSendMail { get; set; }
|
||||
public bool IsSendInbox { get; set; }
|
||||
public bool IsSendNotification { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue