-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Az sender for sending task owner report
- Loading branch information
1 parent
75c7441
commit 16a7ea2
Showing
17 changed files
with
451 additions
and
6 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/Fusion.Resources.Functions.Common/ApiClients/ApiModels/Mails.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace Fusion.Resources.Functions.Common.ApiClients.ApiModels; | ||
|
||
public class SendEmailRequest | ||
{ | ||
public required string[] Recipients { get; set; } | ||
public required string Subject { get; set; } | ||
public required string Body { get; set; } | ||
public string? FromDisplayName { get; set; } | ||
} | ||
|
||
public class SendEmailWithTemplateRequest | ||
{ | ||
public required string Subject { get; set; } | ||
|
||
public required string[] Recipients { get; set; } | ||
|
||
/// <summary> | ||
/// Specify the content that is to be displayed in the mail | ||
/// </summary> | ||
public required MailBody MailBody { get; set; } | ||
} | ||
|
||
public class MailBody | ||
{ | ||
/// <summary> | ||
/// The main content in the mail placed between the header and footer | ||
/// </summary> | ||
public required string HtmlContent { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. If not specified, the footer template will be used | ||
/// </summary> | ||
public string? HtmlFooter { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. A text that is displayed inside the header. Will default to 'Mail from Fusion' | ||
/// </summary> | ||
public string? HeaderTitle { get; set; } | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Fusion.Resources.Functions.Common/ApiClients/IMailApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Fusion.Resources.Functions.Common.ApiClients.ApiModels; | ||
|
||
namespace Fusion.Resources.Functions.Common.ApiClients; | ||
|
||
public interface IMailApiClient | ||
{ | ||
public Task SendEmailAsync(SendEmailRequest request, CancellationToken cancellationToken = default); | ||
|
||
public Task SendEmailWithTemplate(SendEmailWithTemplateRequest request, string? templateName = "default", CancellationToken cancellationToken = default); | ||
} |
6 changes: 5 additions & 1 deletion
6
src/Fusion.Resources.Functions.Common/ApiClients/IPeopleApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
namespace Fusion.Resources.Functions.Common.ApiClients; | ||
using Fusion.Integration.Profile; | ||
using Fusion.Integration.Profile.ApiClient; | ||
|
||
namespace Fusion.Resources.Functions.Common.ApiClients; | ||
|
||
public interface IPeopleApiClient | ||
{ | ||
Task<string> GetPersonFullDepartmentAsync(Guid? personAzureUniqueId); | ||
Task<ICollection<ApiEnsuredProfileV2>> ResolvePersonsAsync(IEnumerable<PersonIdentifier> personAzureUniqueIds, CancellationToken cancellationToken = default); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/Fusion.Resources.Functions.Common/ApiClients/MailApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Text; | ||
using Fusion.Resources.Functions.Common.ApiClients.ApiModels; | ||
using Fusion.Resources.Functions.Common.Extensions; | ||
using Fusion.Resources.Functions.Common.Integration.Errors; | ||
using Fusion.Resources.Functions.Common.Integration.Http; | ||
using Newtonsoft.Json; | ||
|
||
namespace Fusion.Resources.Functions.Common.ApiClients; | ||
|
||
public class MailApiClient : IMailApiClient | ||
{ | ||
private readonly HttpClient mailClient; | ||
|
||
public MailApiClient(IHttpClientFactory httpClientFactory) | ||
{ | ||
mailClient = httpClientFactory.CreateClient(HttpClientNames.Application.Mail); | ||
mailClient.Timeout = TimeSpan.FromMinutes(2); | ||
} | ||
|
||
public async Task SendEmailAsync(SendEmailRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
var json = JsonConvert.SerializeObject(request); | ||
var content = new StringContent(json, Encoding.UTF8, "application/json"); | ||
|
||
using var response = await mailClient.PostAsync("/mails", content, cancellationToken); | ||
|
||
await ThrowIfNotSuccess(response); | ||
} | ||
|
||
public async Task SendEmailWithTemplate(SendEmailWithTemplateRequest request, string? templateName = "default", CancellationToken cancellationToken = default) | ||
{ | ||
var json = JsonConvert.SerializeObject(request); | ||
var content = new StringContent(json, Encoding.UTF8, "application/json"); | ||
|
||
using var response = await mailClient.PostAsync($"templates/{templateName}/mails", content, cancellationToken); | ||
|
||
await ThrowIfNotSuccess(response); | ||
} | ||
|
||
private async Task ThrowIfNotSuccess(HttpResponseMessage response) | ||
{ | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
var body = await response.Content.ReadAsStringAsync(); | ||
throw new ApiError(response.RequestMessage!.RequestUri!.ToString(), response.StatusCode, body, "Response from API call indicates error"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Fusion.Resources.Functions.Common/Integration/Http/Handlers/MailHttpHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Fusion.Resources.Functions.Common.Integration.Authentication; | ||
using Fusion.Resources.Functions.Common.Integration.ServiceDiscovery; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Fusion.Resources.Functions.Common.Integration.Http.Handlers; | ||
|
||
public class MailHttpHandler : FunctionHttpMessageHandler | ||
{ | ||
private readonly IOptions<HttpClientsOptions> options; | ||
|
||
public MailHttpHandler(ILoggerFactory loggerFactory, ITokenProvider tokenProvider, IServiceDiscovery serviceDiscovery, IOptions<HttpClientsOptions> options) | ||
: base(loggerFactory.CreateLogger<MailHttpHandler>(), tokenProvider, serviceDiscovery) | ||
{ | ||
this.options = options; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
await SetEndpointUriForRequestAsync(request, ServiceEndpoint.Mail); | ||
await AddAuthHeaderForRequestAsync(request, options.Value.Fusion); | ||
|
||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.