Refactor GetOrCreateEndpointCommand to ObtainEndpointCommand
Replaced `GetOrCreateEndpointCommand` with `ObtainEndpointCommand` to improve clarity and align with naming conventions. Removed `GetOrCreateEndpointCommand` and its handler, and introduced `ObtainEndpointCommand` with equivalent functionality. Updated `MappingProfile.cs` to map `ObtainEndpointCommand` to `Endpoint`. Refactored `CreateRecActionCommand.cs` to use the new `ObtainEndpointCommand` for retrieving or creating `Endpoint` entities. These changes ensure consistent naming and maintain the same behavior while improving code readability.
This commit is contained in:
parent
a962299c95
commit
918372371e
@ -5,14 +5,14 @@ using ReC.Domain.Entities;
|
|||||||
|
|
||||||
namespace ReC.Application.Endpoints.Commands;
|
namespace ReC.Application.Endpoints.Commands;
|
||||||
|
|
||||||
public class GetOrCreateEndpointCommand : IRequest<Endpoint>
|
public class ObtainEndpointCommand : IRequest<Endpoint>
|
||||||
{
|
{
|
||||||
public string Uri { get; init; } = null!;
|
public string Uri { get; init; } = null!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetOrCreateEndpointCommandHandler(IRepository<Endpoint> repo) : IRequestHandler<GetOrCreateEndpointCommand, Endpoint>
|
public class ObtainEndpointCommandHandler(IRepository<Endpoint> repo) : IRequestHandler<ObtainEndpointCommand, Endpoint>
|
||||||
{
|
{
|
||||||
public async Task<Endpoint> Handle(GetOrCreateEndpointCommand request, CancellationToken cancel)
|
public async Task<Endpoint> Handle(ObtainEndpointCommand request, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var endpoint = await repo.Where(e => e.Uri == request.Uri).FirstOrDefaultAsync(cancel);
|
var endpoint = await repo.Where(e => e.Uri == request.Uri).FirstOrDefaultAsync(cancel);
|
||||||
|
|
||||||
@ -7,6 +7,6 @@ public class MappingProfile : AutoMapper.Profile
|
|||||||
{
|
{
|
||||||
public MappingProfile()
|
public MappingProfile()
|
||||||
{
|
{
|
||||||
CreateMap<GetOrCreateEndpointCommand, Endpoint>();
|
CreateMap<ObtainEndpointCommand, Endpoint>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ public class CreateRecActionCommandHandler(ISender sender) : IRequestHandler<Cre
|
|||||||
if(request.EndpointId is null)
|
if(request.EndpointId is null)
|
||||||
if(request.EndpointUri is string endpointUri)
|
if(request.EndpointUri is string endpointUri)
|
||||||
{
|
{
|
||||||
var endpoint = await sender.Send(new GetOrCreateEndpointCommand { Uri = endpointUri }, cancel);
|
var endpoint = await sender.Send(new ObtainEndpointCommand { Uri = endpointUri }, cancel);
|
||||||
request.EndpointId = endpoint.Id;
|
request.EndpointId = endpoint.Id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user