-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_statements.go
61 lines (53 loc) · 1.71 KB
/
api_statements.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
/*
* 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 (
"net/http"
"strconv"
"strings"
"github.com/gorilla/mux"
)
// A StatementsApiController binds http requests to an api service and writes the service results to the http response
type StatementsApiController struct {
service StatementsApiServicer
}
// NewStatementsApiController creates a default api controller
func NewStatementsApiController(s StatementsApiServicer) Router {
return &StatementsApiController{service: s}
}
// Routes returns all of the api route for the StatementsApiController
func (c *StatementsApiController) Routes() Routes {
return Routes{
{
"GetAccountStatements",
strings.ToUpper("Get"),
"/cloud/v1/account/{accountId}/statements",
c.GetAccountStatements,
},
}
}
// GetAccountStatements - Return a list of statements for a given account
func (c *StatementsApiController) GetAccountStatements(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
query := r.URL.Query()
accountId := params["accountId"]
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")
result, err := c.service.GetAccountStatements(r.Context(), accountId, mask, 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)
}