@@ -11,6 +11,9 @@ import (
1111 "github.com/pkg/errors"
1212)
1313
14+ // AggregateID is the global AggregateID for Inventory Aggregate.
15+ const AggregateID int8 = 2
16+
1417// Inventory defines the Inventory Aggregate.
1518type Inventory struct {
1619 ID objectid.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
@@ -25,7 +28,6 @@ type Inventory struct {
2528 Name string `bson:"name,omitempty" json:"name,omitempty"`
2629 Origin string `bson:"origin,omitempty" json:"origin,omitempty"`
2730 Price float64 `bson:"price,omitempty" json:"price,omitempty"`
28- Quantity int64 `bson:"quantity,omitempty" json:"quantity,omitempty"`
2931 RSCustomerID uuuid.UUID `bson:"rsCustomerID,omitempty" json:"rsCustomerID,omitempty"`
3032 SalePrice float64 `bson:"salePrice,omitempty" json:"salePrice,omitempty"`
3133 SKU string `bson:"sku,omitempty" json:"sku,omitempty"`
@@ -36,58 +38,33 @@ type Inventory struct {
3638 WasteWeight float64 `bson:"wasteWeight,omitempty" json:"wasteWeight,omitempty"`
3739}
3840
39- // marshalInventory is simplified version of Inventory, for convenience
40- // in Marshalling and Unmarshalling operations.
41- type marshalInventory struct {
42- ID objectid.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
43- ItemID string `bson:"itemID,omitempty" json:"itemID,omitempty"`
44- Barcode string `bson:"barcode,omitempty" json:"barcode,omitempty"`
45- DateArrived int64 `bson:"dateArrived,omitempty" json:"dateArrived,omitempty"`
46- DateSold int64 `bson:"dateSold,omitempty" json:"dateSold,omitempty"`
47- DeviceID string `bson:"deviceID,omitempty" json:"deviceID,omitempty"`
48- DonateWeight float64 `bson:"donateWeight,omitempty" json:"donateWeight,omitempty"`
49- ExpiryDate int64 `bson:"expiryDate,omitempty" json:"expiryDate,omitempty"`
50- Lot string `bson:"lot,omitempty" json:"lot,omitempty"`
51- Name string `bson:"name,omitempty" json:"name,omitempty"`
52- Origin string `bson:"origin,omitempty" json:"origin,omitempty"`
53- Price float64 `bson:"price,omitempty" json:"price,omitempty"`
54- Quantity int64 `bson:"quantity,omitempty" json:"quantity,omitempty"`
55- RSCustomerID string `bson:"rsCustomerID,omitempty" json:"rsCustomerID,omitempty"`
56- SalePrice float64 `bson:"salePrice,omitempty" json:"salePrice,omitempty"`
57- SKU string `bson:"sku,omitempty" json:"sku,omitempty"`
58- SoldWeight float64 `bson:"soldWeight,omitempty" json:"soldWeight,omitempty"`
59- Timestamp int64 `bson:"timestamp,omitempty" json:"timestamp,omitempty"`
60- TotalWeight float64 `bson:"totalWeight,omitempty" json:"totalWeight,omitempty"`
61- UPC int64 `bson:"upc,omitempty" json:"upc,omitempty"`
62- WasteWeight float64 `bson:"wasteWeight,omitempty" json:"wasteWeight,omitempty"`
63- }
64-
6541// MarshalBSON returns bytes of BSON-type.
6642func (i Inventory ) MarshalBSON () ([]byte , error ) {
67- in := & marshalInventory {
68- ID : i .ID ,
69- ItemID : i .ItemID .String (),
70- Barcode : i .Barcode ,
71- DateArrived : i .DateArrived ,
72- DateSold : i .DateSold ,
73- DeviceID : i .DeviceID .String (),
74- DonateWeight : i .DonateWeight ,
75- ExpiryDate : i .ExpiryDate ,
76- Lot : i .Lot ,
77- Name : i .Name ,
78- Origin : i .Origin ,
79- Price : i .Price ,
80- Quantity : i .Quantity ,
81- RSCustomerID : i .RSCustomerID .String (),
82- SalePrice : i .SalePrice ,
83- SKU : i .SKU ,
84- SoldWeight : i .SoldWeight ,
85- Timestamp : i .Timestamp ,
86- TotalWeight : i .TotalWeight ,
87- UPC : i .UPC ,
88- WasteWeight : i .WasteWeight ,
43+ in := map [string ]interface {}{
44+ "itemID" : i .ItemID .String (),
45+ "barcode" : i .Barcode ,
46+ "dateArrived" : i .DateArrived ,
47+ "dateSold" : i .DateSold ,
48+ "deviceID" : i .DeviceID .String (),
49+ "donateWeight" : i .DonateWeight ,
50+ "expiryDate" : i .ExpiryDate ,
51+ "lot" : i .Lot ,
52+ "name" : i .Name ,
53+ "origin" : i .Origin ,
54+ "price" : i .Price ,
55+ "rsCustomerID" : i .RSCustomerID .String (),
56+ "salePrice" : i .SalePrice ,
57+ "sku" : i .SKU ,
58+ "soldWeight" : i .SoldWeight ,
59+ "timestamp" : i .Timestamp ,
60+ "totalWeight" : i .TotalWeight ,
61+ "upc" : i .UPC ,
62+ "wasteWeight" : i .WasteWeight ,
8963 }
9064
65+ if i .ID != objectid .NilObjectID {
66+ in ["_id" ] = i .ID
67+ }
9168 return bson .Marshal (in )
9269}
9370
@@ -105,7 +82,6 @@ func (i *Inventory) MarshalJSON() ([]byte, error) {
10582 "name" : i .Name ,
10683 "origin" : i .Origin ,
10784 "price" : i .Price ,
108- "quantity" : i .Quantity ,
10985 "rsCustomerID" : i .RSCustomerID .String (),
11086 "salePrice" : i .SalePrice ,
11187 "sku" : i .SKU ,
@@ -248,13 +224,6 @@ func (i *Inventory) unmarshalFromMap(m map[string]interface{}) error {
248224 return err
249225 }
250226 }
251- if m ["quantity" ] != nil {
252- i .Quantity , err = util .AssertInt64 (m ["quantity" ])
253- if err != nil {
254- err = errors .Wrap (err , "Error while asserting Quantity" )
255- return err
256- }
257- }
258227 if m ["salePrice" ] != nil {
259228 i .SalePrice , err = util .AssertFloat64 (m ["salePrice" ])
260229 if err != nil {
0 commit comments