-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.go
More file actions
71 lines (59 loc) · 1.85 KB
/
models.go
File metadata and controls
71 lines (59 loc) · 1.85 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"time"
"github.com/jinzhu/gorm"
)
// Session is to store informations about a recorded session
type Session struct {
gorm.Model
Name string `json:"session_name"`
StartDate time.Time `json:"start_date"`
Labels []Label `json:"labels"`
}
// BeforeDelete for labelset is used to clean up LabelTemplates
func (session *Session) BeforeDelete(tx *gorm.DB) (err error) {
// Remove invoice notes:
var labels []Label
tx.Model(&session).Related(&labels)
for _, item := range labels {
tx.Delete(&item)
}
return
}
// Label is an annotated event
type Label struct {
gorm.Model
SessionID uint `json:"session_id"`
Description string `json:"description"`
Subject string `json:"subject"`
Start float64 `json:"start"`
End float64 `json:"end"`
CreatedBy string `json:"created_by"`
}
// LabelTemplate is one node in the hierarchy
type LabelTemplate struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
DeletedAt *time.Time `json:"deleted_at,omitempty"`
Description string `json:"description,omitempty"`
LabelSetID uint `json:"labelset_id,omitempty"`
LabelTemplateID uint `json:"parent_id,omitempty"`
Children []LabelTemplate `json:"children,omitempty"`
}
// LabelSet is a collaction of hierarchical labels
type LabelSet struct {
gorm.Model
Name string `json:"name"`
Labels []LabelTemplate `json:"labels"`
}
// BeforeDelete for labelset is used to clean up LabelTemplates
func (labelset *LabelSet) BeforeDelete(tx *gorm.DB) (err error) {
// Remove invoice notes:
var labelTemps []LabelTemplate
tx.Model(&labelset).Related(&labelTemps)
for _, item := range labelTemps {
tx.Delete(&item)
}
return
}