Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace email-service project with NuGet package #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PackageVersion Include="Dapper" Version="2.1.35" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="GaEpd.AppLibrary" Version="5.3.1" />
<PackageVersion Include="GaEpd.EmailService" Version="1.0.0" />
<PackageVersion Include="GaEpd.FileService" Version="3.1.1" />
<PackageVersion Include="HtmlSanitizer" Version="8.1.870" />
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/AppServices/AppServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="AutoMapper" />
<PackageReference Include="ClosedXML" />
<PackageReference Include="FluentValidation.AspNetCore" />
<PackageReference Include="GaEpd.EmailService"/>
<PackageReference Include="GaEpd.FileService" />
<PackageReference Include="JetBrains.Annotations" />
<PackageReference Include="Microsoft.Identity.Web" />
Expand All @@ -22,7 +23,6 @@

<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\EmailService\EmailService.csproj" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/AppServices/Notifications/NotificationService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GaEpd.EmailService;
using GaEpd.EmailService.Repository;
using GaEpd.EmailService.EmailLogRepository;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using MyApp.AppServices.ErrorLogging;
Expand All @@ -9,7 +9,7 @@ namespace MyApp.AppServices.Notifications;

public class NotificationService(
IEmailService emailService,
IEmailLogRepository repository,
IEmailLogRepository emailLogRepository,
IHostEnvironment environment,
IConfiguration configuration,
IErrorLogger errorLogger) : INotificationService
Expand Down Expand Up @@ -39,15 +39,15 @@ public async Task<NotificationResult> SendNotificationAsync(Template template, s
Message message;
try
{
message = Message.Create(subject, recipientEmail, settings.DefaultSender, textBody, htmlBody);
message = Message.Create(subject, recipientEmail, textBody, htmlBody);
}
catch (Exception e)
{
await errorLogger.LogErrorAsync(e, subject).ConfigureAwait(false);
return NotificationResult.FailureResult($"{FailurePrefix} An error occurred when generating the email.");
}

if (settings.SaveEmail) await repository.InsertAsync(EmailLog.Create(message), token).ConfigureAwait(false);
await emailLogRepository.InsertAsync(message, token).ConfigureAwait(false);

if (settings is { EnableEmail: false, EnableEmailAuditing: false })
{
Expand All @@ -56,7 +56,7 @@ public async Task<NotificationResult> SendNotificationAsync(Template template, s

try
{
await emailService.SendEmailAsync(message, settings, token).ConfigureAwait(false);
_ = emailService.SendEmailAsync(message, token);
}
catch (Exception e)
{
Expand Down
4 changes: 3 additions & 1 deletion src/AppServices/Permissions/Policies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ public static class Policies
// These policies are for use in PageModel class attributes, e.g.:
// [Authorize(Policy = nameof(Policies.ActiveUser))]

public static void AddAuthorizationPolicies(this IServiceCollection services)
public static IServiceCollection AddAuthorizationPolicies(this IServiceCollection services)
{
services.AddAuthorizationBuilder()
.AddPolicy(nameof(ActiveUser), ActiveUser)
.AddPolicy(nameof(Manager), Manager)
.AddPolicy(nameof(SiteMaintainer), SiteMaintainer)
.AddPolicy(nameof(StaffUser), StaffUser)
.AddPolicy(nameof(UserAdministrator), UserAdministrator);

return services;
}

// Default policy builder
Expand Down
4 changes: 2 additions & 2 deletions src/AppServices/RegisterServices/AutoMapperProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace MyApp.AppServices.RegisterServices;

public static class AutoMapperProfiles
{
public static void AddAutoMapperProfiles(this IServiceCollection services)
public static IServiceCollection AddAutoMapperProfiles(this IServiceCollection services)
{
// Add AutoMapper profiles
services.AddAutoMapper(expression => expression.AddProfile<AutoMapperProfile>());
return services.AddAutoMapper(expression => expression.AddProfile<AutoMapperProfile>());
}
}
12 changes: 6 additions & 6 deletions src/AppServices/RegisterServices/RegisterAppServices.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GaEpd.EmailService;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using MyApp.AppServices.DataExport;
using MyApp.AppServices.EntryActions;
using MyApp.AppServices.EntryTypes;
Expand All @@ -14,7 +13,7 @@ namespace MyApp.AppServices.RegisterServices;

public static class RegisterAppServices
{
public static void AddAppServices(this IServiceCollection services)
public static IServiceCollection AddAppServices(this IServiceCollection services)
{
// Work Entries
services.AddScoped<IWorkEntryManager, WorkEntryManager>();
Expand All @@ -26,9 +25,8 @@ public static void AddAppServices(this IServiceCollection services)
// Entry Types
services.AddScoped<IEntryTypeManager, EntryTypeManager>();
services.AddScoped<IEntryTypeService, EntryTypeService>();

// Email
services.AddTransient<IEmailService, EmailService>();

// Notifications
services.AddScoped<INotificationService, NotificationService>();

// Offices
Expand All @@ -37,5 +35,7 @@ public static void AddAppServices(this IServiceCollection services)

// Data Export
services.AddScoped<ISearchResultsExportService, SearchResultsExportService>();

return services;
}
}
2 changes: 1 addition & 1 deletion src/AppServices/RegisterServices/Validators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace MyApp.AppServices.RegisterServices;
public static class Validators
{
// Add all validators
public static void AddValidators(this IServiceCollection services) =>
public static IServiceCollection AddValidators(this IServiceCollection services) =>
services.AddValidatorsFromAssemblyContaining(typeof(Validators));
}
2 changes: 1 addition & 1 deletion src/EfRepository/DbContext/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GaEpd.EmailService.Repository;
using GaEpd.EmailService.EmailLogRepository;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MyApp.Domain.Entities.EntryActions;
Expand Down
3 changes: 2 additions & 1 deletion src/EfRepository/EfRepository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GaEpd.EmailService"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -21,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AppServices\AppServices.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj"/>
<ProjectReference Include="..\TestData\TestData.csproj" />
</ItemGroup>

Expand Down
25 changes: 18 additions & 7 deletions src/EfRepository/Repositories/EmailLogRepository.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
using GaEpd.EmailService.Repository;
using GaEpd.EmailService;
using GaEpd.EmailService.EmailLogRepository;
using Microsoft.Extensions.Configuration;
using MyApp.EfRepository.DbContext;

namespace MyApp.EfRepository.Repositories;

public sealed class EmailLogRepository(AppDbContext dbContext) : IEmailLogRepository
public sealed class EmailLogRepository(AppDbContext context, IConfiguration configuration) : IEmailLogRepository
{
public async Task InsertAsync(EmailLog emailLog, CancellationToken token = default)
public async Task InsertAsync(Message message, CancellationToken token = default)
{
await dbContext.EmailLogs.AddAsync(emailLog, token).ConfigureAwait(false);
await dbContext.SaveChangesAsync(token).ConfigureAwait(false);
var settings = new EmailServiceSettings();
configuration.GetSection(nameof(EmailServiceSettings)).Bind(settings);
if (!settings.EnableEmailLog) return;

var emailLog = EmailLog.Create(message);
await context.EmailLogs.AddAsync(emailLog, token).ConfigureAwait(false);
await context.SaveChangesAsync(token).ConfigureAwait(false);
}

public void Dispose() => dbContext.Dispose();
public ValueTask DisposeAsync() => dbContext.DisposeAsync();
#region IDisposable, IAsyncDisposable

public void Dispose() => context.Dispose();
public ValueTask DisposeAsync() => context.DisposeAsync();

#endregion
}
65 changes: 0 additions & 65 deletions src/EmailService/EmailService.cs

This file was deleted.

16 changes: 0 additions & 16 deletions src/EmailService/EmailService.csproj

This file was deleted.

2 changes: 0 additions & 2 deletions src/EmailService/EmailService.csproj.DotSettings

This file was deleted.

13 changes: 0 additions & 13 deletions src/EmailService/EmailServiceSettings.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/EmailService/IEmailService.cs

This file was deleted.

44 changes: 0 additions & 44 deletions src/EmailService/Message.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/EmailService/Properties/AssemblyInfo.cs

This file was deleted.

42 changes: 0 additions & 42 deletions src/EmailService/Repository/EmailLog.cs

This file was deleted.

Loading
Loading