test
This commit is contained in:
parent
6ab774cc43
commit
346275e12c
@ -1,14 +1,15 @@
|
|||||||
package bill
|
package bill
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/order"
|
"cloud.o-forge.io/core/oc-lib/models/order"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/purchase_resource"
|
"cloud.o-forge.io/core/oc-lib/models/resources/purchase_resource"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
@ -135,20 +136,25 @@ type PeerOrder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *PeerOrder) Pay(request *tools.APIRequest, response chan *PeerOrder, wg *sync.WaitGroup) {
|
func (d *PeerOrder) Pay(request *tools.APIRequest, response chan *PeerOrder, wg *sync.WaitGroup) {
|
||||||
|
|
||||||
d.Status = enum.PENDING
|
d.Status = enum.PENDING
|
||||||
go func() {
|
go func() {
|
||||||
|
|
||||||
// DO SOMETHING TO PAY ON BLOCKCHAIN OR WHATEVER ON RETURN UPDATE STATUS
|
// DO SOMETHING TO PAY ON BLOCKCHAIN OR WHATEVER ON RETURN UPDATE STATUS
|
||||||
d.Status = enum.PAID // TO REMOVE LATER IT'S A MOCK
|
d.Status = enum.PAID // TO REMOVE LATER IT'S A MOCK
|
||||||
if d.Status == enum.PAID {
|
if d.Status == enum.PAID {
|
||||||
for _, b := range d.Items {
|
for _, b := range d.Items {
|
||||||
if !b.Item.IsPurchasable() {
|
var priced *resources.PricedResource
|
||||||
|
bb, _ := json.Marshal(b.Item)
|
||||||
|
json.Unmarshal(bb, priced)
|
||||||
|
if !priced.IsPurchasable() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
accessor := purchase_resource.NewAccessor(request)
|
accessor := purchase_resource.NewAccessor(request)
|
||||||
accessor.StoreOne(&purchase_resource.PurchaseResource{
|
accessor.StoreOne(&purchase_resource.PurchaseResource{
|
||||||
ResourceID: b.Item.GetID(),
|
ResourceID: priced.GetID(),
|
||||||
ResourceType: b.Item.GetType(),
|
ResourceType: priced.GetType(),
|
||||||
EndDate: b.Item.GetLocationEnd(),
|
EndDate: priced.GetLocationEnd(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,14 +180,17 @@ func (d *PeerOrder) SumUpBill(request *tools.APIRequest) error {
|
|||||||
type PeerItemOrder struct {
|
type PeerItemOrder struct {
|
||||||
Quantity int `json:"quantity,omitempty" bson:"quantity,omitempty"`
|
Quantity int `json:"quantity,omitempty" bson:"quantity,omitempty"`
|
||||||
Purchase *purchase_resource.PurchaseResource `json:"purchase,omitempty" bson:"purchase,omitempty"`
|
Purchase *purchase_resource.PurchaseResource `json:"purchase,omitempty" bson:"purchase,omitempty"`
|
||||||
Item pricing.PricedItemITF `json:"item,omitempty" bson:"item,omitempty"`
|
Item map[string]interface{} `json:"item,omitempty" bson:"item,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *PeerItemOrder) GetPrice(request *tools.APIRequest) (float64, error) {
|
func (d *PeerItemOrder) GetPrice(request *tools.APIRequest) (float64, error) {
|
||||||
|
var priced *resources.PricedResource
|
||||||
|
b, _ := json.Marshal(d.Item)
|
||||||
|
json.Unmarshal(b, priced)
|
||||||
accessor := purchase_resource.NewAccessor(request)
|
accessor := purchase_resource.NewAccessor(request)
|
||||||
search, code, _ := accessor.Search(&dbs.Filters{
|
search, code, _ := accessor.Search(&dbs.Filters{
|
||||||
And: map[string][]dbs.Filter{
|
And: map[string][]dbs.Filter{
|
||||||
"resource_id": {{Operator: dbs.EQUAL.String(), Value: d.Item.GetID()}},
|
"resource_id": {{Operator: dbs.EQUAL.String(), Value: priced.GetID()}},
|
||||||
},
|
},
|
||||||
}, "", d.Purchase.IsDraft)
|
}, "", d.Purchase.IsDraft)
|
||||||
if code == 200 && len(search) > 0 {
|
if code == 200 && len(search) > 0 {
|
||||||
@ -191,7 +200,7 @@ func (d *PeerItemOrder) GetPrice(request *tools.APIRequest) (float64, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p, err := d.Item.GetPrice()
|
p, err := priced.GetPrice()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package purchase_resource
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
@ -11,11 +10,11 @@ import (
|
|||||||
type PurchaseResource struct {
|
type PurchaseResource struct {
|
||||||
utils.AbstractObject
|
utils.AbstractObject
|
||||||
DestPeerID string
|
DestPeerID string
|
||||||
PricedItem pricing.PricedItemITF `json:"priced_item,omitempty" bson:"priced_item,omitempty" validate:"required"`
|
PricedItem map[string]interface{} `json:"priced_item,omitempty" bson:"priced_item,omitempty" validate:"required"`
|
||||||
ExecutionsID string `json:"executions_id,omitempty" bson:"executions_id,omitempty" validate:"required"` // ExecutionsID is the ID of the executions
|
ExecutionsID string `json:"executions_id,omitempty" bson:"executions_id,omitempty" validate:"required"` // ExecutionsID is the ID of the executions
|
||||||
EndDate *time.Time `json:"end_buying_date,omitempty" bson:"end_buying_date,omitempty"`
|
EndDate *time.Time `json:"end_buying_date,omitempty" bson:"end_buying_date,omitempty"`
|
||||||
ResourceID string `json:"resource_id" bson:"resource_id" validate:"required"`
|
ResourceID string `json:"resource_id" bson:"resource_id" validate:"required"`
|
||||||
ResourceType tools.DataType `json:"resource_type" bson:"resource_type" validate:"required"`
|
ResourceType tools.DataType `json:"resource_type" bson:"resource_type" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *PurchaseResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
func (d *PurchaseResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||||
|
Loading…
Reference in New Issue
Block a user