From a02cac8778770f4b68e5049b201d8ee28d6e2f33 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 15 Dec 2025 13:08:21 +0100 Subject: [PATCH] Refactor handler to use AutoMapper and entity repository Updated ObtainEndpointCommandHandler to depend on IRepository and IMapper. Now maps Endpoint entities to EndpointDto using AutoMapper before returning, ensuring proper separation of concerns and DTO exposure. --- .../Endpoints/Commands/ObtainEndpointCommand.cs.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ReC.Application/Endpoints/Commands/ObtainEndpointCommand.cs.cs b/src/ReC.Application/Endpoints/Commands/ObtainEndpointCommand.cs.cs index 3460f30..23d32e5 100644 --- a/src/ReC.Application/Endpoints/Commands/ObtainEndpointCommand.cs.cs +++ b/src/ReC.Application/Endpoints/Commands/ObtainEndpointCommand.cs.cs @@ -1,7 +1,9 @@ -using DigitalData.Core.Abstraction.Application.Repository; +using AutoMapper; +using DigitalData.Core.Abstraction.Application.Repository; using MediatR; using Microsoft.EntityFrameworkCore; using ReC.Application.Common.Dto; +using ReC.Domain.Entities; namespace ReC.Application.Endpoints.Commands; @@ -10,16 +12,16 @@ public class ObtainEndpointCommand : IRequest public string Uri { get; init; } = null!; } -public class ObtainEndpointCommandHandler(IRepository repo) : IRequestHandler +public class ObtainEndpointCommandHandler(IRepository repo, IMapper mapper) : IRequestHandler { public async Task Handle(ObtainEndpointCommand request, CancellationToken cancel) { var endpoint = await repo.Where(e => e.Uri == request.Uri).FirstOrDefaultAsync(cancel); if (endpoint is not null) - return endpoint; + return mapper.Map(endpoint); endpoint = await repo.CreateAsync(request, cancel); - return endpoint; + return mapper.Map(endpoint); } } \ No newline at end of file