|
3 | 3 | using Microsoft.Extensions.Logging; |
4 | 4 | using Pims.Api.Models.Ches; |
5 | 5 | using Pims.Api.Models.CodeTypes; |
| 6 | +using Pims.Api.Models.Config; |
6 | 7 | using Pims.Api.Models.Requests.Http; |
7 | 8 | using Pims.Api.Repositories.Ches; |
8 | 9 |
|
9 | 10 | namespace Pims.Api.Services |
10 | | - /// <summary> |
11 | | - /// Default implementation of IEmailService using CHES. |
12 | | - /// </summary> |
| 11 | +/// <summary> |
| 12 | +/// Default implementation of IEmailService using CHES. |
| 13 | +/// </summary> |
13 | 14 | { |
14 | 15 | public class ChesService : IEmailService |
15 | 16 | { |
16 | 17 | private readonly IEmailRepository _chesRepository; |
17 | 18 | private readonly ILogger<ChesService> _logger; |
| 19 | + private readonly ChesConfig _chesConfig; |
18 | 20 |
|
19 | | - public ChesService(IEmailRepository chesRepository, ILogger<ChesService> logger) |
| 21 | + public ChesService(IEmailRepository chesRepository, ILogger<ChesService> logger, ChesConfig chesConfig) |
20 | 22 | { |
21 | 23 | _chesRepository = chesRepository; |
22 | 24 | _logger = logger; |
| 25 | + _chesConfig = chesConfig; |
23 | 26 | } |
24 | 27 |
|
25 | 28 | public async Task<ExternalResponse<EmailResponse>> SendEmailAsync(EmailRequest request) |
26 | 29 | { |
27 | 30 | _logger.LogInformation("Email send requested. Recipient count: {recipientCount}.", request.To?.Count ?? 0); |
28 | 31 |
|
| 32 | + if (string.IsNullOrEmpty(request.From)) |
| 33 | + { |
| 34 | + request.From = _chesConfig.FromEmail; |
| 35 | + } |
| 36 | + |
29 | 37 | ExternalResponse<EmailResponse>? response = await _chesRepository.SendEmailAsync(request); |
30 | 38 |
|
31 | 39 | if (response == null || response.Payload == null) |
|
0 commit comments