Format: ./src/Core/Service

This commit is contained in:
Aaron Po
2026-02-15 22:34:45 -05:00
parent 584c47e162
commit f4a76a365b
8 changed files with 61 additions and 48 deletions

View File

@@ -23,7 +23,6 @@ public class RegisterServiceTest
_tokenServiceMock = new Mock<ITokenService>(); _tokenServiceMock = new Mock<ITokenService>();
_emailServiceMock = new Mock<IEmailService>(); _emailServiceMock = new Mock<IEmailService>();
_registerService = new RegisterService( _registerService = new RegisterService(
_authRepoMock.Object, _authRepoMock.Object,
_passwordInfraMock.Object, _passwordInfraMock.Object,
@@ -97,7 +96,6 @@ public class RegisterServiceTest
.Setup(x => x.GenerateRefreshToken(It.IsAny<UserAccount>())) .Setup(x => x.GenerateRefreshToken(It.IsAny<UserAccount>()))
.Returns("refresh-token"); .Returns("refresh-token");
// Act // Act
var result = await _registerService.RegisterAsync( var result = await _registerService.RegisterAsync(
userAccount, userAccount,
@@ -134,8 +132,14 @@ public class RegisterServiceTest
), ),
Times.Once Times.Once
); );
_emailServiceMock.Verify(x => x.SendRegistrationEmailAsync(It.IsAny<UserAccount>(), It.IsAny<string>()), _emailServiceMock.Verify(
Times.Once); x =>
x.SendRegistrationEmailAsync(
It.IsAny<UserAccount>(),
It.IsAny<string>()
),
Times.Once
);
} }
[Fact] [Fact]

View File

@@ -54,7 +54,10 @@ public class RegisterService(
var refreshToken = tokenService.GenerateRefreshToken(createdUser); var refreshToken = tokenService.GenerateRefreshToken(createdUser);
// send confirmation email // send confirmation email
await emailService.SendRegistrationEmailAsync(createdUser, "some-confirmation-token"); await emailService.SendRegistrationEmailAsync(
createdUser,
"some-confirmation-token"
);
return new AuthServiceReturn(createdUser, refreshToken, accessToken); return new AuthServiceReturn(createdUser, refreshToken, accessToken);
} }

View File

