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; public class ObtainEndpointCommand : IRequest { public string Uri { get; init; } = null!; } 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 mapper.Map(endpoint); endpoint = await repo.CreateAsync(request, cancel); return mapper.Map(endpoint); } }