From 78b207a40436d0c15a2b806171914d802cd20661 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 10 Apr 2012 20:58:13 -0400 Subject: tests passing --- core.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 11 deletions(-) (limited to 'core.go') 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 } -- cgit v1.2.3