Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Nov 21, 2022
1 parent d7972e6 commit 334a749
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
24 changes: 5 additions & 19 deletions api/message_bus/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,7 @@ components:
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Property"
$ref: "#/components/schemas/Property"

responses:
ResponseInternalServerError:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions route/adapter/in/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
9 changes: 5 additions & 4 deletions route/adapter/out/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions route/api_route_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}

Expand Down

0 comments on commit 334a749

Please sign in to comment.