Refactor GetOrCreateCommand and add AutoMapper profile
Refactored the `GetOrCreateCommand` to simplify the creation of `Endpoint` entities by delegating the creation logic to `repo.CreateAsync`. Added a new `MappingProfile` class using AutoMapper to define mappings between command objects (`CreateEndpointCommand` and `GetOrCreateCommand`) and the `Endpoint` entity, improving code maintainability and reducing boilerplate. Included necessary `using` directives in `MappingProfile.cs` to support the new mapping functionality.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ReC.Domain.Entities;
|
||||
|
||||
namespace ReC.Application.Endpoints.Commands;
|
||||
|
||||
@@ -19,11 +18,7 @@ public class GetOrCreateCommandHandler(IRepository<Endpoint> repo) : IRequestHan
|
||||
if (endpoint is not null)
|
||||
return endpoint;
|
||||
|
||||
endpoint = new Endpoint
|
||||
{
|
||||
Uri = request.Uri
|
||||
};
|
||||
await repo.CreateAsync(endpoint, cancel);
|
||||
endpoint = await repo.CreateAsync(request, cancel);
|
||||
return endpoint;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user