-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory.go
60 lines (49 loc) · 1.12 KB
/
inventory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package models
import (
"encoding/json"
"github.com/satori/go.uuid"
"github.com/shopspring/decimal"
"strings"
)
type ItemOrigin string
const (
ItemOriginImported ItemOrigin = "IMPORT"
ItemOriginLocal ItemOrigin = "LOCAL"
)
// Category is used to define if an item is suitable for billing or pricing.
type Category struct {
Id uuid.UUID `json:"id"`
Name string `json:"name"`
}
// InventoryItem represents the physical good available
type InventoryItem struct {
Id uuid.UUID `json:"id"`
Name string `json:"name"`
CategoryId uuid.UUID `json:"category"`
Origin ItemOrigin `json:"origin"`
Price decimal.Decimal `json:"price"`
}
func (c *Category) String() string {
b, err := json.Marshal(c)
if err != nil {
return ""
}
return string(b)
}
func (i *InventoryItem) String() string {
b, err := json.Marshal(i)
if err != nil {
return ""
}
return string(b)
}
func (io *ItemOrigin) UnmarshalText(b []byte) error {
str := strings.Trim(string(b), `"`)
switch str {
case "IMPORT", "LOCAL":
*io = ItemOrigin(str)
default:
*io = ItemOriginLocal
}
return nil
}