aboutsummaryrefslogtreecommitdiffstats
path: root/core.go
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2012-04-10 20:58:13 -0400
committerbnewbold <bnewbold@robocracy.org>2012-04-11 10:58:08 -0400
commit78b207a40436d0c15a2b806171914d802cd20661 (patch)
tree730d02b32e5d54b2512a319d7ced34ad8ce3aacf /core.go
parent3c7a4451e62d27bbe9dc8eb2c16e2ff5607d1b04 (diff)
downloadbommom-78b207a40436d0c15a2b806171914d802cd20661.tar.gz
bommom-78b207a40436d0c15a2b806171914d802cd20661.zip
tests passing
Diffstat (limited to 'core.go')
-rw-r--r--core.go59
1 files changed, 48 insertions, 11 deletions
diff --git a/core.go b/core.go
index 4472f07..3b756d8 100644
--- a/core.go
+++ b/core.go
@@ -1,30 +1,67 @@
package main
+import (
+ "time"
+)
+
+type OfferPrice struct {
+ Currency string
+ MinQty uint32
+ Price float32
+}
+
type Offer struct {
+ Distributor, Sku, Url, Comment string
+ Prices []OfferPrice
}
type LineItem struct {
+ Mfg, Mpn, Description, Comment, Tag string
+ Elements []string // TODO: add "circuit element" type
+ Offers []Offer
}
-type Element struct {
+func (li *LineItem) Id() string {
+ return li.Mfg + "::" + li.Mpn
}
// The main anchor of a BOM as a cohesive whole, with a name and permissions.
// Multiple BOMs are associated with a single BomStub; the currently active one
// is the 'head'.
type BomStub struct {
- name *ShortName
- owner string
- description string
- homepage *Url
- isPublicView, isPublicEdit bool
+ Name string
+ Owner string
+ Description string
+ HeadVersion string
+ Homepage *Url
+ IsPublicView, IsPublicEdit bool
}
// An actual list of parts/elements. Intended to be immutable once persisted.
type Bom struct {
- version *ShortName
- date uint64 // TODO: unix timestamp?
- progeny string // where did this BOM come from?
- elements []Element
- lineitems []LineItem
+ Version string
+ Created time.Time // TODO: unix timestamp?
+ Progeny string // where did this BOM come from?
+ LineItems []LineItem
+}
+
+func NewBom(version string) *Bom {
+ return &Bom{Version: version, Created: time.Now()}
+}
+
+func (b *Bom) GetLineItem(mfg, mpn string) *LineItem {
+ for _, li := range b.LineItems {
+ if li.Mfg == mfg && li.Mpn == mpn {
+ return &li
+ }
+ }
+ return nil
+}
+
+func (b *Bom) AddLineItem(li *LineItem) error {
+ if eli := b.GetLineItem(li.Mfg, li.Mpn); eli != nil {
+ return Error("This BOM already had an identical LineItem")
+ }
+ b.LineItems = append(b.LineItems, *li)
+ return nil
}