From 334a749c58576ea7b108b572b14a0f20aff4014d Mon Sep 17 00:00:00 2001 From: LinkLeong Date: Mon, 21 Nov 2022 08:27:44 +0000 Subject: [PATCH] wip --- api/message_bus/openapi.yaml | 24 +++++------------------- route/adapter/in/action.go | 6 +----- route/adapter/out/action.go | 9 +++++---- route/api_route_action.go | 6 ++++-- 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/api/message_bus/openapi.yaml b/api/message_bus/openapi.yaml index 14b7b8f..724ad47 100644 --- a/api/message_bus/openapi.yaml +++ b/api/message_bus/openapi.yaml @@ -346,9 +346,7 @@ components: content: application/json: schema: - type: array - items: - $ref: "#/components/schemas/Property" + $ref: "#/components/schemas/Property" responses: ResponseInternalServerError: @@ -499,19 +497,8 @@ components: Property: type: object - required: - - "name" - - "value" - properties: - name: - type: string - description: property name - example: "local-storage:vendor" - value: - type: string - description: property value - example: "SanDisk" - + additionalProperties: + type: string Event: type: object required: @@ -576,10 +563,9 @@ components: description: action name example: "local-storage:disk:format" properties: - type: array + type: object description: action properties - items: - $ref: "#/components/schemas/Property" + $ref: "#/components/schemas/Property" timestamp: type: string description: timestamp this action took place diff --git a/route/adapter/in/action.go b/route/adapter/in/action.go index 2a91a5e..f2801b3 100644 --- a/route/adapter/in/action.go +++ b/route/adapter/in/action.go @@ -6,10 +6,6 @@ import ( ) func ActionAdapter(action codegen.Action) model.Action { - properties := make(map[string]string) - for _, property := range *action.Properties { - properties[property.Name] = property.Value - } var timestamp int64 if action.Timestamp != nil { @@ -19,7 +15,7 @@ func ActionAdapter(action codegen.Action) model.Action { return model.Action{ SourceID: *action.SourceID, Name: *action.Name, - Properties: properties, + Properties: *action.Properties, Timestamp: timestamp, } } diff --git a/route/adapter/out/action.go b/route/adapter/out/action.go index dd507e3..c8636de 100644 --- a/route/adapter/out/action.go +++ b/route/adapter/out/action.go @@ -9,10 +9,11 @@ import ( ) func ActionAdapter(action model.Action) codegen.Action { - properties := make([]codegen.Property, 0) - for k, v := range action.Properties { - properties = append(properties, codegen.Property{Name: k, Value: v}) - } + properties := make(codegen.Property) + // for k, v := range action.Properties { + // properties = append(properties, codegen.Property{Name: k, Value: v}) + // } + properties = action.Properties return codegen.Action{ SourceID: &action.SourceID, diff --git a/route/api_route_action.go b/route/api_route_action.go index 017f6c3..1117892 100644 --- a/route/api_route_action.go +++ b/route/api_route_action.go @@ -85,16 +85,18 @@ func (r *APIRoute) TriggerAction(c echo.Context, sourceID codegen.SourceID, name return c.JSON(http.StatusNotFound, codegen.ResponseNotFound{Message: utils.Ptr("not found")}) } - var properties []codegen.Property + var properties map[string]string if err := c.Bind(&properties); err != nil { message := err.Error() return c.JSON(http.StatusBadRequest, codegen.ResponseBadRequest{Message: &message}) } + pro := codegen.Property{} + pro = properties action := codegen.Action{ SourceID: &sourceID, Name: &name, - Properties: &properties, + Properties: &pro, Timestamp: utils.Ptr(time.Now()), }