Upstream sync
This commit is contained in:
@@ -25,6 +25,7 @@ type Contract struct {
|
||||
BlockchainID string `json:"blockchainId"`
|
||||
ContractInfos []ContractInfo `json:"contractInfos"`
|
||||
ProductID uint `json:"productId"`
|
||||
TemplateID uint `json:"templateId"`
|
||||
MaxTemp float64 `json:"maxTemp"`
|
||||
MinTemp float64 `json:"minTemp"`
|
||||
ArrivalDate time.Time `json:"arrivalDate"`
|
||||
@@ -35,7 +36,7 @@ type Contract struct {
|
||||
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
|
||||
}
|
||||
|
||||
type ContractResponse struct {
|
||||
type DashboardContractResponse struct {
|
||||
BaseModel
|
||||
Name string `json:"name"`
|
||||
DeviceIDs pq.Int64Array `json:"deviceIds" gorm:"type:integer[]"`
|
||||
@@ -62,10 +63,132 @@ type ContractResponse struct {
|
||||
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{}
|
||||
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{
|
||||
ID: contract.ID,
|
||||
CreatedAt: contract.CreatedAt,
|
||||
@@ -100,7 +223,7 @@ func ConvertContractToResponse(contracts []Contract) []ContractResponse {
|
||||
return contractResponses
|
||||
}
|
||||
|
||||
func ConvertContractToResponseModel(contracts []Contract) []ListContractResponse {
|
||||
func ConvertContractToListResponse(contracts []Contract) []ListContractResponse {
|
||||
listInvoiceResponses := []ListContractResponse{}
|
||||
|
||||
// Get all statuses
|
||||
|
||||
@@ -25,7 +25,7 @@ type Invoice struct {
|
||||
InvoiceDate time.Time `json:"invoiceDate"`
|
||||
InvoiceDueDate time.Time `json:"invoiceDueDate"`
|
||||
ContractID uint `json:"contractId"`
|
||||
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
|
||||
InvoiceItem []InvoiceItem `json:"invoiceItem"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ type InvoiceResponse struct {
|
||||
InvoiceDate time.Time `json:"invoiceDate"`
|
||||
InvoiceDueDate time.Time `json:"invoiceDueDate"`
|
||||
ContractID uint `json:"contractId"`
|
||||
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
|
||||
InvoiceItem []InvoiceItem `json:"invoiceItem"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func ConvertInvoiceToResponse(invoices []Invoice) []InvoiceResponse {
|
||||
for _, invoice := range invoices {
|
||||
if invoice.InvoiceItem == nil {
|
||||
emptySlice := make([]InvoiceItem, 0)
|
||||
invoice.InvoiceItem = &emptySlice
|
||||
invoice.InvoiceItem = emptySlice
|
||||
}
|
||||
|
||||
invoiceResponse := InvoiceResponse{
|
||||
|
||||
Reference in New Issue
Block a user