get rid of TrackTemplate, use Set... methods instead
This commit is contained in:
parent
191b2a874a
commit
48e60dc721
3 changed files with 21 additions and 35 deletions
|
@ -33,7 +33,7 @@ func Messages(db *sql.Storage) *tracking.Container {
|
|||
}
|
||||
|
||||
func New(cont *tracking.Container, h ...string) *message {
|
||||
return Message(cont.NewTrack(h, lib.Map{}, nil))
|
||||
return Message(cont.NewTrack(h, nil))
|
||||
}
|
||||
|
||||
// message store action handler
|
||||
|
@ -46,15 +46,7 @@ func Store(act lib.Action) bool {
|
|||
|
||||
func StoreDB(db *sql.Storage, msg lib.Message) {
|
||||
cont := Messages(db)
|
||||
t := tracking.TrackTemplate{
|
||||
Head: lib.StrMap{
|
||||
"Domain": msg.Domain(),
|
||||
"Action": msg.Action(),
|
||||
"Class": msg.Class(),
|
||||
"Item": msg.Item(),
|
||||
},
|
||||
}
|
||||
cont.Save(&t)
|
||||
cont.Save(cont.ItemFactory(cont))
|
||||
}
|
||||
|
||||
// container definition
|
||||
|
|
|
@ -20,18 +20,13 @@ type Track interface {
|
|||
Head() lib.StrMap
|
||||
Data() lib.Map
|
||||
TimeStamp() *time.Time
|
||||
Update(*TrackTemplate)
|
||||
SetTrackId(lib.Ident)
|
||||
SetTimeStamp(*time.Time)
|
||||
Update(lib.StrSlice, lib.Map, *time.Time)
|
||||
}
|
||||
|
||||
type BaseTrack = track
|
||||
|
||||
type TrackTemplate struct {
|
||||
TrackId lib.Ident
|
||||
Head lib.StrMap
|
||||
TimeStamp *time.Time
|
||||
Data lib.Map
|
||||
}
|
||||
|
||||
// basic track implementation
|
||||
|
||||
type track struct {
|
||||
|
@ -69,19 +64,15 @@ func (tr *track) TimeStamp() *time.Time {
|
|||
return tr.timeStamp
|
||||
}
|
||||
|
||||
func (tr *track) Update(t *TrackTemplate) {
|
||||
if t.TrackId != 0 {
|
||||
tr.trackId = t.TrackId
|
||||
}
|
||||
if t.Head != nil {
|
||||
tr.head = t.Head // or update map with non-empty values?
|
||||
}
|
||||
if t.TimeStamp != nil {
|
||||
tr.timeStamp = t.TimeStamp
|
||||
}
|
||||
if t.Data != nil {
|
||||
tr.data = t.Data
|
||||
}
|
||||
func (tr *track) SetTrackId(id lib.Ident) {
|
||||
tr.trackId = id
|
||||
}
|
||||
|
||||
func (tr *track) SetTimeStamp(ts *time.Time) {
|
||||
tr.timeStamp = ts
|
||||
}
|
||||
|
||||
func (tr *track) Update(h lib.StrSlice, d lib.Map, ts *time.Time) {
|
||||
}
|
||||
|
||||
// basic container implementation
|
||||
|
@ -117,13 +108,14 @@ func (cont *Container) Query(headValues lib.StrSlice) Track {
|
|||
return tr
|
||||
}
|
||||
|
||||
func (cont *Container) NewTrack(h []string, data lib.Map, ts *time.Time) Track {
|
||||
func (cont *Container) NewTrack(h []string, data lib.Map) Track {
|
||||
tr := cont.ItemFactory(cont, h...)
|
||||
//tr.SetData(data)
|
||||
cont.insert(tr)
|
||||
return tr
|
||||
}
|
||||
|
||||
func (cont *Container) Save(t *TrackTemplate) lib.Ident {
|
||||
func (cont *Container) Save(t Track) lib.Ident {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -157,7 +149,9 @@ func (cont *Container) insert(tr Track) lib.Ident {
|
|||
return err
|
||||
}
|
||||
if err := db.Query(proc, sql, values...); err == nil {
|
||||
tr.Update(&TrackTemplate{TrackId: trid, TimeStamp: ts})
|
||||
//tr.Update(&TrackTemplate{TrackId: trid, TimeStamp: ts})
|
||||
tr.SetTrackId(trid)
|
||||
tr.SetTimeStamp(ts)
|
||||
return trid
|
||||
}
|
||||
return 0
|
||||
|
|
|
@ -68,7 +68,7 @@ func BaseTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
|
|||
func TrackingTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
|
||||
cont := tracking.Tracks(db)
|
||||
cont.CreateTable()
|
||||
track := cont.NewTrack(lib.StrSlice{"t01", "john"}, lib.Map{}, nil)
|
||||
track := cont.NewTrack(lib.StrSlice{"t01", "john"}, nil)
|
||||
t.AssertEqual(track.TrackId(), lib.Ident(1))
|
||||
t.AssertEqual(track.TimeStamp().Year(), time.Now().Year())
|
||||
//fmt.Printf("%+v\n", track.TimeStamp())
|
||||
|
|
Loading…
Add table
Reference in a new issue