Refactor GetOrCreateCommand to GetOrCreateEndpointCommand

Renamed `GetOrCreateCommand` to `GetOrCreateEndpointCommand`
to improve clarity and consistency. Removed the old
`GetOrCreateCommand` class and handler, and introduced the
new `GetOrCreateEndpointCommand` class with equivalent
functionality.

Updated `MappingProfile` to reflect the new command name
and adjusted `CreateRecActionCommand` to use the renamed
command. Added the appropriate namespace for the new class
to ensure proper organization.
This commit is contained in:
tekh 2025-12-01 15:56:25 +01:00
parent cacd5eddbe
commit a962299c95
3 changed files with 5 additions and 5 deletions

View File

@ -5,14 +5,14 @@ using ReC.Domain.Entities;
namespace ReC.Application.Endpoints.Commands; namespace ReC.Application.Endpoints.Commands;
public class GetOrCreateCommand : IRequest<Endpoint> public class GetOrCreateEndpointCommand : IRequest<Endpoint>
{ {
public string Uri { get; init; } = null!; public string Uri { get; init; } = null!;
} }
public class GetOrCreateCommandHandler(IRepository<Endpoint> repo) : IRequestHandler<GetOrCreateCommand, Endpoint> public class GetOrCreateEndpointCommandHandler(IRepository<Endpoint> repo) : IRequestHandler<GetOrCreateEndpointCommand, Endpoint>
{ {
public async Task<Endpoint> Handle(GetOrCreateCommand request, CancellationToken cancel) public async Task<Endpoint> Handle(GetOrCreateEndpointCommand 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);

View File

@ -7,6 +7,6 @@ public class MappingProfile : AutoMapper.Profile
{ {
public MappingProfile() public MappingProfile()
{ {
CreateMap<GetOrCreateCommand, Endpoint>(); CreateMap<GetOrCreateEndpointCommand, Endpoint>();
} }
} }

View File

@ -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 GetOrCreateCommand { Uri = endpointUri }, cancel); var endpoint = await sender.Send(new GetOrCreateEndpointCommand { Uri = endpointUri }, cancel);
request.EndpointId = endpoint.Id; request.EndpointId = endpoint.Id;
} }
else else