Last active
February 15, 2023 08:56
-
-
Save gonace/bced27f191dcd8f000e902c745fa2478 to your computer and use it in GitHub Desktop.
IMapper<TFrom, TTo>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Payment.System.Provider.Core.Interfaces | |
{ | |
public interface IMapper<in TFrom, out TTo> | |
{ | |
TTo Map(TFrom from); | |
} | |
} | |
namespace Payment.System.Provider.Ping.Mappers | |
{ | |
public class OrderMapper : IMapper<Ping.Models.Order, Payment.System.Models.Order> | |
{ | |
public Payment.System.Models.Order Map(Ping.Models.Order from) => new Payment.System.Models.Order | |
{ | |
Id = from.Id, | |
... | |
}; | |
} | |
} | |
namespace Payment.System.Provider.Ping.Clients | |
{ | |
public class OrderClient : BaseClient, IOrderClient | |
{ | |
private static readonly IMapper<Ping.Models.Order, Payment.System.Models.Order> OrderMapper = new OrderMapper(); | |
public OrderClient(IOptions options) | |
: base(options) | |
{ | |
} | |
public async Task<Payment.System.Models.Order> GetAsync(Ping.Requests.Order.Get request) | |
{ | |
var result = await base.GetAsync<Ping.Responses.Order>($"order/{request.Id}"); | |
return OrderMapper.Map(result); | |
} | |
public async Task<IEnumerable<Payment.System.Models.Order>> FindAsync(Ping.Requests.Order.Find request) | |
{ | |
var result = await base.GetAsync<IEnumerable<Payment.System.Models.Order>, Ping.Requests.Order.Find>($"orders"); | |
return OrderMapper.Map(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment