-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions_balance_trusts.go
49 lines (40 loc) · 1.03 KB
/
actions_balance_trusts.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
package horizon
import (
"gitlab.com/tokend/horizon/db2/core"
"gitlab.com/tokend/horizon/render/hal"
"gitlab.com/tokend/horizon/render/problem"
"gitlab.com/tokend/horizon/resource"
)
type BalanceTrustsAction struct {
Action
BalanceID string
CoreRecords []core.Trust
Resource resource.Trusts
}
// JSON is a method for actions.JSON
func (action *BalanceTrustsAction) JSON() {
action.Do(
action.loadParams,
action.checkAllowed,
action.loadRecords,
func() {
hal.Render(action.W, action.Resource)
},
)
}
func (action *BalanceTrustsAction) loadParams() {
action.BalanceID = action.GetString("balance_id")
}
func (action *BalanceTrustsAction) checkAllowed() {
action.IsAllowed("")
}
func (action *BalanceTrustsAction) loadRecords() {
var err error
err = action.CoreQ().Trusts().ForBalance(action.BalanceID).Select(&action.CoreRecords)
if err != nil {
action.Log.WithError(err).Error("Failed to get trusts from core DB")
action.Err = &problem.ServerError
return
}
action.Resource.Populate(action.CoreRecords)
}