This repository has been archived by the owner on May 17, 2024. It is now read-only.
generated from findy-network/findy-template-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_credential.go
119 lines (100 loc) · 3.45 KB
/
api_credential.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
/*
* Aries Agent Test Harness Backchannel API
*
* This page documents the backchannel API the test harness uses to communicate with agents under tests. For more information checkout the [Aries Interoperability Information](http://aries-interop.info) page.
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package openapi
import (
"net/http"
"strings"
"github.com/gorilla/mux"
)
// CredentialApiController binds http requests to an api service and writes the service results to the http response
type CredentialApiController struct {
service CredentialApiServicer
errorHandler ErrorHandler
}
// CredentialApiOption for how the controller is set up.
type CredentialApiOption func(*CredentialApiController)
// WithCredentialApiErrorHandler inject ErrorHandler into controller
func WithCredentialApiErrorHandler(h ErrorHandler) CredentialApiOption {
return func(c *CredentialApiController) {
c.errorHandler = h
}
}
// NewCredentialApiController creates a default api controller
func NewCredentialApiController(s CredentialApiServicer, opts ...CredentialApiOption) Router {
controller := &CredentialApiController{
service: s,
errorHandler: DefaultErrorHandler,
}
for _, opt := range opts {
opt(controller)
}
return controller
}
// Routes returns all the api routes for the CredentialApiController
func (c *CredentialApiController) Routes() Routes {
return Routes{
{
"CredentialDeleteById",
strings.ToUpper("Delete"),
"/agent/command/credential/{credentialId}",
c.CredentialDeleteById,
},
{
"CredentialGetById",
strings.ToUpper("Get"),
"/agent/command/credential/{credentialId}",
c.CredentialGetById,
},
{
"CredentialGetRevocationStatusById",
strings.ToUpper("Get"),
"/agent/command/credential/revoked/{credentialId}",
c.CredentialGetRevocationStatusById,
},
}
}
// CredentialDeleteById - Delete credential by id
func (c *CredentialApiController) CredentialDeleteById(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
credentialIdParam := params["credentialId"]
result, err := c.service.CredentialDeleteById(r.Context(), credentialIdParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// CredentialGetById - Get credential by id
func (c *CredentialApiController) CredentialGetById(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
credentialIdParam := params["credentialId"]
result, err := c.service.CredentialGetById(r.Context(), credentialIdParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// CredentialGetRevocationStatusById - Get Credential Revocation Status
func (c *CredentialApiController) CredentialGetRevocationStatusById(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
credentialIdParam := params["credentialId"]
result, err := c.service.CredentialGetRevocationStatusById(r.Context(), credentialIdParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}