-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions_history_offer_index.go
79 lines (69 loc) · 1.91 KB
/
actions_history_offer_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package horizon
import (
"gitlab.com/tokend/horizon/db2"
"gitlab.com/tokend/horizon/render/hal"
"gitlab.com/tokend/horizon/render/problem"
"gitlab.com/tokend/horizon/resource"
)
type HistoryOfferIndexAction struct {
Action
OwnerID string
BaseAsset string
QuoteAsset string
PagingParams db2.PageQuery
Page hal.Page
}
// JSON is a method for actions.JSON
func (action *HistoryOfferIndexAction) JSON() {
action.Do(
action.loadParams,
action.checkAllowed,
action.loadRecords,
action.loadPage,
func() {
hal.Render(action.W, action.Page)
},
)
}
func (action *HistoryOfferIndexAction) checkAllowed() {
action.IsAllowed(action.OwnerID)
}
func (action *HistoryOfferIndexAction) loadParams() {
action.OwnerID = action.GetNonEmptyString("owner_id")
action.BaseAsset = action.GetNonEmptyString("base_asset")
action.QuoteAsset = action.GetNonEmptyString("quote_asset")
action.PagingParams = action.GetPageQuery()
action.Page.Filters = map[string]string{
"owner_id": action.OwnerID,
"base_asset": action.BaseAsset,
"quote_asset": action.QuoteAsset,
}
}
func (action *HistoryOfferIndexAction) loadRecords() {
historyOffers, err := action.HistoryQ().Offers().
ForOwnerID(action.OwnerID).
ForBase(action.BaseAsset).
ForQuote(action.QuoteAsset).
Page(action.PagingParams).
Select()
if err != nil {
action.Log.WithError(err).Error("failed to select history offers")
action.Err = &problem.ServerError
return
}
if len(historyOffers) == 0 {
action.Err = &problem.NotFound
return
}
for _, offer := range historyOffers {
action.Page.Add(resource.PopulateHistoryOffer(offer))
}
}
func (action *HistoryOfferIndexAction) loadPage() {
action.Page.BaseURL = action.BaseURL()
action.Page.BasePath = action.Path()
action.Page.Limit = action.PagingParams.Limit
action.Page.Cursor = action.PagingParams.Cursor
action.Page.Order = action.PagingParams.Order
action.Page.PopulateLinks()
}