upstream sync
This commit is contained in:
@@ -200,19 +200,21 @@ func CreateContract(c *gin.Context) {
|
||||
db := shared.GetDb()
|
||||
|
||||
newContract := models.Contract{
|
||||
BuyerID: payload.BuyerID,
|
||||
SellerID: payload.SellerID,
|
||||
Description: payload.Description,
|
||||
ProductID: payload.ProductID,
|
||||
MinTemp: payload.MinTemp,
|
||||
MaxTemp: payload.MaxTemp,
|
||||
ArrivalDate: time.Unix(payload.ArrivalDate, 0),
|
||||
PenaltyType: payload.PenaltyRec,
|
||||
PenaltyValue: payload.PenaltyValue,
|
||||
PenaltyRec: payload.PenaltyRec,
|
||||
StartLat: payload.StartLat,
|
||||
StartLon: payload.StartLon,
|
||||
Status: models.ContractStatusDraft,
|
||||
BuyerID: payload.BuyerID,
|
||||
SellerID: payload.SellerID,
|
||||
Description: payload.Description,
|
||||
ProductID: payload.ProductID,
|
||||
MinTemp: payload.MinTemp,
|
||||
MaxTemp: payload.MaxTemp,
|
||||
ArrivalDate: time.Unix(payload.ArrivalDate, 0),
|
||||
PenaltyType: payload.PenaltyType,
|
||||
PenaltyValue: payload.PenaltyValue,
|
||||
PenaltyRec: payload.PenaltyRec,
|
||||
StartLat: payload.StartLat,
|
||||
StartLon: payload.StartLon,
|
||||
Status: models.ContractStatusDraft,
|
||||
StartPlaceName: payload.StartPlaceName,
|
||||
EndPlaceName: payload.EndPlaceName,
|
||||
}
|
||||
|
||||
if err := db.Create(&newContract).Error; err != nil {
|
||||
|
||||
@@ -15,6 +15,7 @@ func GetInvoices(c *gin.Context) {
|
||||
buyerName := c.Query("buyer_name")
|
||||
sortBy := c.Query("sort_by")
|
||||
iDsStr := c.QueryArray("ids[]")
|
||||
status := c.QueryArray("status")
|
||||
|
||||
limit, err := strconv.Atoi(limitStr)
|
||||
if err != nil {
|
||||
@@ -39,7 +40,7 @@ func GetInvoices(c *gin.Context) {
|
||||
invoiceIDs = append(invoiceIDs, id)
|
||||
}
|
||||
|
||||
invoices, total, err := invoice.GetInvoices(buyerName, sortBy, limit, offset, invoiceIDs)
|
||||
invoices, total, err := invoice.GetInvoices(buyerName, sortBy, limit, offset, invoiceIDs, status)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -59,7 +60,7 @@ func GetInvoiceByID(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
invoices, _, err := invoice.GetInvoices("", "", 1, 0, []int64{int64(id)})
|
||||
invoices, _, err := invoice.GetInvoices("", "", 1, 0, []int64{int64(id)}, nil)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"gitlab.com/pactual1/backend/shared"
|
||||
)
|
||||
|
||||
func GetInvoices(buyerName string, sortBy string, limit int, offset int, ids []int64) ([]models.Invoice, int64, error) {
|
||||
func GetInvoices(buyerName string, sortBy string, limit int, offset int, ids []int64, status []string) ([]models.Invoice, int64, error) {
|
||||
var invoices []models.Invoice
|
||||
|
||||
// Default sort by InvoiceDate DESC
|
||||
@@ -35,6 +35,12 @@ func GetInvoices(buyerName string, sortBy string, limit int, offset int, ids []i
|
||||
countDb = countDb.Where("id in (?)", ids)
|
||||
}
|
||||
|
||||
// Added conditional for status search
|
||||
if len(status) > 0 {
|
||||
db = db.Where("status in (?)", status)
|
||||
countDb = countDb.Where("status in (?)", status)
|
||||
}
|
||||
|
||||
var total int64
|
||||
if err := countDb.Model(&models.Invoice{}).Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
|
||||
@@ -33,6 +33,8 @@ type Contract struct {
|
||||
PenaltyValue int `json:"penaltyValue"`
|
||||
PenaltyRec string `json:"penaltyRec"`
|
||||
BuyerName string `json:"buyerName" gorm:"-"`
|
||||
SellerName string `json:"sellerName" gorm:"-"`
|
||||
ProductName string `json:"productName" gorm:"-"`
|
||||
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
|
||||
}
|
||||
|
||||
@@ -91,11 +93,6 @@ type ContractResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"product"`
|
||||
Template struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
} `json:"template"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status"`
|
||||
BlockchainID string `json:"blockchainId"`
|
||||
@@ -118,7 +115,6 @@ func ConvertContractsToContractResponse(contracts []Contract) []ContractResponse
|
||||
}
|
||||
|
||||
func ConvertContractToContractResponse(contract Contract) ContractResponse {
|
||||
|
||||
contractResponse := ContractResponse{
|
||||
BaseModel: BaseModel{ID: contract.ID, CreatedAt: contract.CreatedAt, UpdatedAt: contract.UpdatedAt},
|
||||
Name: contract.Name,
|
||||
@@ -128,12 +124,14 @@ func ConvertContractToContractResponse(contract Contract) ContractResponse {
|
||||
Name string "json:\"name\""
|
||||
}{
|
||||
ID: contract.SellerID,
|
||||
Name: contract.SellerName,
|
||||
},
|
||||
Buyer: struct {
|
||||
ID uint "json:\"id\""
|
||||
Name string "json:\"name\""
|
||||
}{
|
||||
ID: contract.BuyerID,
|
||||
Name: contract.BuyerName,
|
||||
},
|
||||
Start: struct {
|
||||
Name string "json:\"name\""
|
||||
@@ -162,13 +160,7 @@ func ConvertContractToContractResponse(contract Contract) ContractResponse {
|
||||
Name string "json:\"name\""
|
||||
}{
|
||||
ID: contract.ProductID,
|
||||
},
|
||||
Template: struct {
|
||||
ID uint "json:\"id\""
|
||||
Name string "json:\"name\""
|
||||
Value string "json:\"value\""
|
||||
}{
|
||||
ID: contract.TemplateID,
|
||||
Name: contract.ProductName,
|
||||
},
|
||||
Description: contract.Description,
|
||||
Status: contract.Status,
|
||||
|
||||
@@ -4,11 +4,10 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"gitlab.com/pactual1/backend/config"
|
||||
"gitlab.com/pactual1/backend/models"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||
"gitlab.com/pactual1/backend/config"
|
||||
"gitlab.com/pactual1/backend/models"
|
||||
)
|
||||
|
||||
var db *gorm.DB
|
||||
|
||||
Reference in New Issue
Block a user