Integrate loaded settings values into ui

Not yet done for single choice and multi choice, but getting there...
This commit is contained in:
Benedikt Kulmann
2020-05-07 07:42:50 +02:00
parent 8a6a06fcb8
commit e44654dc9d
21 changed files with 2416 additions and 1494 deletions
+3 -3
View File
File diff suppressed because one or more lines are too long
+1814 -1062
View File
File diff suppressed because it is too large Load Diff
+100
View File
@@ -13,6 +13,7 @@ import (
import (
context "context"
api "github.com/micro/go-micro/v2/api"
client "github.com/micro/go-micro/v2/client"
server "github.com/micro/go-micro/v2/server"
)
@@ -29,10 +30,39 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option
// Api Endpoints for BundleService service
func NewBundleServiceEndpoints() []*api.Endpoint {
return []*api.Endpoint{
&api.Endpoint{
Name: "BundleService.SaveSettingsBundle",
Path: []string{"/api/v0/settings/bundle-save"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
},
&api.Endpoint{
Name: "BundleService.GetSettingsBundle",
Path: []string{"/api/v0/settings/bundle-get"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
},
&api.Endpoint{
Name: "BundleService.ListSettingsBundles",
Path: []string{"/api/v0/settings/bundles-list"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
},
}
}
// Client API for BundleService service
type BundleService interface {
@@ -101,6 +131,27 @@ func RegisterBundleServiceHandler(s server.Server, hdlr BundleServiceHandler, op
bundleService
}
h := &bundleServiceHandler{hdlr}
opts = append(opts, api.WithEndpoint(&api.Endpoint{
Name: "BundleService.SaveSettingsBundle",
Path: []string{"/api/v0/settings/bundle-save"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
}))
opts = append(opts, api.WithEndpoint(&api.Endpoint{
Name: "BundleService.GetSettingsBundle",
Path: []string{"/api/v0/settings/bundle-get"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
}))
opts = append(opts, api.WithEndpoint(&api.Endpoint{
Name: "BundleService.ListSettingsBundles",
Path: []string{"/api/v0/settings/bundles-list"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
}))
return s.Handle(s.NewHandler(&BundleService{h}, opts...))
}
@@ -120,6 +171,34 @@ func (h *bundleServiceHandler) ListSettingsBundles(ctx context.Context, in *List
return h.BundleServiceHandler.ListSettingsBundles(ctx, in, out)
}
// Api Endpoints for ValueService service
func NewValueServiceEndpoints() []*api.Endpoint {
return []*api.Endpoint{
&api.Endpoint{
Name: "ValueService.SaveSettingsValue",
Path: []string{"/api/v0/settings/value-save"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
},
&api.Endpoint{
Name: "ValueService.GetSettingsValue",
Path: []string{"/api/v0/settings/value-get"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
},
&api.Endpoint{
Name: "ValueService.ListSettingsValues",
Path: []string{"/api/v0/settings/values-list"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
},
}
}
// Client API for ValueService service
type ValueService interface {
@@ -188,6 +267,27 @@ func RegisterValueServiceHandler(s server.Server, hdlr ValueServiceHandler, opts
valueService
}
h := &valueServiceHandler{hdlr}
opts = append(opts, api.WithEndpoint(&api.Endpoint{
Name: "ValueService.SaveSettingsValue",
Path: []string{"/api/v0/settings/value-save"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
}))
opts = append(opts, api.WithEndpoint(&api.Endpoint{
Name: "ValueService.GetSettingsValue",
Path: []string{"/api/v0/settings/value-get"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
}))
opts = append(opts, api.WithEndpoint(&api.Endpoint{
Name: "ValueService.ListSettingsValues",
Path: []string{"/api/v0/settings/values-list"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
}))
return s.Handle(s.NewHandler(&ValueService{h}, opts...))
}
+26 -26
View File
@@ -53,10 +53,10 @@ func (h *webBundleServiceHandler) GetSettingsBundle(w http.ResponseWriter, r *ht
resp := &GetSettingsBundleResponse{}
//if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
// http.Error(w, err.Error(), http.StatusPreconditionFailed)
// return
//}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusPreconditionFailed)
return
}
if err := h.h.GetSettingsBundle(
context.Background(),
@@ -67,7 +67,7 @@ func (h *webBundleServiceHandler) GetSettingsBundle(w http.ResponseWriter, r *ht
return
}
render.Status(r, http.StatusOK)
render.Status(r, http.StatusCreated)
render.JSON(w, r, resp)
}
@@ -77,10 +77,10 @@ func (h *webBundleServiceHandler) ListSettingsBundles(w http.ResponseWriter, r *
resp := &ListSettingsBundlesResponse{}
//if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
// http.Error(w, err.Error(), http.StatusPreconditionFailed)
// return
//}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusPreconditionFailed)
return
}
if err := h.h.ListSettingsBundles(
context.Background(),
@@ -91,7 +91,7 @@ func (h *webBundleServiceHandler) ListSettingsBundles(w http.ResponseWriter, r *
return
}
render.Status(r, http.StatusOK)
render.Status(r, http.StatusCreated)
render.JSON(w, r, resp)
}
@@ -101,9 +101,9 @@ func RegisterBundleServiceWeb(r chi.Router, i BundleServiceHandler, middlewares
h: i,
}
r.MethodFunc("POST", "/api/v0/settings/bundles", handler.SaveSettingsBundle)
r.MethodFunc("GET", "/api/v0/settings/bundles/{identifier.extension}/{identifier.bundle_key}", handler.GetSettingsBundle)
r.MethodFunc("GET", "/api/v0/settings/bundles/{identifier.extension}", handler.ListSettingsBundles)
r.MethodFunc("POST", "/api/v0/settings/bundle-save", handler.SaveSettingsBundle)
r.MethodFunc("POST", "/api/v0/settings/bundle-get", handler.GetSettingsBundle)
r.MethodFunc("POST", "/api/v0/settings/bundles-list", handler.ListSettingsBundles)
}
type webValueServiceHandler struct {
@@ -145,10 +145,10 @@ func (h *webValueServiceHandler) GetSettingsValue(w http.ResponseWriter, r *http
resp := &GetSettingsValueResponse{}
//if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
// http.Error(w, err.Error(), http.StatusPreconditionFailed)
// return
//}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusPreconditionFailed)
return
}
if err := h.h.GetSettingsValue(
context.Background(),
@@ -159,7 +159,7 @@ func (h *webValueServiceHandler) GetSettingsValue(w http.ResponseWriter, r *http
return
}
render.Status(r, http.StatusOK)
render.Status(r, http.StatusCreated)
render.JSON(w, r, resp)
}
@@ -169,10 +169,10 @@ func (h *webValueServiceHandler) ListSettingsValues(w http.ResponseWriter, r *ht
resp := &ListSettingsValuesResponse{}
//if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
// http.Error(w, err.Error(), http.StatusPreconditionFailed)
// return
//}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusPreconditionFailed)
return
}
if err := h.h.ListSettingsValues(
context.Background(),
@@ -183,7 +183,7 @@ func (h *webValueServiceHandler) ListSettingsValues(w http.ResponseWriter, r *ht
return
}
render.Status(r, http.StatusOK)
render.Status(r, http.StatusCreated)
render.JSON(w, r, resp)
}
@@ -193,9 +193,9 @@ func RegisterValueServiceWeb(r chi.Router, i ValueServiceHandler, middlewares ..
h: i,
}
r.MethodFunc("POST", "/api/v0/settings/values", handler.SaveSettingsValue)
r.MethodFunc("GET", "/api/v0/settings/values/{identifier.account_uuid}/{identifier.extension}/{identifier.bundle_key}/{identifier.setting_key}", handler.GetSettingsValue)
r.MethodFunc("GET", "/api/v0/settings/values/{identifier.account_uuid}/{identifier.extension}/{identifier.bundle_key}", handler.ListSettingsValues)
r.MethodFunc("POST", "/api/v0/settings/value-save", handler.SaveSettingsValue)
r.MethodFunc("POST", "/api/v0/settings/value-get", handler.GetSettingsValue)
r.MethodFunc("POST", "/api/v0/settings/values-list", handler.ListSettingsValues)
}
// SaveSettingsBundleRequestJSONMarshaler describes the default jsonpb.Marshaler used by all
+19 -7
View File
@@ -1,7 +1,7 @@
syntax = "proto3";
package proto;
option go_package = "proto";
option go_package = ".;proto";
import "google/api/annotations.proto";
import "protoc-gen-swagger/options/annotations.proto";
@@ -33,30 +33,42 @@ option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
service BundleService {
rpc SaveSettingsBundle(SaveSettingsBundleRequest) returns (SaveSettingsBundleResponse) {
option (google.api.http) = {
post: "/api/v0/settings/bundles",
post: "/api/v0/settings/bundle-save",
body: "*"
};
};
rpc GetSettingsBundle(GetSettingsBundleRequest) returns (GetSettingsBundleResponse) {
option (google.api.http).get = "/api/v0/settings/bundles/{identifier.extension}/{identifier.bundle_key}";
option (google.api.http) = {
post: "/api/v0/settings/bundle-get",
body: "*"
};
};
rpc ListSettingsBundles(ListSettingsBundlesRequest) returns (ListSettingsBundlesResponse) {
option (google.api.http).get = "/api/v0/settings/bundles/{identifier.extension}";
option (google.api.http) = {
post: "/api/v0/settings/bundles-list",
body: "*"
};
};
}
service ValueService {
rpc SaveSettingsValue(SaveSettingsValueRequest) returns (SaveSettingsValueResponse) {
option (google.api.http) = {
post: "/api/v0/settings/values",
post: "/api/v0/settings/value-save",
body: "*"
};
};
rpc GetSettingsValue(GetSettingsValueRequest) returns (GetSettingsValueResponse) {
option (google.api.http).get = "/api/v0/settings/values/{identifier.account_uuid}/{identifier.extension}/{identifier.bundle_key}/{identifier.setting_key}";
option (google.api.http) = {
post: "/api/v0/settings/value-get",
body: "*"
};
};
rpc ListSettingsValues(ListSettingsValuesRequest) returns (ListSettingsValuesResponse) {
option (google.api.http).get = "/api/v0/settings/values/{identifier.account_uuid}/{identifier.extension}/{identifier.bundle_key}";
option (google.api.http) = {
post: "/api/v0/settings/values-list",
body: "*"
};
};
}
+92 -124
View File
@@ -24,9 +24,41 @@
"application/json"
],
"paths": {
"/api/v0/settings/bundles": {
"/api/v0/settings/bundle-get": {
"post": {
"operationId": "SaveSettingsBundle",
"operationId": "BundleService_GetSettingsBundle",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protoGetSettingsBundleResponse"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/runtimeError"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/protoGetSettingsBundleRequest"
}
}
],
"tags": [
"BundleService"
]
}
},
"/api/v0/settings/bundle-save": {
"post": {
"operationId": "BundleService_SaveSettingsBundle",
"responses": {
"200": {
"description": "A successful response.",
@@ -56,9 +88,9 @@
]
}
},
"/api/v0/settings/bundles/{identifier.extension}": {
"get": {
"operationId": "ListSettingsBundles",
"/api/v0/settings/bundles-list": {
"post": {
"operationId": "BundleService_ListSettingsBundles",
"responses": {
"200": {
"description": "A successful response.",
@@ -75,28 +107,12 @@
},
"parameters": [
{
"name": "identifier.extension",
"in": "path",
"name": "body",
"in": "body",
"required": true,
"type": "string"
},
{
"name": "identifier.bundle_key",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "identifier.setting_key",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "identifier.account_uuid",
"in": "query",
"required": false,
"type": "string"
"schema": {
"$ref": "#/definitions/protoListSettingsBundlesRequest"
}
}
],
"tags": [
@@ -104,14 +120,14 @@
]
}
},
"/api/v0/settings/bundles/{identifier.extension}/{identifier.bundle_key}": {
"get": {
"operationId": "GetSettingsBundle",
"/api/v0/settings/value-get": {
"post": {
"operationId": "ValueService_GetSettingsValue",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protoGetSettingsBundleResponse"
"$ref": "#/definitions/protoGetSettingsValueResponse"
}
},
"default": {
@@ -123,38 +139,22 @@
},
"parameters": [
{
"name": "identifier.extension",
"in": "path",
"name": "body",
"in": "body",
"required": true,
"type": "string"
},
{
"name": "identifier.bundle_key",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "identifier.setting_key",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "identifier.account_uuid",
"in": "query",
"required": false,
"type": "string"
"schema": {
"$ref": "#/definitions/protoGetSettingsValueRequest"
}
}
],
"tags": [
"BundleService"
"ValueService"
]
}
},
"/api/v0/settings/values": {
"/api/v0/settings/value-save": {
"post": {
"operationId": "SaveSettingsValue",
"operationId": "ValueService_SaveSettingsValue",
"responses": {
"200": {
"description": "A successful response.",
@@ -184,9 +184,9 @@
]
}
},
"/api/v0/settings/values/{identifier.account_uuid}/{identifier.extension}/{identifier.bundle_key}": {
"get": {
"operationId": "ListSettingsValues",
"/api/v0/settings/values-list": {
"post": {
"operationId": "ValueService_ListSettingsValues",
"responses": {
"200": {
"description": "A successful response.",
@@ -203,76 +203,12 @@
},
"parameters": [
{
"name": "identifier.account_uuid",
"in": "path",
"name": "body",
"in": "body",
"required": true,
"type": "string"
},
{
"name": "identifier.extension",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "identifier.bundle_key",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "identifier.setting_key",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"ValueService"
]
}
},
"/api/v0/settings/values/{identifier.account_uuid}/{identifier.extension}/{identifier.bundle_key}/{identifier.setting_key}": {
"get": {
"operationId": "GetSettingsValue",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protoGetSettingsValueResponse"
"$ref": "#/definitions/protoListSettingsValuesRequest"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/runtimeError"
}
}
},
"parameters": [
{
"name": "identifier.account_uuid",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "identifier.extension",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "identifier.bundle_key",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "identifier.setting_key",
"in": "path",
"required": true,
"type": "string"
}
],
"tags": [
@@ -294,6 +230,14 @@
}
}
},
"protoGetSettingsBundleRequest": {
"type": "object",
"properties": {
"identifier": {
"$ref": "#/definitions/protoIdentifier"
}
}
},
"protoGetSettingsBundleResponse": {
"type": "object",
"properties": {
@@ -302,6 +246,14 @@
}
}
},
"protoGetSettingsValueRequest": {
"type": "object",
"properties": {
"identifier": {
"$ref": "#/definitions/protoIdentifier"
}
}
},
"protoGetSettingsValueResponse": {
"type": "object",
"properties": {
@@ -383,6 +335,14 @@
}
}
},
"protoListSettingsBundlesRequest": {
"type": "object",
"properties": {
"identifier": {
"$ref": "#/definitions/protoIdentifier"
}
}
},
"protoListSettingsBundlesResponse": {
"type": "object",
"properties": {
@@ -394,6 +354,14 @@
}
}
},
"protoListSettingsValuesRequest": {
"type": "object",
"properties": {
"identifier": {
"$ref": "#/definitions/protoIdentifier"
}
}
},
"protoListSettingsValuesResponse": {
"type": "object",
"properties": {
+5 -3
View File
@@ -79,8 +79,10 @@ func (g Service) ListSettingsValues(c context.Context, req *proto.ListSettingsVa
func getFailsafeIdentifier(identifier *proto.Identifier) *proto.Identifier {
if identifier == nil {
return &proto.Identifier{}
} else {
return identifier
identifier = &proto.Identifier{}
}
if identifier.AccountUuid == "me" {
identifier.AccountUuid = "5681371F-4A6E-43BC-8BB5-9C9237FA9C58"
}
return identifier
}
+7 -2
View File
@@ -30,8 +30,13 @@ func (s Store) ListBundles(identifier *proto.Identifier) ([]*proto.SettingsBundl
if err == nil {
for _, bundleFile := range bundleFiles {
record := proto.SettingsBundle{}
err = s.parseRecordFromFile(&record, path.Join(extensionPath, bundleFile.Name()))
if err == nil && (len(identifier.Extension) == 0 || identifier.Extension == record.Identifier.Extension) {
bundlePath := path.Join(extensionPath, bundleFile.Name())
err = s.parseRecordFromFile(&record, bundlePath)
if err != nil {
s.Logger.Warn().Msgf("error reading %v", bundlePath)
continue
}
if len(identifier.Extension) == 0 || identifier.Extension == record.Identifier.Extension {
records = append(records, &record)
}
}