upstream sync

This commit is contained in:
Senad Uka
2023-10-12 05:23:34 +02:00
parent d3011d77ff
commit 7369739bdd
21 changed files with 1686 additions and 85 deletions

View File

@@ -9,60 +9,60 @@ import (
type Contract struct {
gorm.Model
Name string `json:"name"`
DeviceIDs pq.Int64Array `json:"deviceIds" gorm:"type:integer[]"`
BuyerID uint `json:"buyerId"`
SellerID uint `json:"sellerId"`
Description string `json:"description"`
StartLat float64 `json:"startLat"`
StartLon float64 `json:"startLon"`
EndLat float64 `json:"endLat"`
EndLon float64 `json:"endLon"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime"`
Status string `json:"status"`
BlockchainID string `json:"blockchainId"`
ContractInfos []ContractInfo `json:"contractInfos"`
ProductID uint `json:"productId"`
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"`
BuyerName string `json:"buyerName" gorm:"-"`
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
Name string `json:"name"`
DeviceIDs pq.Int64Array `json:"deviceIds" gorm:"type:integer[]"`
BuyerID uint `json:"buyerId"`
SellerID uint `json:"sellerId"`
Description string `json:"description"`
StartPlaceName string `json:"startPlaceName"`
StartLat float64 `json:"startLat"`
StartLon float64 `json:"startLon"`
EndPlaceName string `json:"endPlaceName"`
EndLat float64 `json:"endLat"`
EndLon float64 `json:"endLon"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime"`
Status string `json:"status"`
BlockchainID string `json:"blockchainId"`
ContractInfos []ContractInfo `json:"contractInfos"`
ProductID uint `json:"productId"`
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"`
BuyerName string `json:"buyerName" gorm:"-"`
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
}
type ContractResponse struct {
BaseModel
Name string `json:"name"`
DeviceIDs pq.Int64Array `json:"deviceIds" gorm:"type:integer[]"`
BuyerID uint `json:"buyerId"`
SellerID uint `json:"sellerId"`
Description string `json:"description"`
StartLat float64 `json:"startLat"`
StartLon float64 `json:"startLon"`
EndLat float64 `json:"endLat"`
EndLon float64 `json:"endLon"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime"`
Status string `json:"status"`
BlockchainID string `json:"blockchainId"`
ContractInfos []ContractInfo `json:"contractInfos"`
ProductID uint `json:"productId"`
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"`
BuyerName string `json:"buyerName" gorm:"-"`
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
Name string `json:"name"`
DeviceIDs pq.Int64Array `json:"deviceIds" gorm:"type:integer[]"`
BuyerID uint `json:"buyerId"`
SellerID uint `json:"sellerId"`
Description string `json:"description"`
StartLat float64 `json:"startLat"`
StartLon float64 `json:"startLon"`
EndLat float64 `json:"endLat"`
EndLon float64 `json:"endLon"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime"`
Status string `json:"status"`
BlockchainID string `json:"blockchainId"`
ContractInfos []ContractInfo `json:"contractInfos"`
ProductID uint `json:"productId"`
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"`
BuyerName string `json:"buyerName" gorm:"-"`
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
}
func ConvertContractToResponse(contracts []Contract) []ContractResponse {
var contractResponses []ContractResponse
for _, contract := range contracts {
@@ -119,17 +119,18 @@ func ConvertContractToResponseModel(contracts []Contract) []ListContractResponse
}
listInvoiceResponse := ListContractResponse{
Status: KeyValue{Key: status.Key, Value: status.Value},
Buyer: CompanyShortResponse{ID: int(contract.BuyerID), Name: contract.BuyerName},
ContractID: int(contract.ID),
DateCreated: contract.CreatedAt,
NumberOfDevices: contract.NumberOfDevices,
Status: KeyValue{Key: status.Key, Value: status.Value},
Buyer: CompanyShortResponse{ID: int(contract.BuyerID), Name: contract.BuyerName},
ContractID: int(contract.ID),
DateCreated: contract.CreatedAt,
NumberOfDevices: contract.NumberOfDevices,
}
listInvoiceResponses = append(listInvoiceResponses, listInvoiceResponse)
}
return listInvoiceResponses
}
const ContractStatusActive = "active"
const ContractStatusPending = "pending"
const ContractStatusDraft = "draft"
@@ -138,14 +139,12 @@ const ContractStatusReadyForActivation = "ready_for_activation"
const ContractStatusExecuted = "executed"
const ContractStatusRevoked = "revoked"
const PenaltyTypeAmount = "amount"
const PenaltyTypePercentage = "percentage"
const PenaltyRecDaily = "daily"
const PenaltyRecMonthly = "monthly"
type Status struct {
Key string `json:"key"`
Value string `json:"value"`
@@ -164,25 +163,24 @@ func GetContractStatuses() []Status {
}
type ListContractResponse struct {
Status KeyValue `json:"status"`
Buyer CompanyShortResponse `json:"buyer"`
ContractID int `json:"contractID"`
NumberOfDevices int `json:"numberOfDevices"`
DateCreated time.Time `json:"dateCreated"`
Status KeyValue `json:"status"`
Buyer CompanyShortResponse `json:"buyer"`
ContractID int `json:"contractID"`
NumberOfDevices int `json:"numberOfDevices"`
DateCreated time.Time `json:"dateCreated"`
}
type CreateContractRequestPayload struct {
SellerID uint `json:"sellerId" binding:"required"`
BuyerID uint `json:"buyerId" binding:"required"`
Description string `json:"description"`
ProductID uint `json:"productId"`
MinTemp float64 `json:"minTemp" binding:"required"`
MaxTemp float64 `json:"maxTemp" binding:"required"`
ArrivalDate int64 `json:"arrivalDate"`
PenaltyType string `json:"penaltyType"`
PenaltyValue int `json:"penaltyValue"`
PenaltyRec string `json:"penaltyRec"`
SellerID uint `json:"sellerId" binding:"required"`
BuyerID uint `json:"buyerId" binding:"required"`
Description string `json:"description"`
ProductID uint `json:"productId"`
MinTemp float64 `json:"minTemp" binding:"required"`
MaxTemp float64 `json:"maxTemp" binding:"required"`
ArrivalDate int64 `json:"arrivalDate"`
PenaltyType string `json:"penaltyType"`
PenaltyValue int `json:"penaltyValue"`
PenaltyRec string `json:"penaltyRec"`
}
func (Contract) Update() (bool, error) {
@@ -194,5 +192,3 @@ func (Contract) Create() (bool, error) {
func (Contract) Delete() (bool, error) {
return false, nil
}

6
models/location.go Normal file
View File

@@ -0,0 +1,6 @@
package models
type Place struct {
Text string `json:"text"`
Coordinates []float64 `json:"coordinates"`
}