Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Nov 24, 2022
2 parents 4b8196a + 0a96845 commit 8ec941d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api/message_bus/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ components:
type: string
description: event name
example: "local-storage:disk:added"
uuid:
type: string
description: event uuid
example: "442e0e5b-9d3e-4fe8-b46f-9c4141fdecd7"
properties:
type: object
description: event properties
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ require (
github.com/getkin/kin-openapi v0.107.0
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.0
github.com/invopop/yaml v0.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/labstack/echo/v4 v4.9.1
Expand Down
1 change: 1 addition & 0 deletions model/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Event struct {
Name string `gorm:"index"`
Properties map[string]string `gorm:"foreignKey:Id"`
Timestamp int64 `gorm:"autoCreateTime:milli"`
Uuid string `json:"uuid,omitempty"`
}

type ActionType struct {
Expand Down
4 changes: 3 additions & 1 deletion route/adapter/in/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func EventAdapter(event codegen.Event) model.Event {
SourceID: event.SourceID,
Name: event.Name,
Properties: event.Properties,
Timestamp: timestamp,
Uuid: *event.Uuid,

Timestamp: timestamp,
}
}
1 change: 1 addition & 0 deletions route/adapter/out/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ func EventAdapter(event model.Event) codegen.Event {
Name: event.Name,
Properties: event.Properties,
Timestamp: utils.Ptr(time.Unix(event.Timestamp, 0)),
Uuid: &event.Uuid,
}
}
4 changes: 3 additions & 1 deletion route/api_route_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/IceWhaleTech/CasaOS-MessageBus/route/adapter/out"
"github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -101,12 +102,13 @@ func (r *APIRoute) PublishEvent(ctx echo.Context, sourceID codegen.SourceID, nam
return ctx.JSON(http.StatusBadRequest, codegen.ResponseBadRequest{Message: &message})
}
}

uuidStr := uuid.New().String()
event := codegen.Event{
SourceID: sourceID,
Name: name,
Properties: properties,
Timestamp: utils.Ptr(time.Now()),
Uuid: &uuidStr,
}

result, err := r.services.EventService.Publish(in.EventAdapter(event))
Expand Down

0 comments on commit 8ec941d

Please sign in to comment.