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_schema_service.go
60 lines (52 loc) · 2.04 KB
/
api_schema_service.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
/*
* 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 (
"context"
"encoding/json"
"net/http"
"github.com/findy-network/findy-agent-backchannel/agent"
)
// SchemaApiService is a service that implements the logic for the SchemaApiServicer
// This service should implement the business logic for every endpoint for the SchemaApi API.
// Include any external packages or services that will be required by this service.
type SchemaApiService struct {
a *agent.Agent
}
// NewSchemaApiService creates a default api service
func NewSchemaApiService(a *agent.Agent) SchemaApiServicer {
return &SchemaApiService{
a: a,
}
}
// SchemaCreate - Create a new schema
func (s *SchemaApiService) SchemaCreate(ctx context.Context, schemaCreateRequest SchemaCreateRequest) (ImplResponse, error) {
res, err := s.a.CreateSchema(schemaCreateRequest.Data.SchemaName, schemaCreateRequest.Data.SchemaVersion, schemaCreateRequest.Data.Attributes)
if err == nil {
schema := make(map[string]interface{})
schema["id"] = res
schema["ver"] = schemaCreateRequest.Data.SchemaVersion
schema["name"] = schemaCreateRequest.Data.SchemaName
schema["attrNames"] = schemaCreateRequest.Data.Attributes
schema["seqNo"] = "" // ?
return Response(200, SchemaCreate200Response{SchemaId: res, Schema: schema}), nil
}
return Response(http.StatusInternalServerError, nil), err
}
// SchemaGetById - Get schema by id
func (s *SchemaApiService) SchemaGetById(ctx context.Context, schemaId string) (ImplResponse, error) {
res, err := s.a.GetSchema(schemaId)
if err == nil {
var resMap map[string]interface{}
if err = json.Unmarshal([]byte(res), &resMap); err == nil {
return Response(200, resMap), nil
}
}
return Response(http.StatusInternalServerError, nil), err
}