-
Notifications
You must be signed in to change notification settings - Fork 40
/
documentBase.go
55 lines (44 loc) · 1.16 KB
/
documentBase.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
package bongo
import (
"github.com/globalsign/mgo/bson"
"time"
)
type DocumentBase struct {
Id bson.ObjectId `bson:"_id,omitempty" json:"_id"`
Created time.Time `bson:"_created" json:"_created"`
Modified time.Time `bson:"_modified" json:"_modified"`
// We want this to default to false without any work. So this will be the opposite of isNew. We want it to be new unless set to existing
exists bool
}
// Satisfy the new tracker interface
func (d *DocumentBase) SetIsNew(isNew bool) {
d.exists = !isNew
}
// Is the document new
func (d *DocumentBase) IsNew() bool {
return !d.exists
}
// Satisfy the document interface
func (d *DocumentBase) GetId() bson.ObjectId {
return d.Id
}
// Sets the ID for the document
func (d *DocumentBase) SetId(id bson.ObjectId) {
d.Id = id
}
// Set's the created date
func (d *DocumentBase) SetCreated(t time.Time) {
d.Created = t
}
// Get the created date
func (d *DocumentBase) GetCreated() time.Time {
return d.Created
}
// Sets the modified date
func (d *DocumentBase) SetModified(t time.Time) {
d.Modified = t
}
// Get's the modified date
func (d *DocumentBase) GetModified() time.Time {
return d.Modified
}