From 356c6eb9c098d447aa602dc59fa21b3426ec2d13 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Sun, 24 Dec 2023 15:05:44 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1no?= =?UTF-8?q?ti=20by=20keycloak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/NotifyController.cs | 41 +++++++++++++++++++ .../Requests/NotiReplyRequest.cs | 15 +++++++ 2 files changed, 56 insertions(+) create mode 100644 BMA.EHR.Placement.Service/Requests/NotiReplyRequest.cs diff --git a/BMA.EHR.Placement.Service/Controllers/NotifyController.cs b/BMA.EHR.Placement.Service/Controllers/NotifyController.cs index 23959e2a..63f01670 100644 --- a/BMA.EHR.Placement.Service/Controllers/NotifyController.cs +++ b/BMA.EHR.Placement.Service/Controllers/NotifyController.cs @@ -72,6 +72,47 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } + [HttpPost("keycloak")] + public async Task> UpdatePropertyByUserKeycloak([FromBody] NotiRequest req) + { + var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == req.ReceiverUserId); + if (profile == null) + return Error(GlobalMessages.DataNotFound); + + await _repositoryNoti.PushNotificationAsync( + profile.Id, + req.Subject, + req.Body, + req.Payload, + req.IsSendInbox, + req.IsSendMail + ); + + return Success(); + } + + [HttpPut("{id:length(36)}")] + public async Task> ReplyPropertyByUser([FromBody] NotiReplyRequest req, Guid id) + { + var inbox = await _context.Inboxes.FirstOrDefaultAsync(x => x.Id == id); + if (inbox == null) + return Error(GlobalMessages.DataNotFound); + var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(inbox.CreatedUserId)); + if (profile == null) + return Error(GlobalMessages.DataNotFound); + + await _repositoryNoti.PushNotificationAsync( + profile.Id, + req.Subject, + req.Body, + req.Payload, + req.IsSendInbox, + req.IsSendMail + ); + + return Success(); + } + [HttpPost("cronjob")] public async Task> CornjobProbation([FromBody] NotiCronjobProbationRequest req) { diff --git a/BMA.EHR.Placement.Service/Requests/NotiReplyRequest.cs b/BMA.EHR.Placement.Service/Requests/NotiReplyRequest.cs new file mode 100644 index 00000000..f60e0f04 --- /dev/null +++ b/BMA.EHR.Placement.Service/Requests/NotiReplyRequest.cs @@ -0,0 +1,15 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Placement.Service.Requests +{ + public class NotiReplyRequest + { + public string Subject { get; set; } = ""; + public string Body { get; set; } = ""; + public string Payload { get; set; } = ""; + public bool IsSendMail { get; set; } = true; + public bool IsSendInbox { get; set; } = true; + public bool IsSendNotification { get; set; } = true; + } +}