Skip to content
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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project>
<ItemGroup>
<PackageVersion Include="AutoMapper" Version="16.1.1" />
<PackageVersion Include="Bullseye" Version="6.0.0" />
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />
<PackageVersion Include="Glob" Version="1.1.9" />
Expand All @@ -9,6 +8,7 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="Riok.Mapperly" Version="4.3.1" />
<PackageVersion Include="Serilog" Version="4.3.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/Conduit/Conduit.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="AutoMapper" />
<PackageReference Include="Riok.Mapperly" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
Expand Down
29 changes: 29 additions & 0 deletions src/Conduit/Features/ConduitMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Conduit.Domain;
using Conduit.Features.Profiles;
using Conduit.Features.Users;
using Riok.Mapperly.Abstractions;

namespace Conduit.Features;

[Mapper]
public partial class ConduitMapper
{
[MapperIgnoreSource(nameof(Person.PersonId))]
[MapperIgnoreSource(nameof(Person.ArticleFavorites))]
[MapperIgnoreSource(nameof(Person.Following))]
[MapperIgnoreSource(nameof(Person.Followers))]
[MapperIgnoreSource(nameof(Person.Hash))]
[MapperIgnoreSource(nameof(Person.Salt))]
[MapperIgnoreTarget(nameof(User.Token))]
public partial User PersonToUser(Person person);

[MapperIgnoreSource(nameof(Person.PersonId))]
[MapperIgnoreSource(nameof(Person.Email))]
[MapperIgnoreSource(nameof(Person.ArticleFavorites))]
[MapperIgnoreSource(nameof(Person.Following))]
[MapperIgnoreSource(nameof(Person.Followers))]
[MapperIgnoreSource(nameof(Person.Hash))]
[MapperIgnoreSource(nameof(Person.Salt))]
[MapperIgnoreTarget(nameof(Profile.IsFollowed))]
public partial Profile PersonToProfile(Person person);
}
8 changes: 0 additions & 8 deletions src/Conduit/Features/Profiles/MappingProfile.cs

This file was deleted.

