Skip to content

Commit f24c98f

Browse files
authored
Merge pull request #7 from TerrexTech/inv-model-change
Changed inventory model
2 parents 18eae9e + c0c910d commit f24c98f

File tree

3 files changed

+76
-56
lines changed

3 files changed

+76
-56
lines changed

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inventory/model.go

Lines changed: 74 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,50 @@ const AggregateID int8 = 2
1616

1717
// Inventory defines the Inventory Aggregate.
1818
type Inventory struct {
19-
ID objectid.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
20-
ItemID uuuid.UUID `bson:"itemID,omitempty" json:"itemID,omitempty"`
21-
DateArrived int64 `bson:"dateArrived,omitempty" json:"dateArrived,omitempty"`
22-
DateSold int64 `bson:"dateSold,omitempty" json:"dateSold,omitempty"`
23-
DeviceID uuuid.UUID `bson:"deviceID,omitempty" json:"deviceID,omitempty"`
24-
DonateWeight float64 `bson:"donateWeight,omitempty" json:"donateWeight,omitempty"`
25-
Lot string `bson:"lot,omitempty" json:"lot,omitempty"`
26-
Name string `bson:"name,omitempty" json:"name,omitempty"`
27-
Origin string `bson:"origin,omitempty" json:"origin,omitempty"`
28-
Price float64 `bson:"price,omitempty" json:"price,omitempty"`
29-
RSCustomerID uuuid.UUID `bson:"rsCustomerID,omitempty" json:"rsCustomerID,omitempty"`
30-
SalePrice float64 `bson:"salePrice,omitempty" json:"salePrice,omitempty"`
31-
SKU string `bson:"sku,omitempty" json:"sku,omitempty"`
32-
SoldWeight float64 `bson:"soldWeight,omitempty" json:"soldWeight,omitempty"`
33-
Timestamp int64 `bson:"timestamp,omitempty" json:"timestamp,omitempty"`
34-
TotalWeight float64 `bson:"totalWeight,omitempty" json:"totalWeight,omitempty"`
35-
UPC string `bson:"upc,omitempty" json:"upc,omitempty"`
36-
WasteWeight float64 `bson:"wasteWeight,omitempty" json:"wasteWeight,omitempty"`
19+
ID objectid.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
20+
ItemID uuuid.UUID `bson:"itemID,omitempty" json:"itemID,omitempty"`
21+
DateArrived int64 `bson:"dateArrived,omitempty" json:"dateArrived,omitempty"`
22+
DateSold int64 `bson:"dateSold,omitempty" json:"dateSold,omitempty"`
23+
DeviceID uuuid.UUID `bson:"deviceID,omitempty" json:"deviceID,omitempty"`
24+
DonateWeight float64 `bson:"donateWeight,omitempty" json:"donateWeight,omitempty"`
25+
Lot string `bson:"lot,omitempty" json:"lot,omitempty"`
26+
Name string `bson:"name,omitempty" json:"name,omitempty"`
27+
Origin string `bson:"origin,omitempty" json:"origin,omitempty"`
28+
Price float64 `bson:"price,omitempty" json:"price,omitempty"`
29+
RSCustomerID uuuid.UUID `bson:"rsCustomerID,omitempty" json:"rsCustomerID,omitempty"`
30+
FlashSaleWeight float64 `bson:"flashSaleWeight,omitempty" json:"flashSaleWeight,omitempty"`
31+
SKU string `bson:"sku,omitempty" json:"sku,omitempty"`
32+
SoldWeight float64 `bson:"soldWeight,omitempty" json:"soldWeight,omitempty"`
33+
Timestamp int64 `bson:"timestamp,omitempty" json:"timestamp,omitempty"`
34+
TotalWeight float64 `bson:"totalWeight,omitempty" json:"totalWeight,omitempty"`
35+
UPC string `bson:"upc,omitempty" json:"upc,omitempty"`
36+
WasteWeight float64 `bson:"wasteWeight,omitempty" json:"wasteWeight,omitempty"`
37+
OnFlashSale bool `bson:"onFlashSale,omitempty" json:"onFlashSale,omitempty"`
38+
FlashSaleTimestamp int64 `bson:"flashSaleTimestamp,omitempty" json:"flashSaleTimestamp,omitempty"`
3739
}
3840

