We have an integration system. We are converting/mapping one object returned by an API to another different object to be used in POST request of another totally separate API. Right now, everything is done in one giant function making debugging really time consuming.
However, it is not as simple as using AutoMapper or a simple custom mapping class. The conversion requires lot of calls in between. A simplified version for example: Let say following is the JSON returned by a GET API call at url (http://example.com/getCustomer)
{
id:1,
addressId:42
countryid:333,
stateId:666
}
Now, we want to convert this to another object that can be sent in a POST request call to a different API say (http://foo.org/createPatron)
{
name:ABC,
address:123 Random Street
country:Canada
state:Ontario
customerSince: 4/8/2018
customerType: VIP
}
So this conversion requires lots of other API calls in addition to other logic to build right kind of object.
Now, I am in dilemma to where this conversion responsibility should take place. I have a POCO from one call and POCO from another call. Any design patterns here? Should an api caller object be passed to POCO's so that API calls can be made from it?
Aucun commentaire:
Enregistrer un commentaire