From a83899a5bf4b2854262f5438b06a9e814c46271d Mon Sep 17 00:00:00 2001 From: jarednimble Date: Thu, 19 Jan 2023 15:57:12 +0000 Subject: [PATCH] Refactored email service and added join a mat templating --- ...AutoPopulatedMoqPropertiesCustomization.cs | 18 ++++ .../Automapper/AutoMapperSetupTests.cs | 43 +++++++++ ...Dfe.Academies.External.Web.UnitTest.csproj | 2 + .../PropertiesPostprocessor.cs | 23 +++++ .../AutoMapper/AutoMapperProfile.cs | 8 ++ .../AutoMapper/AutoMapperSetup.cs | 18 ++++ .../Dfe.Academies.External.Web.csproj | 2 + .../Dtos/EmailVariablesDto.cs | 8 ++ .../ContributorNotifyTemplateFactory.cs | 19 ++++ .../IContributorNotifyTemplateFactory.cs | 10 +++ .../Helpers/NotifyTemplateSettings.cs | 10 +++ .../FormAMatChairContributor.cs | 19 ++++ .../FormAMatNonChairContributor.cs | 18 ++++ .../EmailTemplates/IContributorTemplate.cs | 10 +++ .../Models/EmailTemplates/IEmailTemplate.cs | 6 ++ .../JoinAMatChairContributor.cs | 19 ++++ .../JoinAMatNonChairContributor.cs | 19 ++++ .../Pages/AddAContributor.cshtml.cs | 12 ++- Dfe.Academies.External.Web/Program.cs | 14 +++ .../Services/ContributorEmailSenderService.cs | 90 +++++-------------- .../IContributorEmailSenderService.cs | 12 +-- Dfe.Academies.External.Web/appsettings.json | 8 +- 22 files changed, 313 insertions(+), 75 deletions(-) create mode 100644 Dfe.Academies.External.Web.UnitTest/AutoPopulatedMoqPropertiesCustomization.cs create mode 100644 Dfe.Academies.External.Web.UnitTest/Automapper/AutoMapperSetupTests.cs create mode 100644 Dfe.Academies.External.Web.UnitTest/PropertiesPostprocessor.cs create mode 100644 Dfe.Academies.External.Web/AutoMapper/AutoMapperProfile.cs create mode 100644 Dfe.Academies.External.Web/AutoMapper/AutoMapperSetup.cs create mode 100644 Dfe.Academies.External.Web/Dtos/EmailVariablesDto.cs create mode 100644 Dfe.Academies.External.Web/Factories/ContributorNotifyTemplateFactory.cs create mode 100644 Dfe.Academies.External.Web/Factories/IContributorNotifyTemplateFactory.cs create mode 100644 Dfe.Academies.External.Web/Helpers/NotifyTemplateSettings.cs create mode 100644 Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatChairContributor.cs create mode 100644 Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatNonChairContributor.cs create mode 100644 Dfe.Academies.External.Web/Models/EmailTemplates/IContributorTemplate.cs create mode 100644 Dfe.Academies.External.Web/Models/EmailTemplates/IEmailTemplate.cs create mode 100644 Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatChairContributor.cs create mode 100644 Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatNonChairContributor.cs diff --git a/Dfe.Academies.External.Web.UnitTest/AutoPopulatedMoqPropertiesCustomization.cs b/Dfe.Academies.External.Web.UnitTest/AutoPopulatedMoqPropertiesCustomization.cs new file mode 100644 index 000000000..9f4dcbcb6 --- /dev/null +++ b/Dfe.Academies.External.Web.UnitTest/AutoPopulatedMoqPropertiesCustomization.cs @@ -0,0 +1,18 @@ +using AutoFixture; +using AutoFixture.AutoMoq; +using AutoFixture.Kernel; + +namespace Dfe.Academies.External.Web.UnitTest; + +public class AutoPopulatedMoqPropertiesCustomization : ICustomization +{ + public void Customize(IFixture fixture) + { + fixture.Customizations.Add( + new PropertiesPostprocessor( + new MockPostprocessor( + new MethodInvoker( + new MockConstructorQuery())))); + fixture.ResidueCollectors.Add(new MockRelay()); + } +} diff --git a/Dfe.Academies.External.Web.UnitTest/Automapper/AutoMapperSetupTests.cs b/Dfe.Academies.External.Web.UnitTest/Automapper/AutoMapperSetupTests.cs new file mode 100644 index 000000000..0cae4b224 --- /dev/null +++ b/Dfe.Academies.External.Web.UnitTest/Automapper/AutoMapperSetupTests.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Reflection; +using AutoFixture; +using AutoMapper; +using AutoMapper.Internal; +using Dfe.Academies.External.Web.AutoMapper; +using Dfe.Academies.External.Web.Dtos; +using Dfe.Academies.External.Web.Models.EmailTemplates; +using FluentAssertions; +using NUnit.Framework; + +namespace Dfe.Academies.External.Web.UnitTest.Automapper +{ + public class AutoMapperSetupTests + { + private Fixture _fixture = new Fixture(); + private IMapper _mapper; + public AutoMapperSetupTests() + { + _fixture.Customize(new AutoPopulatedMoqPropertiesCustomization()); + + var mapperConfig = new MapperConfiguration(cfg => + { + cfg.AddProfile(); + }); + + mapperConfig.AssertConfigurationIsValid(); + _mapper = new Mapper(mapperConfig); + } + + [Test] + public void Map_WhenGivenEmailVariablesDto_ReturnsDictionary() + { + var emailTemplate = _fixture.Create(); + var result = _mapper.Map>(emailTemplate); + foreach (var propertyInfo in emailTemplate.GetType().GetProperties()) + { + var value = propertyInfo.GetValue(emailTemplate, null); + result.Values.Should().Contain(value); + } + } + } +} diff --git a/Dfe.Academies.External.Web.UnitTest/Dfe.Academies.External.Web.UnitTest.csproj b/Dfe.Academies.External.Web.UnitTest/Dfe.Academies.External.Web.UnitTest.csproj index 26032e81b..e8e8f74d5 100644 --- a/Dfe.Academies.External.Web.UnitTest/Dfe.Academies.External.Web.UnitTest.csproj +++ b/Dfe.Academies.External.Web.UnitTest/Dfe.Academies.External.Web.UnitTest.csproj @@ -47,7 +47,9 @@ + + diff --git a/Dfe.Academies.External.Web.UnitTest/PropertiesPostprocessor.cs b/Dfe.Academies.External.Web.UnitTest/PropertiesPostprocessor.cs new file mode 100644 index 000000000..acf868a07 --- /dev/null +++ b/Dfe.Academies.External.Web.UnitTest/PropertiesPostprocessor.cs @@ -0,0 +1,23 @@ +using AutoFixture.Kernel; + +namespace Dfe.Academies.External.Web.UnitTest; + +public class PropertiesPostprocessor : ISpecimenBuilder +{ + private readonly ISpecimenBuilder builder; + + public PropertiesPostprocessor(ISpecimenBuilder builder) + { + this.builder = builder; + } + + public object Create(object request, ISpecimenContext context) + { + dynamic s = this.builder.Create(request, context); + if (s is NoSpecimen) + return s; + + s.SetupAllProperties(); + return s; + } +} diff --git a/Dfe.Academies.External.Web/AutoMapper/AutoMapperProfile.cs b/Dfe.Academies.External.Web/AutoMapper/AutoMapperProfile.cs new file mode 100644 index 000000000..d38ee3cca --- /dev/null +++ b/Dfe.Academies.External.Web/AutoMapper/AutoMapperProfile.cs @@ -0,0 +1,8 @@ +using AutoMapper; + +namespace Dfe.Academies.External.Web.AutoMapper; + +public class AutoMapperProfile : Profile +{ + public AutoMapperProfile() => AutoMapperSetup.AddMappings(this); +} diff --git a/Dfe.Academies.External.Web/AutoMapper/AutoMapperSetup.cs b/Dfe.Academies.External.Web/AutoMapper/AutoMapperSetup.cs new file mode 100644 index 000000000..32fa11fb1 --- /dev/null +++ b/Dfe.Academies.External.Web/AutoMapper/AutoMapperSetup.cs @@ -0,0 +1,18 @@ +using AutoMapper; +using Dfe.Academies.External.Web.Dtos; + +namespace Dfe.Academies.External.Web.AutoMapper; + +public static class AutoMapperSetup +{ + public static void AddMappings(Profile profile) + { + profile.CreateMap>() + .ConvertUsing(x => new Dictionary + { + {"invitee_name", x.ContributorName}, + {"school", x.SchoolName}, + {"inviting_contributor", x.InvitingUsername} + }); + } +} diff --git a/Dfe.Academies.External.Web/Dfe.Academies.External.Web.csproj b/Dfe.Academies.External.Web/Dfe.Academies.External.Web.csproj index 09b4bb3a2..55e845392 100644 --- a/Dfe.Academies.External.Web/Dfe.Academies.External.Web.csproj +++ b/Dfe.Academies.External.Web/Dfe.Academies.External.Web.csproj @@ -16,6 +16,8 @@ + + diff --git a/Dfe.Academies.External.Web/Dtos/EmailVariablesDto.cs b/Dfe.Academies.External.Web/Dtos/EmailVariablesDto.cs new file mode 100644 index 000000000..db207e51e --- /dev/null +++ b/Dfe.Academies.External.Web/Dtos/EmailVariablesDto.cs @@ -0,0 +1,8 @@ +namespace Dfe.Academies.External.Web.Dtos; + +public record EmailVariablesDto +{ + public string ContributorName { get; set; } + public string SchoolName { get; set; } + public string InvitingUsername { get; set; } +} diff --git a/Dfe.Academies.External.Web/Factories/ContributorNotifyTemplateFactory.cs b/Dfe.Academies.External.Web/Factories/ContributorNotifyTemplateFactory.cs new file mode 100644 index 000000000..0ce937d32 --- /dev/null +++ b/Dfe.Academies.External.Web/Factories/ContributorNotifyTemplateFactory.cs @@ -0,0 +1,19 @@ +using Dfe.Academies.External.Web.Enums; +using Dfe.Academies.External.Web.Models.EmailTemplates; + +namespace Dfe.Academies.External.Web.Factories; + +public class ContributorNotifyTemplateFactory : IContributorNotifyTemplateFactory +{ + private readonly List _emailTemplates; + + public ContributorNotifyTemplateFactory(IEnumerable emailTemplates) + { + _emailTemplates = emailTemplates.ToList(); + } + public IContributorTemplate Get(ApplicationTypes applicationType, SchoolRoles schoolRole) + { + return _emailTemplates.First(x => + x.ApplicationType == applicationType && x.SchoolRole == schoolRole); + } +} diff --git a/Dfe.Academies.External.Web/Factories/IContributorNotifyTemplateFactory.cs b/Dfe.Academies.External.Web/Factories/IContributorNotifyTemplateFactory.cs new file mode 100644 index 000000000..d7cd3eb4b --- /dev/null +++ b/Dfe.Academies.External.Web/Factories/IContributorNotifyTemplateFactory.cs @@ -0,0 +1,10 @@ +using Dfe.Academies.External.Web.Enums; +using Dfe.Academies.External.Web.Models.EmailTemplates; + +namespace Dfe.Academies.External.Web.Factories +{ + public interface IContributorNotifyTemplateFactory + { + IContributorTemplate Get(ApplicationTypes applicationType, SchoolRoles schoolRole); + } +} diff --git a/Dfe.Academies.External.Web/Helpers/NotifyTemplateSettings.cs b/Dfe.Academies.External.Web/Helpers/NotifyTemplateSettings.cs new file mode 100644 index 000000000..eb5f7a9cc --- /dev/null +++ b/Dfe.Academies.External.Web/Helpers/NotifyTemplateSettings.cs @@ -0,0 +1,10 @@ +namespace Dfe.Academies.External.Web.Helpers +{ + public class NotifyTemplateSettings + { + public string JamChairTemplateId { get; set; } + public string JamNonChairTemplateId { get; set; } + public string FamChairTemplateId { get; set; } + public string FamNonChairTemplateId { get; set; } + } +} diff --git a/Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatChairContributor.cs b/Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatChairContributor.cs new file mode 100644 index 000000000..030e68889 --- /dev/null +++ b/Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatChairContributor.cs @@ -0,0 +1,19 @@ +using System.Dynamic; +using Dfe.Academies.External.Web.Enums; +using Dfe.Academies.External.Web.Helpers; +using Microsoft.Extensions.Options; + +namespace Dfe.Academies.External.Web.Models.EmailTemplates +{ + public class FormAMatChairContributor : IContributorTemplate + { + public ApplicationTypes ApplicationType => ApplicationTypes.FormAMat; + public SchoolRoles SchoolRole => SchoolRoles.ChairOfGovernors; + public string TemplateId { get; } + + public FormAMatChairContributor(IOptions notifyTemplateSettings) + { + TemplateId = notifyTemplateSettings.Value.FamChairTemplateId; + } + } +} diff --git a/Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatNonChairContributor.cs b/Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatNonChairContributor.cs new file mode 100644 index 000000000..a14faec05 --- /dev/null +++ b/Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatNonChairContributor.cs @@ -0,0 +1,18 @@ +using Dfe.Academies.External.Web.Enums; +using Dfe.Academies.External.Web.Helpers; +using Microsoft.Extensions.Options; + +namespace Dfe.Academies.External.Web.Models.EmailTemplates +{ + public class FormAMatNonChairContributor : IContributorTemplate + { + public ApplicationTypes ApplicationType => ApplicationTypes.FormAMat; + public SchoolRoles SchoolRole => SchoolRoles.Other; + public string TemplateId { get; } + + public FormAMatNonChairContributor(IOptions notifyTemplateSettings) + { + TemplateId = notifyTemplateSettings.Value.FamNonChairTemplateId; + } + } +} diff --git a/Dfe.Academies.External.Web/Models/EmailTemplates/IContributorTemplate.cs b/Dfe.Academies.External.Web/Models/EmailTemplates/IContributorTemplate.cs new file mode 100644 index 000000000..d64f29fed --- /dev/null +++ b/Dfe.Academies.External.Web/Models/EmailTemplates/IContributorTemplate.cs @@ -0,0 +1,10 @@ +using Dfe.Academies.External.Web.Enums; + +namespace Dfe.Academies.External.Web.Models.EmailTemplates +{ + public interface IContributorTemplate : IEmailTemplate + { + public SchoolRoles SchoolRole { get; } + public ApplicationTypes ApplicationType { get; } + } +} diff --git a/Dfe.Academies.External.Web/Models/EmailTemplates/IEmailTemplate.cs b/Dfe.Academies.External.Web/Models/EmailTemplates/IEmailTemplate.cs new file mode 100644 index 000000000..9820a5263 --- /dev/null +++ b/Dfe.Academies.External.Web/Models/EmailTemplates/IEmailTemplate.cs @@ -0,0 +1,6 @@ +namespace Dfe.Academies.External.Web.Models.EmailTemplates; + +public interface IEmailTemplate +{ + public string TemplateId { get; } +} diff --git a/Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatChairContributor.cs b/Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatChairContributor.cs new file mode 100644 index 000000000..e36019e53 --- /dev/null +++ b/Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatChairContributor.cs @@ -0,0 +1,19 @@ +using System.Dynamic; +using Dfe.Academies.External.Web.Enums; +using Dfe.Academies.External.Web.Helpers; +using Microsoft.Extensions.Options; + +namespace Dfe.Academies.External.Web.Models.EmailTemplates +{ + public class JoinAMatChairContributor : IContributorTemplate + { + public ApplicationTypes ApplicationType => ApplicationTypes.JoinAMat; + public SchoolRoles SchoolRole => SchoolRoles.ChairOfGovernors; + public string TemplateId { get; } + + public JoinAMatChairContributor(IOptions notifyTemplateSettings) + { + TemplateId = notifyTemplateSettings.Value.JamChairTemplateId; + } + } +} diff --git a/Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatNonChairContributor.cs b/Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatNonChairContributor.cs new file mode 100644 index 000000000..d7ff96887 --- /dev/null +++ b/Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatNonChairContributor.cs @@ -0,0 +1,19 @@ +using System.Dynamic; +using Dfe.Academies.External.Web.Enums; +using Dfe.Academies.External.Web.Helpers; +using Microsoft.Extensions.Options; + +namespace Dfe.Academies.External.Web.Models.EmailTemplates +{ + public class JoinAMatNonChairContributor : IContributorTemplate + { + public ApplicationTypes ApplicationType => ApplicationTypes.JoinAMat; + public SchoolRoles SchoolRole => SchoolRoles.Other; + public string TemplateId { get; } + + public JoinAMatNonChairContributor(IOptions notifyTemplateSettings) + { + TemplateId = notifyTemplateSettings.Value.JamNonChairTemplateId; + } + } +} diff --git a/Dfe.Academies.External.Web/Pages/AddAContributor.cshtml.cs b/Dfe.Academies.External.Web/Pages/AddAContributor.cshtml.cs index 269e67755..2eebf0b78 100644 --- a/Dfe.Academies.External.Web/Pages/AddAContributor.cshtml.cs +++ b/Dfe.Academies.External.Web/Pages/AddAContributor.cshtml.cs @@ -1,6 +1,8 @@ using System.ComponentModel.DataAnnotations; +using System.Dynamic; using System.Security.Claims; using Dfe.Academies.External.Web.Attributes; +using Dfe.Academies.External.Web.Dtos; using Dfe.Academies.External.Web.Enums; using Dfe.Academies.External.Web.Models; using Dfe.Academies.External.Web.Pages.Base; @@ -119,10 +121,14 @@ public async Task OnPostAsync() string firstName = User.FindFirst(ClaimTypes.GivenName)?.Value ?? ""; string lastName = User.FindFirst(ClaimTypes.Surname)?.Value ?? ""; string invitingUserName = $"{firstName} {lastName}"; - + var schoolName = ApplicationSchoolName(draftConversionApplication); + var emailVariables = new EmailVariablesDto + { + ContributorName = Name!, InvitingUsername = invitingUserName, SchoolName = schoolName + }; + await _contributorEmailSenderService.SendInvitationToContributor(draftConversionApplication.ApplicationType, ContributorRole, - Name!, EmailAddress!, ApplicationSchoolName(draftConversionApplication), - invitingUserName); + EmailAddress!, emailVariables); // update temp store for next step draftConversionApplication.Contributors.Add(contributor); diff --git a/Dfe.Academies.External.Web/Program.cs b/Dfe.Academies.External.Web/Program.cs index 30eee2b4a..378558edb 100644 --- a/Dfe.Academies.External.Web/Program.cs +++ b/Dfe.Academies.External.Web/Program.cs @@ -1,7 +1,10 @@ using System.Globalization; +using Dfe.Academies.External.Web.AutoMapper; using Dfe.Academies.External.Web.Extensions; +using Dfe.Academies.External.Web.Factories; using Dfe.Academies.External.Web.Helpers; using Dfe.Academies.External.Web.Middleware; +using Dfe.Academies.External.Web.Models.EmailTemplates; using Dfe.Academies.External.Web.Routing; using Dfe.Academies.External.Web.Services; using GovUk.Frontend.AspNetCore; @@ -10,6 +13,9 @@ using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApplicationModels; +using Microsoft.Extensions.Options; +using Notify.Client; +using Notify.Interfaces; using Polly; using Polly.Extensions.Http; @@ -136,6 +142,14 @@ ); builder.Services.AddSingleton(); +builder.Services.AddAutoMapper(typeof(AutoMapperProfile)); +builder.Services.AddTransient(x => new NotificationClient(builder.Configuration["emailnotifications:key"])); +builder.Services.Configure(builder.Configuration.GetSection("govuk-notify-templates")); +builder.Services.AddSingleton(x => new FormAMatChairContributor(x.GetRequiredService>())); +builder.Services.AddSingleton(x => new FormAMatNonChairContributor(x.GetRequiredService>())); +builder.Services.AddSingleton(x => new JoinAMatChairContributor(x.GetRequiredService>())); +builder.Services.AddSingleton(x => new JoinAMatNonChairContributor(x.GetRequiredService>())); +builder.Services.AddSingleton(); builder.Services.AddHttpClient(client => { client.BaseAddress = new Uri(configuration["Sharepoint:ApiUrl"]); diff --git a/Dfe.Academies.External.Web/Services/ContributorEmailSenderService.cs b/Dfe.Academies.External.Web/Services/ContributorEmailSenderService.cs index a1251e0f9..0cfeee6a3 100644 --- a/Dfe.Academies.External.Web/Services/ContributorEmailSenderService.cs +++ b/Dfe.Academies.External.Web/Services/ContributorEmailSenderService.cs @@ -1,77 +1,35 @@ -using Dfe.Academies.External.Web.Enums; -using Dfe.Academies.External.Web.Middleware; -using Dfe.Academies.External.Web.Models.Notifications; +using AutoMapper; +using Dfe.Academies.External.Web.Dtos; +using Dfe.Academies.External.Web.Enums; +using Dfe.Academies.External.Web.Factories; +using Notify.Interfaces; namespace Dfe.Academies.External.Web.Services; -public sealed class ContributorEmailSenderService : BaseService, IContributorEmailSenderService +public sealed class ContributorEmailSenderService : IContributorEmailSenderService { - private readonly HttpClient _httpClient; - private readonly EmailNotificationService _emailNotificationService; - - private const string InvitationToContributeChairTemplateId = "858e5bea-9d49-442e-a89e-aaed2fb4ade6"; // template id from gov uk notify ! - private const string InvitationToContributeNonChairTemplateId = "03a0ae16-27fe-425d-8aa7-cac43d79f040"; // template id from gov uk notify ! - - public ContributorEmailSenderService(IHttpClientFactory httpClientFactory, ILogger logger, - IConfiguration configuration) - : base(httpClientFactory) + private readonly IAsyncNotificationClient _notificationClient; + private readonly IContributorNotifyTemplateFactory _contributorNotifyTemplateFactory; + private readonly IMapper _mapper; + public ContributorEmailSenderService( + IAsyncNotificationClient notificationClient, + IContributorNotifyTemplateFactory contributorNotifyTemplateFactory, + IMapper mapper) { - // TODO:- amend startupextensions to create new client - not sure, as no URI specified in https://docs.notifications.service.gov.uk/net.html ??? - _httpClient = httpClientFactory.CreateClient(AcademiesAPIHttpClientName); - _emailNotificationService = new EmailNotificationService(configuration, logger); + _contributorNotifyTemplateFactory = contributorNotifyTemplateFactory; + _mapper = mapper; + _notificationClient = notificationClient; } /// - public async Task SendInvitationToContributor(ApplicationTypes applicationType, SchoolRoles contributorRole, - string contributorName, string contributorEmailAddress, - string schoolName, - string invitingUserName) - { - // send email - diff templates for different roles - // TODO:- && different email dependent on application type? i.e. grab FirstOrDefault() on school for JoinAMat ? - if (contributorRole == SchoolRoles.ChairOfGovernors) - { - await InvitationToContributorChair(contributorName, contributorEmailAddress, schoolName, invitingUserName); - } - else - { - await InvitationToContributorNonChair(contributorName,contributorEmailAddress, schoolName, invitingUserName); - } - } - - private async Task InvitationToContributorChair(string contributorName, string contributorEmailAddress, string schoolName, - string invitingUserName) + public async Task SendInvitationToContributor( + ApplicationTypes applicationType, + SchoolRoles contributorRole, + string contributorEmailAddress, + EmailVariablesDto emailVariables) { - Dictionary personalisation = new Dictionary - { - { "invitee_name", contributorName }, - { "school", schoolName }, - { "inviting_contributor", invitingUserName }, - }; - - MessageDto emailMessage = new MessageDto(contributorEmailAddress, InvitationToContributeChairTemplateId) - { - Personalisation = personalisation - }; - - await _emailNotificationService.SendAsync(emailMessage); - } - - private async Task InvitationToContributorNonChair(string contributorName, string contributorEmailAddress, string schoolName, - string invitingUserName) - { - Dictionary personalisation = new Dictionary - { - { "invitee_name", contributorName }, - { "school", schoolName }, - { "inviting_contributor", invitingUserName }, - }; - - MessageDto emailMessage = new MessageDto(contributorEmailAddress, InvitationToContributeNonChairTemplateId) - { - Personalisation = personalisation - }; - - await _emailNotificationService.SendAsync(emailMessage); + var template = _contributorNotifyTemplateFactory.Get(applicationType, contributorRole); + var personalisation = _mapper.Map>(emailVariables); + await _notificationClient.SendEmailAsync(contributorEmailAddress, template.TemplateId, personalisation); } } diff --git a/Dfe.Academies.External.Web/Services/IContributorEmailSenderService.cs b/Dfe.Academies.External.Web/Services/IContributorEmailSenderService.cs index 7c781d49e..1ae0fbe08 100644 --- a/Dfe.Academies.External.Web/Services/IContributorEmailSenderService.cs +++ b/Dfe.Academies.External.Web/Services/IContributorEmailSenderService.cs @@ -1,11 +1,13 @@ -using Dfe.Academies.External.Web.Enums; +using Dfe.Academies.External.Web.Dtos; +using Dfe.Academies.External.Web.Enums; namespace Dfe.Academies.External.Web.Services; public interface IContributorEmailSenderService { - Task SendInvitationToContributor(ApplicationTypes applicationType, SchoolRoles contributorRole, - string contributorName, string contributorEmailAddress, - string schoolName, - string invitingUserName); + Task SendInvitationToContributor( + ApplicationTypes applicationType, + SchoolRoles contributorRole, + string contributorEmailAddress, + EmailVariablesDto emailVariables); } diff --git a/Dfe.Academies.External.Web/appsettings.json b/Dfe.Academies.External.Web/appsettings.json index b2d86a5bb..70b5ad715 100644 --- a/Dfe.Academies.External.Web/appsettings.json +++ b/Dfe.Academies.External.Web/appsettings.json @@ -30,5 +30,11 @@ "ClientId": "", "Secret": "", "Authority": "" - } + }, + "govuk-notify":{ + "JamChairTemplateId": "858e5bea-9d49-442e-a89e-aaed2fb4ade6", + "JamNonChairTemplateId": "03a0ae16-27fe-425d-8aa7-cac43d79f040", + "FamChairTemplateId": "1189f32b-79b9-43b5-9012-17a98ea39876", + "FamNonChairTemplateId": "490fd1a8-8b64-43ad-8929-344981c44121" + } }