I just want to implement microservices in my e-commerce projects. If I have 2 microservices that is the products microservice & transactions microservice in separate project & db & server. and the db design is like this:
products table:
id
name
code
price
...
transactions table:
id
product_id
qty
price
...
The question is: how can I make a Get All transactions API with relation to products? since product in another project & db? should I fetch all transaction, looping over and call get Product detail and then set the product key to the product object one by one? or is there any best workaround for this? Thanks.
I want to return something like this since I want this API returning product relation to show product in the transaction list frontend.
{
"transactions": [
{
"id": 1,
"product": {
"id": 1,
"name": "Bottle",
"code": "B1",
"price": 50000
},
"qty": 1,
"price": 50000
}, {
"id": 2,
"product": {
"id": 2,
"name": "Cable",
"code": "C1",
"price": 20000
},
"qty": 1,
"price": 20000
}
]
}