-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.go
38 lines (32 loc) · 1.32 KB
/
entry.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
package model
import (
"go.mongodb.org/mongo-driver/bson/primitive"
"time"
)
type DBEntry struct {
ID primitive.ObjectID `bson:"_id" json:"id"`
Tags []string `bson:"tags" json:"tags"` // Tags used for searching entries and ordering
PartOf []*primitive.ObjectID `bson:"part_of" json:"part_of"` // PartOf specifies the lists this entry is part of
HashValue string `bson:"hash_value" json:"hash"` // HashValue is the SHA512-hash of the file
//FileURL string `bson:"file_url" json:"file_url"` // FileURL may be set to a file link
Timestamp time.Time `bson:"timestamp" json:"timestamp"` // Timestamp of when this entry was added
AddedBy *primitive.ObjectID `bson:"added_by" json:"added_by"` // AddedBy is a reference to the user who added this
Comments []*DBComment `bson:"comments" json:"comments"` // Comments regarding this entry
}
func (entry *DBEntry) AddTo(id *primitive.ObjectID) {
for _, addedTo := range entry.PartOf {
if addedTo.Hex() == id.Hex() {
return
}
}
entry.PartOf = append(entry.PartOf, id)
}
func (entry *DBEntry) RemoveFrom(id *primitive.ObjectID) {
for i, addedTo := range entry.PartOf {
if addedTo.Hex() == id.Hex() {
entry.PartOf = append(entry.PartOf[:i], entry.PartOf[i+1:]...)
return
}
}
return
}