upstream sync

This commit is contained in:
Senad Uka
2023-10-17 10:32:52 +02:00
parent 3cff15ed25
commit 7c3407c86d
6 changed files with 56 additions and 33 deletions

View File

@@ -182,6 +182,29 @@ func GetContractByID(contractID uint64) (models.Contract, int, error) {
return contract, http.StatusInternalServerError, err
}
return contract, http.StatusOK, nil
// Fetch the product
var product models.ProductTemplate
if err := shared.GetDb().Unscoped().Where("id = ?", contract.ProductID).First(&product).Error; err != nil {
log.Printf("GetContractByID Error: Could not fetch product: %v", err)
return contract, http.StatusInternalServerError, err
}
contract.ProductName = product.Name
// Fetch the seller
var seller models.Company
if err := shared.GetDb().Unscoped().Where("id = ?", contract.SellerID).First(&seller).Error; err != nil {
log.Printf("GetContractByID Error: Could not fetch seller: %v", err)
return contract, http.StatusInternalServerError, err
}
contract.SellerName = seller.Name
// Fetch the buyer
var buyer models.Company
if err := shared.GetDb().Unscoped().Where("id = ?", contract.BuyerID).First(&buyer).Error; err != nil {
log.Printf("GetContractByID Error: Could not fetch buyer: %v", err)
return contract, http.StatusInternalServerError, err
}
contract.BuyerName = buyer.Name
return contract, http.StatusOK, nil
}