Upstream sync
This commit is contained in:
@@ -97,7 +97,7 @@ func GetLatestContracts(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Respond with the contracts and the total count
|
// Respond with the contracts and the total count
|
||||||
c.JSON(http.StatusOK, gin.H{"total": total, "data": models.ConvertContractToResponse(contracts)})
|
c.JSON(http.StatusOK, gin.H{"total": total, "data": models.ConvertContractToDashboardResponse(contracts)})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBuyerContracts(c *gin.Context) {
|
func GetBuyerContracts(c *gin.Context) {
|
||||||
@@ -106,6 +106,7 @@ func GetBuyerContracts(c *gin.Context) {
|
|||||||
offsetStr := c.DefaultQuery("offset", "0")
|
offsetStr := c.DefaultQuery("offset", "0")
|
||||||
status := c.QueryArray("status")
|
status := c.QueryArray("status")
|
||||||
iDsStr := c.QueryArray("ids[]")
|
iDsStr := c.QueryArray("ids[]")
|
||||||
|
qStr := c.Query("q")
|
||||||
dateCreatedStr := c.Query("date_created")
|
dateCreatedStr := c.Query("date_created")
|
||||||
startTimeStr := c.Query("start_time")
|
startTimeStr := c.Query("start_time")
|
||||||
endTimeStr := c.Query("end_time")
|
endTimeStr := c.Query("end_time")
|
||||||
@@ -170,14 +171,14 @@ func GetBuyerContracts(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch contracts
|
// Fetch contracts
|
||||||
contracts, total, st, err := contract.GetContracts(status, "", "", "", "", startTime, endTime, "", nil, contractIDs, &dateCreated, limit, offset)
|
contracts, total, st, err := contract.GetContracts(status, "", "", "", "", startTime, endTime, qStr, nil, contractIDs, &dateCreated, limit, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(st, gin.H{"error": err.Error()})
|
c.JSON(st, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond with the contracts and the total count
|
// Respond with the contracts and the total count
|
||||||
c.JSON(http.StatusOK, gin.H{"total": total, "data": models.ConvertContractToResponseModel(contracts)})
|
c.JSON(http.StatusOK, gin.H{"total": total, "data": models.ConvertContractToListResponse(contracts)})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetContractStatuses(c *gin.Context) {
|
func GetContractStatuses(c *gin.Context) {
|
||||||
@@ -249,7 +250,7 @@ func GetContractByID(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Respond with the contracts and the total count
|
// Respond with the contracts and the total count
|
||||||
c.JSON(http.StatusOK, gin.H{"data": contract})
|
c.JSON(http.StatusOK, gin.H{"data": models.ConvertContractToContractResponse(contract)})
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateContract(c *gin.Context) {
|
func UpdateContract(c *gin.Context) {
|
||||||
@@ -290,5 +291,5 @@ func UpdateContract(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Respond with the contracts and the total count
|
// Respond with the contracts and the total count
|
||||||
c.JSON(http.StatusOK, gin.H{"data": contractModel})
|
c.JSON(http.StatusOK, gin.H{"data": models.ConvertContractToContractResponse(contractModel)})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func GetInvoices(buyerName string, sortBy string, limit int, offset int, ids []i
|
|||||||
for i := range invoices {
|
for i := range invoices {
|
||||||
var sum int64
|
var sum int64
|
||||||
if invoices[i].InvoiceItem != nil {
|
if invoices[i].InvoiceItem != nil {
|
||||||
for _, item := range *invoices[i].InvoiceItem {
|
for _, item := range invoices[i].InvoiceItem {
|
||||||
sum += item.PriceCents * item.Quantity
|
sum += item.PriceCents * item.Quantity
|
||||||
}
|
}
|
||||||
invoices[i].PriceCents = sum
|
invoices[i].PriceCents = sum
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type Contract struct {
|
|||||||
BlockchainID string `json:"blockchainId"`
|
BlockchainID string `json:"blockchainId"`
|
||||||
ContractInfos []ContractInfo `json:"contractInfos"`
|
ContractInfos []ContractInfo `json:"contractInfos"`
|
||||||
ProductID uint `json:"productId"`
|
ProductID uint `json:"productId"`
|
||||||
|
TemplateID uint `json:"templateId"`
|
||||||
MaxTemp float64 `json:"maxTemp"`
|
MaxTemp float64 `json:"maxTemp"`
|
||||||
MinTemp float64 `json:"minTemp"`
|
MinTemp float64 `json:"minTemp"`
|
||||||
ArrivalDate time.Time `json:"arrivalDate"`
|
ArrivalDate time.Time `json:"arrivalDate"`
|
||||||
@@ -35,7 +36,7 @@ type Contract struct {
|
|||||||
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
|
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContractResponse struct {
|
type DashboardContractResponse struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
DeviceIDs pq.Int64Array `json:"deviceIds" gorm:"type:integer[]"`
|
DeviceIDs pq.Int64Array `json:"deviceIds" gorm:"type:integer[]"`
|
||||||
@@ -62,10 +63,132 @@ type ContractResponse struct {
|
|||||||
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
|
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertContractToResponse(contracts []Contract) []ContractResponse {
|
type ContractResponse struct {
|
||||||
|
BaseModel
|
||||||
|
Name string `json:"name"`
|
||||||
|
DeviceIDs pq.Int64Array `json:"deviceIds" gorm:"type:integer[]"`
|
||||||
|
Seller struct {
|
||||||
|
ID uint `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"seller"`
|
||||||
|
Buyer struct {
|
||||||
|
ID uint `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"buyer"`
|
||||||
|
Start struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Lat float64 `json:"lat"`
|
||||||
|
Lon float64 `json:"lon"`
|
||||||
|
Time time.Time `json:"time"`
|
||||||
|
} `json:"start"`
|
||||||
|
End struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Lat float64 `json:"lat"`
|
||||||
|
Lon float64 `json:"lon"`
|
||||||
|
Time time.Time `json:"time"`
|
||||||
|
} `json:"end"`
|
||||||
|
Product 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"`
|
||||||
|
ContractInfos []ContractInfo `json:"contractInfos"`
|
||||||
|
MaxTemp float64 `json:"maxTemp"`
|
||||||
|
MinTemp float64 `json:"minTemp"`
|
||||||
|
ArrivalDate time.Time `json:"arrivalDate"`
|
||||||
|
PenaltyType string `json:"penaltyType"`
|
||||||
|
PenaltyValue int `json:"penaltyValue"`
|
||||||
|
PenaltyRec string `json:"penaltyRec"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertContractsToContractResponse(contracts []Contract) []ContractResponse {
|
||||||
contractResponses := []ContractResponse{}
|
contractResponses := []ContractResponse{}
|
||||||
for _, contract := range contracts {
|
for _, contract := range contracts {
|
||||||
contractResponse := ContractResponse{
|
contractResponse := ConvertContractToContractResponse(contract)
|
||||||
|
contractResponses = append(contractResponses, contractResponse)
|
||||||
|
}
|
||||||
|
return contractResponses
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertContractToContractResponse(contract Contract) ContractResponse {
|
||||||
|
|
||||||
|
contractResponse := ContractResponse{
|
||||||
|
BaseModel: BaseModel{ID: contract.ID, CreatedAt: contract.CreatedAt, UpdatedAt: contract.UpdatedAt},
|
||||||
|
Name: contract.Name,
|
||||||
|
DeviceIDs: contract.DeviceIDs,
|
||||||
|
Seller: struct {
|
||||||
|
ID uint "json:\"id\""
|
||||||
|
Name string "json:\"name\""
|
||||||
|
}{
|
||||||
|
ID: contract.SellerID,
|
||||||
|
},
|
||||||
|
Buyer: struct {
|
||||||
|
ID uint "json:\"id\""
|
||||||
|
Name string "json:\"name\""
|
||||||
|
}{
|
||||||
|
ID: contract.BuyerID,
|
||||||
|
},
|
||||||
|
Start: struct {
|
||||||
|
Name string "json:\"name\""
|
||||||
|
Lat float64 "json:\"lat\""
|
||||||
|
Lon float64 "json:\"lon\""
|
||||||
|
Time time.Time "json:\"time\""
|
||||||
|
}{
|
||||||
|
Name: contract.StartPlaceName,
|
||||||
|
Lat: contract.StartLat,
|
||||||
|
Lon: contract.StartLon,
|
||||||
|
Time: contract.StartTime,
|
||||||
|
},
|
||||||
|
End: struct {
|
||||||
|
Name string "json:\"name\""
|
||||||
|
Lat float64 "json:\"lat\""
|
||||||
|
Lon float64 "json:\"lon\""
|
||||||
|
Time time.Time "json:\"time\""
|
||||||
|
}{
|
||||||
|
Name: contract.EndPlaceName,
|
||||||
|
Lat: contract.EndLat,
|
||||||
|
Lon: contract.EndLon,
|
||||||
|
Time: contract.EndTime,
|
||||||
|
},
|
||||||
|
Product: struct {
|
||||||
|
ID uint "json:\"id\""
|
||||||
|
Name string "json:\"name\""
|
||||||
|
}{
|
||||||
|
ID: contract.ProductID,
|
||||||
|
},
|
||||||
|
Template: struct {
|
||||||
|
ID uint "json:\"id\""
|
||||||
|
Name string "json:\"name\""
|
||||||
|
Value string "json:\"value\""
|
||||||
|
}{
|
||||||
|
ID: contract.TemplateID,
|
||||||
|
},
|
||||||
|
Description: contract.Description,
|
||||||
|
Status: contract.Status,
|
||||||
|
BlockchainID: contract.BlockchainID,
|
||||||
|
ContractInfos: contract.ContractInfos,
|
||||||
|
MaxTemp: contract.MaxTemp,
|
||||||
|
MinTemp: contract.MinTemp,
|
||||||
|
ArrivalDate: contract.ArrivalDate,
|
||||||
|
PenaltyType: contract.PenaltyType,
|
||||||
|
PenaltyValue: contract.PenaltyValue,
|
||||||
|
PenaltyRec: contract.PenaltyRec,
|
||||||
|
}
|
||||||
|
|
||||||
|
return contractResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertContractToDashboardResponse(contracts []Contract) []DashboardContractResponse {
|
||||||
|
contractResponses := []DashboardContractResponse{}
|
||||||
|
for _, contract := range contracts {
|
||||||
|
contractResponse := DashboardContractResponse{
|
||||||
BaseModel: BaseModel{
|
BaseModel: BaseModel{
|
||||||
ID: contract.ID,
|
ID: contract.ID,
|
||||||
CreatedAt: contract.CreatedAt,
|
CreatedAt: contract.CreatedAt,
|
||||||
@@ -100,7 +223,7 @@ func ConvertContractToResponse(contracts []Contract) []ContractResponse {
|
|||||||
return contractResponses
|
return contractResponses
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertContractToResponseModel(contracts []Contract) []ListContractResponse {
|
func ConvertContractToListResponse(contracts []Contract) []ListContractResponse {
|
||||||
listInvoiceResponses := []ListContractResponse{}
|
listInvoiceResponses := []ListContractResponse{}
|
||||||
|
|
||||||
// Get all statuses
|
// Get all statuses
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type Invoice struct {
|
|||||||
InvoiceDate time.Time `json:"invoiceDate"`
|
InvoiceDate time.Time `json:"invoiceDate"`
|
||||||
InvoiceDueDate time.Time `json:"invoiceDueDate"`
|
InvoiceDueDate time.Time `json:"invoiceDueDate"`
|
||||||
ContractID uint `json:"contractId"`
|
ContractID uint `json:"contractId"`
|
||||||
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
|
InvoiceItem []InvoiceItem `json:"invoiceItem"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ type InvoiceResponse struct {
|
|||||||
InvoiceDate time.Time `json:"invoiceDate"`
|
InvoiceDate time.Time `json:"invoiceDate"`
|
||||||
InvoiceDueDate time.Time `json:"invoiceDueDate"`
|
InvoiceDueDate time.Time `json:"invoiceDueDate"`
|
||||||
ContractID uint `json:"contractId"`
|
ContractID uint `json:"contractId"`
|
||||||
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
|
InvoiceItem []InvoiceItem `json:"invoiceItem"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ func ConvertInvoiceToResponse(invoices []Invoice) []InvoiceResponse {
|
|||||||
for _, invoice := range invoices {
|
for _, invoice := range invoices {
|
||||||
if invoice.InvoiceItem == nil {
|
if invoice.InvoiceItem == nil {
|
||||||
emptySlice := make([]InvoiceItem, 0)
|
emptySlice := make([]InvoiceItem, 0)
|
||||||
invoice.InvoiceItem = &emptySlice
|
invoice.InvoiceItem = emptySlice
|
||||||
}
|
}
|
||||||
|
|
||||||
invoiceResponse := InvoiceResponse{
|
invoiceResponse := InvoiceResponse{
|
||||||
|
|||||||
Reference in New Issue
Block a user