Skip to content

Commit

Permalink
Extended notificationOrderExt with sms properties (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
acn-sbuad authored Feb 5, 2024
1 parent 682f951 commit ffbd840
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/Altinn.Notifications/Mappers/OrderMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static NotificationOrderRequest MapToOrderRequest(this EmailNotificationO
return new NotificationOrderRequest(
extRequest.SendersReference,
creator,
new List<INotificationTemplate>() { emailTemplate },
[emailTemplate],
extRequest.RequestedSendTime.ToUniversalTime(),
NotificationChannel.Email,
recipients);
Expand All @@ -49,7 +49,7 @@ public static NotificationOrderRequest MapToOrderRequest(this SmsNotificationOrd
return new NotificationOrderRequest(
extRequest.SendersReference,
creator,
new List<INotificationTemplate>() { smsTemplate },
[smsTemplate],
extRequest.RequestedSendTime.ToUniversalTime(),
NotificationChannel.Sms,
recipients);
Expand Down Expand Up @@ -81,7 +81,13 @@ public static NotificationOrderExt MapToNotificationOrderExt(this NotificationOr
};

break;
default:
case NotificationTemplateType.Sms:
var smsTemplate = template! as SmsTemplate;
orderExt.SmsTemplate = new()
{
Body = smsTemplate!.Body,
SenderNumber = smsTemplate.SenderNumber
};
break;
}
}
Expand Down Expand Up @@ -160,7 +166,7 @@ internal static List<RecipientExt> MapToRecipientExt(this List<Recipient> recipi
recipients.Select(r => new RecipientExt
{
EmailAddress = GetEmailFromAddressList(r.AddressInfo),
MobileNumber = GetMobileNumberFromAddressList(r.AddressInfo)
MobileNumber = GetMobileNumberFromAddressList(r.AddressInfo)
}));

return recipientExt;
Expand Down
6 changes: 6 additions & 0 deletions src/Altinn.Notifications/Models/NotificationOrderExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public class NotificationOrderExt : IBaseNotificationOrderExt
[JsonPropertyName("emailTemplate")]
public EmailTemplateExt? EmailTemplate { get; set; }

/// <summary>
/// Gets or sets the smsTemplate
/// </summary>
[JsonPropertyName("smsTemplate")]
public SmsTemplateExt? SmsTemplate { get; set; }

/// <summary>
/// Gets or sets the link of the order
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions src/Altinn.Notifications/Models/SmsTemplateExt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;

namespace Altinn.Notifications.Models
{
/// <summary>
/// Template for an sms notification
/// </summary>
public class SmsTemplateExt
{
/// <summary>
/// Gets the number from which the SMS is created by the template
/// </summary>
[JsonPropertyName("senderNumber")]
public string SenderNumber { get; internal set; } = string.Empty;

/// <summary>
/// Gets the body of SMSs created by the template
/// </summary>
[JsonPropertyName("body")]
public string Body { get; internal set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ public void MapToNotificationOrderExt_AreEquivalent()
{
Id = Guid.NewGuid(),
SendersReference = "ref1337",
Templates = new List<INotificationTemplate>() { new EmailTemplate("from@domain.com", "email-subject", "email-body", EmailContentType.Plain) },
Templates = [
new EmailTemplate("from@domain.com", "email-subject", "email-body", EmailContentType.Plain),
new SmsTemplate("Altinn-test", "This is a text message")
],
RequestedSendTime = sendTime,
NotificationChannel = NotificationChannel.Email,
Creator = new Creator("ttd"),
Created = created,
Recipients = new List<Recipient>()
Recipients = []
};

NotificationOrderExt expected = new()
Expand All @@ -56,6 +59,11 @@ public void MapToNotificationOrderExt_AreEquivalent()
FromAddress = "from@domain.com",
Subject = "email-subject"
},
SmsTemplate = new SmsTemplateExt
{
Body = "This is a text message",
SenderNumber = "Altinn-test"
},
Links = new OrderResourceLinksExt()
{
Self = $"https://platform.at22.altinn.cloud/notifications/api/v1/orders/{order.Id}",
Expand Down

0 comments on commit ffbd840

Please sign in to comment.