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_out_of_band_v2.go
136 lines (119 loc) · 4.35 KB
/
api_out_of_band_v2.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
/*
* 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 (
"encoding/json"
"net/http"
"strings"
"github.com/gorilla/mux"
)
// OutOfBandV2ApiController binds http requests to an api service and writes the service results to the http response
type OutOfBandV2ApiController struct {
service OutOfBandV2ApiServicer
errorHandler ErrorHandler
}
// OutOfBandV2ApiOption for how the controller is set up.
type OutOfBandV2ApiOption func(*OutOfBandV2ApiController)
// WithOutOfBandV2ApiErrorHandler inject ErrorHandler into controller
func WithOutOfBandV2ApiErrorHandler(h ErrorHandler) OutOfBandV2ApiOption {
return func(c *OutOfBandV2ApiController) {
c.errorHandler = h
}
}
// NewOutOfBandV2ApiController creates a default api controller
func NewOutOfBandV2ApiController(s OutOfBandV2ApiServicer, opts ...OutOfBandV2ApiOption) Router {
controller := &OutOfBandV2ApiController{
service: s,
errorHandler: DefaultErrorHandler,
}
for _, opt := range opts {
opt(controller)
}
return controller
}
// Routes returns all the api routes for the OutOfBandV2ApiController
func (c *OutOfBandV2ApiController) Routes() Routes {
return Routes{
{
"DIDCommV2AcceptInvitation",
strings.ToUpper("Post"),
"/agent/command/oob-v2/accept-invitation",
c.DIDCommV2AcceptInvitation,
},
{
"DIDCommV2CreateInvitation",
strings.ToUpper("Post"),
"/agent/command/oob-v2/create-invitation",
c.DIDCommV2CreateInvitation,
},
{
"DIDCommV2GetByInvitationId",
strings.ToUpper("Get"),
"/agent/command/oob-v2/invitation-connection/{invitationId}",
c.DIDCommV2GetByInvitationId,
},
}
}
// DIDCommV2AcceptInvitation - Accept a DIDComm V2 out of band invitation
func (c *OutOfBandV2ApiController) DIDCommV2AcceptInvitation(w http.ResponseWriter, r *http.Request) {
didCommV2AcceptInvitationRequestParam := DidCommV2AcceptInvitationRequest{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&didCommV2AcceptInvitationRequestParam); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertDidCommV2AcceptInvitationRequestRequired(didCommV2AcceptInvitationRequestParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.DIDCommV2AcceptInvitation(r.Context(), didCommV2AcceptInvitationRequestParam)
// 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)
}
// DIDCommV2CreateInvitation - Create a new DIDComm V2 out of band invitation
func (c *OutOfBandV2ApiController) DIDCommV2CreateInvitation(w http.ResponseWriter, r *http.Request) {
didCommV2CreateInvitationRequestParam := DidCommV2CreateInvitationRequest{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&didCommV2CreateInvitationRequestParam); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertDidCommV2CreateInvitationRequestRequired(didCommV2CreateInvitationRequestParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.DIDCommV2CreateInvitation(r.Context(), didCommV2CreateInvitationRequestParam)
// 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)
}
// DIDCommV2GetByInvitationId - Get connection ID of new connection created by a response to this invitation.
func (c *OutOfBandV2ApiController) DIDCommV2GetByInvitationId(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
invitationIdParam := params["invitationId"]
result, err := c.service.DIDCommV2GetByInvitationId(r.Context(), invitationIdParam)
// 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)
}