-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_transactions.go
190 lines (171 loc) · 6.2 KB
/
api_transactions.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* Cloud API
*
* The public facing API through which connectors are exposed as a single abstract API
*
* API version: v1.5
* Contact: support@trexis.net
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package finite
import (
"encoding/json"
"net/http"
"strconv"
"strings"
"github.com/gorilla/mux"
)
// A TransactionsApiController binds http requests to an api service and writes the service results to the http response
type TransactionsApiController struct {
service TransactionsApiServicer
}
// NewTransactionsApiController creates a default api controller
func NewTransactionsApiController(s TransactionsApiServicer) Router {
return &TransactionsApiController{service: s}
}
// Routes returns all of the api route for the TransactionsApiController
func (c *TransactionsApiController) Routes() Routes {
return Routes{
{
"GetAccountTransaction",
strings.ToUpper("Get"),
"/cloud/v1/account/{accountId}/transaction/{transactionId}",
c.GetAccountTransaction,
},
{
"GetAccountTransactionImage",
strings.ToUpper("Get"),
"/cloud/v1/account/{accountId}/image/{itemId}",
c.GetAccountTransactionImage,
},
{
"GetAccountTransactionImages",
strings.ToUpper("Get"),
"/cloud/v1/account/{accountId}/transaction/{transactionId}/images",
c.GetAccountTransactionImages,
},
{
"GetAccountTransactions",
strings.ToUpper("Get"),
"/cloud/v1/account/{accountId}/transactions",
c.GetAccountTransactions,
},
{
"SearchTransactions",
strings.ToUpper("Post"),
"/cloud/v1/transactions/search",
c.SearchTransactions,
},
}
}
// GetAccountTransaction - Return a given accounts transaction
func (c *TransactionsApiController) GetAccountTransaction(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
query := r.URL.Query()
accountId := params["accountId"]
transactionId := params["transactionId"]
mask, _ := strconv.ParseBool(query.Get("mask"))
inline, _ := strconv.ParseBool(query.Get("inline"))
enhance, _ := strconv.ParseBool(query.Get("enhance"))
xTRACEID := r.Header.Get("X-TRACE-ID")
xTOKEN := r.Header.Get("X-TOKEN")
result, err := c.service.GetAccountTransaction(r.Context(), accountId, transactionId, mask, inline, enhance, xTRACEID, xTOKEN)
//If an error occured, encode the error with the status code
if err != nil {
EncodeJSONResponse(err.Error(), &result.Code, w)
return
}
//If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// GetAccountTransactionImage - Return a given image
func (c *TransactionsApiController) GetAccountTransactionImage(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
accountId := params["accountId"]
itemId := params["itemId"]
xTRACEID := r.Header.Get("X-TRACE-ID")
xTOKEN := r.Header.Get("X-TOKEN")
result, err := c.service.GetAccountTransactionImage(r.Context(), accountId, itemId, xTRACEID, xTOKEN)
//If an error occured, encode the error with the status code
if err != nil {
EncodeJSONResponse(err.Error(), &result.Code, w)
return
}
//If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// GetAccountTransactionImages - Return the binary images for a given transaction
func (c *TransactionsApiController) GetAccountTransactionImages(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
query := r.URL.Query()
accountId := params["accountId"]
transactionId := params["transactionId"]
mask, _ := strconv.ParseBool(query.Get("mask"))
inline, _ := strconv.ParseBool(query.Get("inline"))
enhance, _ := strconv.ParseBool(query.Get("enhance"))
xTRACEID := r.Header.Get("X-TRACE-ID")
xTOKEN := r.Header.Get("X-TOKEN")
result, err := c.service.GetAccountTransactionImages(r.Context(), accountId, transactionId, mask, inline, enhance, xTRACEID, xTOKEN)
//If an error occured, encode the error with the status code
if err != nil {
EncodeJSONResponse(err.Error(), &result.Code, w)
return
}
//If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// GetAccountTransactions - Return a accounts transactions
func (c *TransactionsApiController) GetAccountTransactions(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
query := r.URL.Query()
accountId := params["accountId"]
mask, _ := strconv.ParseBool(query.Get("mask"))
startDateTime := query.Get("startDateTime")
endDateTime := query.Get("endDateTime")
reversedInRunning, _ := strconv.ParseBool(query.Get("reversedInRunning"))
limit, err := parseInt32Parameter(query.Get("limit"))
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
cursor := query.Get("cursor")
status := TransactionStatus(query.Get("status"))
enhance, _ := strconv.ParseBool(query.Get("enhance"))
xTRACEID := r.Header.Get("X-TRACE-ID")
xTOKEN := r.Header.Get("X-TOKEN")
result, err := c.service.GetAccountTransactions(r.Context(), accountId, mask, startDateTime, endDateTime, reversedInRunning, limit, cursor, status, enhance, xTRACEID, xTOKEN)
//If an error occured, encode the error with the status code
if err != nil {
EncodeJSONResponse(err.Error(), &result.Code, w)
return
}
//If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// SearchTransactions - Search for transactions
func (c *TransactionsApiController) SearchTransactions(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
limit, err := parseInt32Parameter(query.Get("limit"))
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
cursor := query.Get("cursor")
mask, _ := strconv.ParseBool(query.Get("mask"))
enhance, _ := strconv.ParseBool(query.Get("enhance"))
xTRACEID := r.Header.Get("X-TRACE-ID")
xTOKEN := r.Header.Get("X-TOKEN")
searchFilter := &[]SearchFilter{}
if err := json.NewDecoder(r.Body).Decode(&searchFilter); err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
result, err := c.service.SearchTransactions(r.Context(), limit, cursor, mask, enhance, xTRACEID, xTOKEN, *searchFilter)
//If an error occured, encode the error with the status code
if err != nil {
EncodeJSONResponse(err.Error(), &result.Code, w)
return
}
//If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}