3941
// MarshalBSON returns bytes of BSON-type.
4042
func (i Inventory) MarshalBSON() ([]byte, error) {
4143
in := map[string]interface{}{
42-
"itemID": i.ItemID.String(),
43-
"dateArrived": i.DateArrived,
44-
"dateSold": i.DateSold,
45-
"deviceID": i.DeviceID.String(),
46-
"donateWeight": i.DonateWeight,
47-
"lot": i.Lot,
48-
"name": i.Name,
49-
"origin": i.Origin,
50-
"price": i.Price,
51-
"rsCustomerID": i.RSCustomerID.String(),
52-
"salePrice": i.SalePrice,
53-
"sku": i.SKU,
54-
"soldWeight": i.SoldWeight,
55-
"timestamp": i.Timestamp,
56-
"totalWeight": i.TotalWeight,
57-
"upc": i.UPC,
58-
"wasteWeight": i.WasteWeight,
44+
"itemID": i.ItemID.String(),
45+
"dateArrived": i.DateArrived,
46+
"dateSold": i.DateSold,
47+
"deviceID": i.DeviceID.String(),
48+
"donateWeight": i.DonateWeight,
49+
"lot": i.Lot,
50+
"name": i.Name,
51+
"origin": i.Origin,
52+
"onFlashSale": i.OnFlashSale,
53+
"price": i.Price,
54+
"rsCustomerID": i.RSCustomerID.String(),
55+
"flashSaleWeight": i.FlashSaleWeight,
56+
"sku": i.SKU,
57+
"soldWeight": i.SoldWeight,
58+
"timestamp": i.Timestamp,
59+
"totalWeight": i.TotalWeight,
60+
"upc": i.UPC,
61+
"wasteWeight": i.WasteWeight,
62+
"flashSaleTimestamp": i.FlashSaleTimestamp,
5963
}
6064

6165
if i.ID != objectid.NilObjectID {
@@ -67,23 +71,25 @@ func (i Inventory) MarshalBSON() ([]byte, error) {
6771
// MarshalJSON returns bytes of JSON-type.
6872
func (i *Inventory) MarshalJSON() ([]byte, error) {
6973
in := map[string]interface{}{
70-
"itemID": i.ItemID.String(),
71-
"dateArrived": i.DateArrived,
72-
"dateSold": i.DateSold,
73-
"deviceID": i.DeviceID.String(),
74-
"donateWeight": i.DonateWeight,
75-
"lot": i.Lot,
76-
"name": i.Name,
77-
"origin": i.Origin,
78-
"price": i.Price,
79-
"rsCustomerID": i.RSCustomerID.String(),
80-
"salePrice": i.SalePrice,
81-
"sku": i.SKU,
82-
"soldWeight": i.SoldWeight,
83-
"timestamp": i.Timestamp,
84-
"totalWeight": i.TotalWeight,
85-
"upc": i.UPC,
86-
"wasteWeight": i.WasteWeight,
74+
"itemID": i.ItemID.String(),
75+
"dateArrived": i.DateArrived,
76+
"dateSold": i.DateSold,
77+
"deviceID": i.DeviceID.String(),
78+
"donateWeight": i.DonateWeight,
79+
"lot": i.Lot,
80+
"name": i.Name,
81+
"origin": i.Origin,
82+
"onFlashSale": i.OnFlashSale,
83+
"price": i.Price,
84+
"rsCustomerID": i.RSCustomerID.String(),
85+
"flashSaleWeight": i.FlashSaleWeight,
86+
"sku": i.SKU,
87+
"soldWeight": i.SoldWeight,
88+
"timestamp": i.Timestamp,
89+
"totalWeight": i.TotalWeight,
90+
"upc": i.UPC,
91+
"wasteWeight": i.WasteWeight,
92+
"flashSaleTimestamp": i.FlashSaleTimestamp,
8793
}
8894

8995
if i.ID != objectid.NilObjectID {
@@ -205,10 +211,10 @@ func (i *Inventory) unmarshalFromMap(m map[string]interface{}) error {
205211
return err
206212
}
207213
}
208-
if m["salePrice"] != nil {
209-
i.SalePrice, err = util.AssertFloat64(m["salePrice"])
214+
if m["flashSaleWeight"] != nil {
215+
i.FlashSaleWeight, err = util.AssertFloat64(m["flashSaleWeight"])
210216
if err != nil {
211-
err = errors.Wrap(err, "Error while asserting SalePrice")
217+
err = errors.Wrap(err, "Error while asserting FlashSaleWeight")
212218
return err
213219
}
214220
}
@@ -245,13 +251,26 @@ func (i *Inventory) unmarshalFromMap(m map[string]interface{}) error {
245251
return errors.New("Error while asserting UPC")
246252
}
247253
}
254+
if m["onFlashSale"] != nil {
255+
i.OnFlashSale, assertOK = m["onFlashSale"].(bool)
256+
if !assertOK {
257+
return errors.New("Error while asserting OnFlashSale")
258+
}
259+
}
248260
if m["wasteWeight"] != nil {
249261
i.WasteWeight, err = util.AssertFloat64(m["wasteWeight"])
250262
if err != nil {
251263
err = errors.Wrap(err, "Error while asserting WasteWeight")
252264
return err
253265
}
254266
}
267+
if m["flashSaleTimestamp"] != nil {
268+
i.FlashSaleTimestamp, err = util.AssertInt64(m["flashSaleTimestamp"])
269+
if err != nil {
270+
err = errors.Wrap(err, "Error while asserting FlashSaleTimestamp")
271+
return err
272+
}
273+
}
255274

256275
return nil
257276
}

test/inventory_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var _ = Describe("InventoryAggregate", func() {
9393
Origin: "test-origin",
9494
Price: 13.4,
9595
RSCustomerID: rsCustomerID,
96-
SalePrice: 12.23,
96+
// SalePrice: 12.23,
9797
SKU: "test-sku",
9898
Timestamp: time.Now().Unix(),
9999
TotalWeight: 300,

0 commit comments

Comments
 (0)