light modification
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||
"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/peer"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/purchase_resource"
|
||||
@@ -20,24 +21,11 @@ import (
|
||||
* Booking is a struct that represents a booking
|
||||
*/
|
||||
|
||||
type OrderStatus = int
|
||||
|
||||
const (
|
||||
DRAFT OrderStatus = iota
|
||||
PENDING
|
||||
CANCELLED
|
||||
PARTIAL
|
||||
PAID
|
||||
DISPUTED
|
||||
OVERDUE
|
||||
REFUND
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
utils.AbstractObject
|
||||
OrderBy string `json:"order_by" bson:"order_by" validate:"required"`
|
||||
WorkflowExecutionIDs []string `json:"workflow_execution_ids" bson:"workflow_execution_ids" validate:"required"`
|
||||
Status OrderStatus `json:"status" bson:"status" default:"0"`
|
||||
Status enum.CompletionStatus `json:"status" bson:"status" default:"0"`
|
||||
SubOrders map[string]*PeerOrder `json:"sub_orders" bson:"sub_orders"`
|
||||
Total float64 `json:"total" bson:"total" validate:"required"`
|
||||
}
|
||||
@@ -69,7 +57,7 @@ func (o *Order) Pay(scheduler *workflow_execution.WorkflowSchedule, request *too
|
||||
if _, err := o.draftBookOrder(scheduler, request); err != nil {
|
||||
return err
|
||||
}
|
||||
o.Status = PENDING
|
||||
o.Status = enum.PENDING
|
||||
_, code, err := o.GetAccessor(request).UpdateOne(o, o.GetID())
|
||||
if code != 200 || err != nil {
|
||||
return errors.New("could not update the order" + fmt.Sprintf("%v", err))
|
||||
@@ -129,7 +117,7 @@ func (o *Order) draftStoreFromModel(scheduler *workflow_execution.WorkflowSchedu
|
||||
}
|
||||
for peerID, resources := range resourcesByPeer {
|
||||
peerOrder := &PeerOrder{
|
||||
Status: DRAFT,
|
||||
Status: enum.DRAFTED,
|
||||
PeerID: peerID,
|
||||
}
|
||||
peerOrder.GenerateID()
|
||||
@@ -231,13 +219,13 @@ func (d *Order) pay(request *tools.APIRequest) error {
|
||||
if res.Error != "" {
|
||||
errs += res.Error
|
||||
}
|
||||
if res.Status != PAID {
|
||||
if res.Status != enum.PAID {
|
||||
gotAnUnpaid = true
|
||||
}
|
||||
d.Status = PARTIAL
|
||||
d.Status = enum.PARTIAL
|
||||
d.SubOrders[res.GetID()] = res
|
||||
if count == len(d.SubOrders) && !gotAnUnpaid {
|
||||
d.Status = PAID
|
||||
d.Status = enum.PAID
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,20 +238,20 @@ func (d *Order) pay(request *tools.APIRequest) error {
|
||||
|
||||
type PeerOrder struct {
|
||||
utils.AbstractObject
|
||||
Error string `json:"error,omitempty" bson:"error,omitempty"`
|
||||
PeerID string `json:"peer_id,omitempty" bson:"peer_id,omitempty"`
|
||||
Status OrderStatus `json:"status" bson:"status" default:"0"`
|
||||
BillingAddress string `json:"billing_address,omitempty" bson:"billing_address,omitempty"`
|
||||
Items []*PeerItemOrder `json:"items,omitempty" bson:"items,omitempty"`
|
||||
Total float64 `json:"total,omitempty" bson:"total,omitempty"`
|
||||
Error string `json:"error,omitempty" bson:"error,omitempty"`
|
||||
PeerID string `json:"peer_id,omitempty" bson:"peer_id,omitempty"`
|
||||
Status enum.CompletionStatus `json:"status" bson:"status" default:"0"`
|
||||
BillingAddress string `json:"billing_address,omitempty" bson:"billing_address,omitempty"`
|
||||
Items []*PeerItemOrder `json:"items,omitempty" bson:"items,omitempty"`
|
||||
Total float64 `json:"total,omitempty" bson:"total,omitempty"`
|
||||
}
|
||||
|
||||
func (d *PeerOrder) Pay(request *tools.APIRequest, response chan *PeerOrder, wg *sync.WaitGroup) {
|
||||
d.Status = PENDING
|
||||
d.Status = enum.PENDING
|
||||
go func() {
|
||||
// DO SOMETHING TO PAY ON BLOCKCHAIN OR WHATEVER ON RETURN UPDATE STATUS
|
||||
d.Status = PAID // TO REMOVE LATER IT'S A MOCK
|
||||
if d.Status == PAID {
|
||||
d.Status = enum.PAID // TO REMOVE LATER IT'S A MOCK
|
||||
if d.Status == enum.PAID {
|
||||
for _, b := range d.Items {
|
||||
if !b.Item.IsPurchased() {
|
||||
continue
|
||||
@@ -277,7 +265,7 @@ func (d *PeerOrder) Pay(request *tools.APIRequest, response chan *PeerOrder, wg
|
||||
}
|
||||
}
|
||||
|
||||
if d.Status != PENDING {
|
||||
if d.Status != enum.PENDING {
|
||||
response <- d
|
||||
}
|
||||
wg.Done()
|
||||
|
Reference in New Issue
Block a user