-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions_core_references.go
56 lines (45 loc) · 1.12 KB
/
actions_core_references.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
56
package horizon
import (
"gitlab.com/tokend/horizon/db2/core"
"gitlab.com/tokend/horizon/render/hal"
"gitlab.com/tokend/horizon/render/problem"
)
type CoreReferencesAction struct {
Action
accountID string
reference string
records []core.Reference
}
func (action *CoreReferencesAction) JSON() {
action.Do(
action.loadParams,
action.checkAllowed,
action.loadRecords,
func() {
response := map[string]interface{}{
"data": action.records,
}
hal.Render(action.W, response)
},
)
}
func (action *CoreReferencesAction) loadParams() {
action.accountID = action.GetNonEmptyString("account_id")
action.reference = action.GetString("reference")
}
func (action *CoreReferencesAction) checkAllowed() {
action.IsAllowed(action.accountID)
}
func (action *CoreReferencesAction) loadRecords() {
q := action.CoreQ().References().ForAccount(action.accountID)
if action.reference != "" {
q = q.ByReference(action.reference)
}
records, err := q.Select()
if err != nil {
action.Log.WithError(err).Error("Failed to get References from core DB")
action.Err = &problem.ServerError
return
}
action.records = records
}