10 changes: 2 additions & 8 deletions src/Conduit/Features/Profiles/ProfileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using Conduit.Infrastructure;
using Conduit.Infrastructure.Errors;
using Microsoft.EntityFrameworkCore;
Expand All @@ -12,7 +11,7 @@ namespace Conduit.Features.Profiles;
public class ProfileReader(
ConduitContext context,
ICurrentUserAccessor currentUserAccessor,
IMapper mapper
ConduitMapper mapper
) : IProfileReader
{
public async Task<ProfileEnvelope> ReadProfile(
Expand All @@ -29,12 +28,7 @@ CancellationToken cancellationToken
{
throw new RestException(HttpStatusCode.NotFound, new { User = Constants.NOT_FOUND });
}

if (person == null)
{
throw new RestException(HttpStatusCode.NotFound, new { User = Constants.NOT_FOUND });
}
var profile = mapper.Map<Domain.Person, Profile>(person);
var profile = mapper.PersonToProfile(person);

if (currentUserName != null)
{
Expand Down
5 changes: 2 additions & 3 deletions src/Conduit/Features/Users/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using Conduit.Domain;
using Conduit.Infrastructure;
using Conduit.Infrastructure.Errors;
Expand Down Expand Up @@ -34,7 +33,7 @@ public class Handler(
ConduitContext context,
IPasswordHasher passwordHasher,
IJwtTokenGenerator jwtTokenGenerator,
IMapper mapper
ConduitMapper mapper
) : IRequestHandler<Command, UserEnvelope>
{
public async Task<UserEnvelope> Handle(Command message, CancellationToken cancellationToken)
Expand Down Expand Up @@ -78,7 +77,7 @@ await context
await context.Persons.AddAsync(person, cancellationToken);
await context.SaveChangesAsync(cancellationToken);

var user = mapper.Map<Person, User>(person);
var user = mapper.PersonToUser(person);
user.Token = jwtTokenGenerator.CreateToken(
person.Username ?? throw new InvalidOperationException()
);
Expand Down
5 changes: 2 additions & 3 deletions src/Conduit/Features/Users/Details.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using Conduit.Infrastructure;
using Conduit.Infrastructure.Errors;
using Conduit.Infrastructure.Security;
Expand All @@ -24,7 +23,7 @@ public class QueryValidator : AbstractValidator<Query>
public class QueryHandler(
ConduitContext context,
IJwtTokenGenerator jwtTokenGenerator,
IMapper mapper
ConduitMapper mapper
) : IRequestHandler<Query, UserEnvelope>
{
public async Task<UserEnvelope> Handle(Query message, CancellationToken cancellationToken)
Expand All @@ -41,7 +40,7 @@ public async Task<UserEnvelope> Handle(Query message, CancellationToken cancella
);
}

var user = mapper.Map<Domain.Person, User>(person);
var user = mapper.PersonToUser(person);
user.Token = jwtTokenGenerator.CreateToken(
person.Username ?? throw new InvalidOperationException()
);
Expand Down
5 changes: 2 additions & 3 deletions src/Conduit/Features/Users/Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using Conduit.Infrastructure;
using Conduit.Infrastructure.Errors;
using Conduit.Infrastructure.Security;
Expand Down Expand Up @@ -39,7 +38,7 @@ public class Handler(
ConduitContext context,
IPasswordHasher passwordHasher,
ICurrentUserAccessor currentUserAccessor,
IMapper mapper
ConduitMapper mapper
) : IRequestHandler<Command, UserEnvelope>
{
public async Task<UserEnvelope> Handle(Command message, CancellationToken cancellationToken)
Expand Down Expand Up @@ -70,7 +69,7 @@ public async Task<UserEnvelope> Handle(Command message, CancellationToken cancel

await context.SaveChangesAsync(cancellationToken);

return new UserEnvelope(mapper.Map<Domain.Person, User>(person));
return new UserEnvelope(mapper.PersonToUser(person));
}
}
}
5 changes: 2 additions & 3 deletions src/Conduit/Features/Users/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using Conduit.Infrastructure;
using Conduit.Infrastructure.Errors;
using Conduit.Infrastructure.Security;
Expand Down Expand Up @@ -38,7 +37,7 @@ public class Handler(
ConduitContext context,
IPasswordHasher passwordHasher,
IJwtTokenGenerator jwtTokenGenerator,
IMapper mapper
ConduitMapper mapper
) : IRequestHandler<Command, UserEnvelope>
{
public async Task<UserEnvelope> Handle(Command message, CancellationToken cancellationToken)
Expand Down Expand Up @@ -67,7 +66,7 @@ public async Task<UserEnvelope> Handle(Command message, CancellationToken cancel
);
}

var user = mapper.Map<Domain.Person, User>(person);
var user = mapper.PersonToUser(person);
user.Token = jwtTokenGenerator.CreateToken(
person.Username ?? throw new InvalidOperationException()
);
Expand Down
8 changes: 0 additions & 8 deletions src/Conduit/Features/Users/MappingProfile.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Conduit/ServicesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void AddConduit(this IServiceCollection services)

services.AddValidatorsFromAssemblyContaining<Details.QueryValidator>();

services.AddAutoMapper(cfg => cfg.AddMaps(typeof(Program)));
services.AddSingleton<Features.ConduitMapper>();

services.AddScoped<IPasswordHasher, PasswordHasher>();
services.AddScoped<IJwtTokenGenerator, JwtTokenGenerator>();
Expand Down
15 changes: 6 additions & 9 deletions src/Conduit/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
"version": 2,
"dependencies": {
"net10.0": {
"AutoMapper": {
"type": "Direct",
"requested": "[16.1.1, )",
"resolved": "16.1.1",
"contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==",
"dependencies": {
"Microsoft.IdentityModel.JsonWebTokens": "8.14.0"
}
},
"FluentValidation": {
"type": "Direct",
"requested": "[12.0.0, )",
Expand Down Expand Up @@ -75,6 +66,12 @@
"Microsoft.EntityFrameworkCore.Relational": "10.0.2"
}
},
"Riok.Mapperly": {
"type": "Direct",
"requested": "[4.3.1, )",
"resolved": "4.3.1",
"contentHash": "oSE+OVLHyiojrws0QVbQaAT2YKsYbyHqJXPdV7EhGseR/dYgeWS2x1T5qY5I4E+RJkJqMSG+FyZOq4SljWgJWQ=="
},
"Serilog": {
"type": "Direct",
"requested": "[4.3.0, )",
Expand Down
19 changes: 7 additions & 12 deletions tests/Conduit.IntegrationTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -459,31 +459,20 @@
"conduit": {
"type": "Project",
"dependencies": {
"AutoMapper": "[16.1.1, )",
"FluentValidation": "[12.0.0, )",
"FluentValidation.DependencyInjectionExtensions": "[12.0.0, )",
"MediatR": "[12.5.0, )",
"Microsoft.AspNetCore.Authentication.JwtBearer": "[10.0.2, )",
"Microsoft.EntityFrameworkCore.InMemory": "[10.0.2, )",
"Microsoft.EntityFrameworkCore.SqlServer": "[10.0.2, )",
"Microsoft.EntityFrameworkCore.Sqlite": "[10.0.2, )",
"Riok.Mapperly": "[4.3.1, )",
"Serilog": "[4.3.0, )",
"Serilog.Extensions.Logging": "[8.0.0, )",
"Serilog.Sinks.Console": "[6.0.0, )",
"Swashbuckle.AspNetCore": "[9.0.6, )"
}
},
"AutoMapper": {
"type": "CentralTransitive",
"requested": "[16.1.1, )",
"resolved": "16.1.1",
"contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "10.0.0",
"Microsoft.Extensions.Options": "10.0.0",
"Microsoft.IdentityModel.JsonWebTokens": "8.14.0"
}
},
"FluentValidation": {
"type": "CentralTransitive",
"requested": "[12.0.0, )",
Expand Down Expand Up @@ -558,6 +547,12 @@
"Microsoft.Extensions.Logging": "10.0.2"
}
},
"Riok.Mapperly": {
"type": "CentralTransitive",
"requested": "[4.3.1, )",
"resolved": "4.3.1",
"contentHash": "oSE+OVLHyiojrws0QVbQaAT2YKsYbyHqJXPdV7EhGseR/dYgeWS2x1T5qY5I4E+RJkJqMSG+FyZOq4SljWgJWQ=="
},
"Serilog": {
"type": "CentralTransitive",
"requested": "[4.3.0, )",
Expand Down