This repository has been archived by the owner on Oct 23, 2021. It is now read-only.
/
pfd_transaction_get_all.go
92 lines (77 loc) · 2.07 KB
/
pfd_transaction_get_all.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
// SPDX-License-Identifier: Apache-2.0
// Copyright © 2020 Intel Corporation
package af
import (
"context"
"encoding/json"
"net/http"
)
func getAllPfdTransactions(cliCtx context.Context, afCtx *Context) (
[]PfdManagement, *http.Response, error) {
cliCfg := NewConfiguration(afCtx)
cli := NewClient(cliCfg)
tTrans, resp, err := cli.PfdManagementGetAllAPI.PfdTransactionsGetAll(
cliCtx, afCtx.cfg.AfID)
if err != nil {
return nil, resp, err
}
return tTrans, resp, nil
}
// GetAllPfdTransactions - Function to read all PFD transactions
func GetAllPfdTransactions(w http.ResponseWriter, r *http.Request) {
var (
err error
tsResp []PfdManagement
resp *http.Response
tsRespJSON []byte
)
afCtx := r.Context().Value(keyType("af-ctx")).(*Context)
if afCtx == nil {
errRspHeader(&w, "GET ALL", "af-ctx retrieved from request is nil",
http.StatusInternalServerError)
return
}
cliCtx, cancel := context.WithCancel(context.Background())
defer cancel()
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
tsResp, resp, err = getAllPfdTransactions(cliCtx, afCtx)
if err != nil {
if resp != nil {
errRspHeader(&w, "GET ALL", err.Error(), resp.StatusCode)
} else {
errRspHeader(&w, "GET ALL", err.Error(),
http.StatusInternalServerError)
}
return
}
for key, v := range tsResp {
// Updating the Self Link and Applications Self Link in AF
var self string
self, err = updateSelfLink(afCtx.cfg, r, v)
if err != nil {
errRspHeader(&w, "GET ALL", err.Error(),
http.StatusInternalServerError)
return
}
v.Self = Link(self)
err = updateAppsLink(afCtx.cfg, r, v)
if err != nil {
errRspHeader(&w, "GET ALL", err.Error(),
http.StatusInternalServerError)
return
}
tsResp[key] = v
}
tsRespJSON, err = json.Marshal(tsResp)
if err != nil {
errRspHeader(&w, "GET ALL", err.Error(),
http.StatusInternalServerError)
return
}
w.WriteHeader(resp.StatusCode)
if _, err = w.Write(tsRespJSON); err != nil {
errRspHeader(&w, "GET ALL", err.Error(),
http.StatusInternalServerError)
return
}
}