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 b4f97b0 commit 124f5dd
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 56 deletions.
30 changes: 15 additions & 15 deletions model/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type EventType struct {
}

type Event struct {
ID uint `gorm:"primaryKey"`
SourceID string `gorm:"index"`
Name string `gorm:"index"`
Properties []Property `gorm:"foreignKey:Id"`
Timestamp int64 `gorm:"autoCreateTime:milli"`
ID uint `gorm:"primaryKey"`
SourceID string `gorm:"index"`
Name string `gorm:"index"`
Properties map[string]string `gorm:"foreignKey:Id"`
Timestamp int64 `gorm:"autoCreateTime:milli"`
}

type ActionType struct {
Expand All @@ -27,22 +27,22 @@ type ActionType struct {
}

type Action struct {
ID uint `gorm:"primaryKey"`
SourceID string `gorm:"index"`
Name string `gorm:"index"`
Properties []Property `gorm:"foreignKey:Id"`
Timestamp int64 `gorm:"autoCreateTime:milli"`
ID uint `gorm:"primaryKey"`
SourceID string `gorm:"index"`
Name string `gorm:"index"`
Properties map[string]string `gorm:"foreignKey:Id"`
Timestamp int64 `gorm:"autoCreateTime:milli"`
}

type PropertyType struct {
Name string `gorm:"primaryKey"`
}

type Property struct {
ID uint `gorm:"primaryKey"`
Name string
Value string
}
// type Property struct {
// ID uint `gorm:"primaryKey"`
// Name string
// Value string
// }

type GenericType struct {
SourceID string `gorm:"primaryKey"`
Expand Down
4 changes: 2 additions & 2 deletions route/adapter/in/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

func ActionAdapter(action codegen.Action) model.Action {
properties := make([]model.Property, 0)
properties := make(map[string]string)
for _, property := range *action.Properties {
properties = append(properties, PropertyAdapter(property))
properties[property.Name] = property.Value
}

var timestamp int64
Expand Down
10 changes: 5 additions & 5 deletions route/adapter/in/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

func EventAdapter(event codegen.Event) model.Event {
properties := make([]model.Property, 0)
for _, property := range event.Properties {
properties = append(properties, PropertyAdapter(property))
}
// properties := make([]model.Property, 0)
// for _, property := range {
// properties = append(properties, PropertyAdapter(property))
// }

var timestamp int64
if event.Timestamp != nil {
Expand All @@ -19,7 +19,7 @@ func EventAdapter(event codegen.Event) model.Event {
return model.Event{
SourceID: event.SourceID,
Name: event.Name,
Properties: properties,
Properties: event.Properties,
Timestamp: timestamp,
}
}
17 changes: 6 additions & 11 deletions route/adapter/in/property.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package in

import (
"github.com/IceWhaleTech/CasaOS-MessageBus/codegen"
"github.com/IceWhaleTech/CasaOS-MessageBus/model"
)

func PropertyAdapter(property codegen.Property) model.Property {
return model.Property{
Name: property.Name,
Value: property.Value,
}
}
// func PropertyAdapter(property codegen.Property) model.Property {
// return model.Property{
// Name: property.Name,
// Value: property.Value,
// }
// }
4 changes: 2 additions & 2 deletions route/adapter/out/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

func ActionAdapter(action model.Action) codegen.Action {
properties := make([]codegen.Property, 0)
for _, property := range action.Properties {
properties = append(properties, PropertyAdapter(property))
for k, v := range action.Properties {
properties = append(properties, codegen.Property{Name: k, Value: v})
}

return codegen.Action{
Expand Down
10 changes: 5 additions & 5 deletions route/adapter/out/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

func EventAdapter(event model.Event) codegen.Event {
properties := make([]codegen.Property, 0)
for _, property := range event.Properties {
properties = append(properties, PropertyAdapter(property))
}
// properties := make([]codegen.Property, 0)
// for _, property := range event.Properties {
// properties = append(properties, PropertyAdapter(property))
// }

return codegen.Event{
SourceID: event.SourceID,
Name: event.Name,
Properties: properties,
Properties: event.Properties,
Timestamp: utils.Ptr(time.Unix(event.Timestamp, 0)),
}
}
17 changes: 6 additions & 11 deletions route/adapter/out/property.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package out

import (
"github.com/IceWhaleTech/CasaOS-MessageBus/codegen"
"github.com/IceWhaleTech/CasaOS-MessageBus/model"
)

func PropertyAdapter(property model.Property) codegen.Property {
return codegen.Property{
Name: property.Name,
Value: property.Value,
}
}
// func PropertyAdapter(property model.Property) codegen.Property {
// return codegen.Property{
// Name: property.Name,
// Value: property.Value,
// }
// }
2 changes: 1 addition & 1 deletion route/api_route_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *APIRoute) PublishEvent(ctx echo.Context, sourceID codegen.SourceID, nam
return ctx.JSON(http.StatusNotFound, codegen.ResponseNotFound{Message: utils.Ptr("not found")})
}

var properties []codegen.Property
var properties map[string]string
if err := ctx.Bind(&properties); err != nil {
message := err.Error()
return ctx.JSON(http.StatusBadRequest, codegen.ResponseBadRequest{Message: &message})
Expand Down
8 changes: 4 additions & 4 deletions service/event_type_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ func TestEventTypeService(t *testing.T) {
expectedEvent := model.Event{
SourceID: sourceID,
Name: name,
Properties: []model.Property{
{Name: "Property1", Value: "Value1"},
{Name: "Property2", Value: "Value2"},
},
// Properties: []model.Property{
// {Name: "Property1", Value: "Value1"},
// {Name: "Property2", Value: "Value2"},
// },
}

actualEvent1, err := service.Publish(expectedEvent)
Expand Down

0 comments on commit 124f5dd

Please sign in to comment.