@@ -8,15 +8,11 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Domain.Entities\Domain.Entities.csproj" /> <ProjectReference Include="..\..\Domain.Entities\Domain.Entities.csproj" />
<ProjectReference Include="..\..\Domain.Exceptions\Domain.Exceptions.csproj" /> <ProjectReference Include="..\..\Domain.Exceptions\Domain.Exceptions.csproj" />
<ProjectReference <ProjectReference Include="..\..\Infrastructure\Infrastructure.Email\Infrastructure.Email.csproj" />
Include="..\..\Infrastructure\Infrastructure.Email\Infrastructure.Email.csproj" /> <ProjectReference Include="..\..\Infrastructure\Infrastructure.Email.Templates\Infrastructure.Email.Templates.csproj" />
<ProjectReference
Include="..\..\Infrastructure\Infrastructure.Email.Templates\Infrastructure.Email.Templates.csproj" />
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Jwt\Infrastructure.Jwt.csproj" /> <ProjectReference Include="..\..\Infrastructure\Infrastructure.Jwt\Infrastructure.Jwt.csproj" />
<ProjectReference <ProjectReference Include="..\..\Infrastructure\Infrastructure.Repository\Infrastructure.Repository.csproj" />
Include="..\..\Infrastructure\Infrastructure.Repository\Infrastructure.Repository.csproj" /> <ProjectReference Include="..\..\Infrastructure\Infrastructure.PasswordHashing\Infrastructure.PasswordHashing.csproj" />
<ProjectReference
Include="..\..\Infrastructure\Infrastructure.PasswordHashing\Infrastructure.PasswordHashing.csproj" />
<ProjectReference Include="..\Service.Emails\Service.Emails.csproj" /> <ProjectReference Include="..\Service.Emails\Service.Emails.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -6,21 +6,30 @@ namespace Service.Emails;
public interface IEmailService public interface IEmailService
{ {
public Task SendRegistrationEmailAsync(UserAccount createdUser, string confirmationToken); public Task SendRegistrationEmailAsync(
UserAccount createdUser,
string confirmationToken
);
} }
public class EmailService( public class EmailService(
IEmailProvider emailProvider, IEmailProvider emailProvider,
IEmailTemplateProvider emailTemplateProvider) : IEmailService IEmailTemplateProvider emailTemplateProvider
) : IEmailService
{ {
public async Task SendRegistrationEmailAsync(UserAccount createdUser, string confirmationToken) public async Task SendRegistrationEmailAsync(
UserAccount createdUser,
string confirmationToken
)
{ {
var confirmationLink = $"https://thebiergarten.app/confirm?token={confirmationToken}"; var confirmationLink =
$"https://thebiergarten.app/confirm?token={confirmationToken}";
var emailHtml = await emailTemplateProvider.RenderUserRegisteredEmailAsync( var emailHtml =
createdUser.FirstName, await emailTemplateProvider.RenderUserRegisteredEmailAsync(
confirmationLink createdUser.FirstName,
); confirmationLink
);
await emailProvider.SendAsync( await emailProvider.SendAsync(
createdUser.Email, createdUser.Email,

View File

@@ -1,15 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup> <ItemGroup>
<TargetFramework>net10.0</TargetFramework> <ProjectReference Include="..\..\Domain.Entities\Domain.Entities.csproj" />
<ImplicitUsings>enable</ImplicitUsings> <ProjectReference Include="..\..\Infrastructure\Infrastructure.Email.Templates\Infrastructure.Email.Templates.csproj" />
<Nullable>enable</Nullable> <ProjectReference Include="..\..\Infrastructure\Infrastructure.Email\Infrastructure.Email.csproj" />
</PropertyGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Domain.Entities\Domain.Entities.csproj" />
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Email.Templates\Infrastructure.Email.Templates.csproj" />
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Email\Infrastructure.Email.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -1,15 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup> <ItemGroup>
<TargetFramework>net10.0</TargetFramework> <ProjectReference Include="..\..\Domain.Exceptions\Domain.Exceptions.csproj" />
<ImplicitUsings>enable</ImplicitUsings> <ProjectReference Include="..\..\Infrastructure\Infrastructure.Repository\Infrastructure.Repository.csproj" />
<Nullable>enable</Nullable> </ItemGroup>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Domain.Exceptions\Domain.Exceptions.csproj" />
<ProjectReference
Include="..\..\Infrastructure\Infrastructure.Repository\Infrastructure.Repository.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -4,7 +4,10 @@ namespace Service.UserManagement.User;
public interface IUserService public interface IUserService
{ {
Task<IEnumerable<UserAccount>> GetAllAsync(int? limit = null, int? offset = null); Task<IEnumerable<UserAccount>> GetAllAsync(
int? limit = null,
int? offset = null
);
Task<UserAccount> GetByIdAsync(Guid id); Task<UserAccount> GetByIdAsync(Guid id);
Task UpdateAsync(UserAccount userAccount); Task UpdateAsync(UserAccount userAccount);

View File

@@ -6,7 +6,10 @@ namespace Service.UserManagement.User;
public class UserService(IUserAccountRepository repository) : IUserService public class UserService(IUserAccountRepository repository) : IUserService
{ {
public async Task<IEnumerable<UserAccount>> GetAllAsync(int? limit = null, int? offset = null) public async Task<IEnumerable<UserAccount>> GetAllAsync(
int? limit = null,
int? offset = null
)
{ {
return await repository.GetAllAsync(limit, offset); return await repository.GetAllAsync(limit, offset);
} }