-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions_account_index.go
55 lines (48 loc) · 1.19 KB
/
actions_account_index.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 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 AccountIndexAction struct {
Action
Types []uint64
Records []core.Account
Page hal.Page
}
func (action *AccountIndexAction) JSON() {
action.Do(
action.EnsureHistoryFreshness,
action.checkAllowed,
action.ValidateCursorWithinHistory,
action.loadRecords,
action.loadPage,
func() {
hal.Render(action.W, action.Page)
},
)
}
func (action *AccountIndexAction) checkAllowed() {
action.IsAllowed("")
}
func (action *AccountIndexAction) loadRecords() {
// pagination is turned off intentionally, coz we can't have string cursors atm
err := action.CoreQ().Accounts().
ForRoles(action.Types).
Select(&action.Records)
if err != nil {
action.Log.WithError(err).Error("failed to load accounts")
action.Err = &problem.ServerError
return
}
}
func (action *AccountIndexAction) loadPage() {
for _, record := range action.Records {
var r resource.Account
r.Populate(action.Ctx, record)
action.Page.Add(r)
}
action.Page.BaseURL = action.BaseURL()
action.Page.BasePath = action.Path()
}