Skip to content

Commit

Permalink
feature: fix for basic resource not saving sequence no. correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
akeemphilbert committed Apr 16, 2024
1 parent 59c0765 commit 3cdf30b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
10 changes: 5 additions & 5 deletions rest/event.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package rest

import (
"encoding/json"
"github.com/getkin/kin-openapi/openapi3"
"gorm.io/datatypes"
"gorm.io/gorm"
"net/http"
)

type Event struct {
gorm.Model
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
Meta EventMeta `json:"meta" gorm:"embedded"`
Version int `json:"version"`
Type string `json:"type"`
Payload datatypes.JSONMap `json:"payload"`
Meta EventMeta `json:"meta" gorm:"embedded"`
Version int `json:"version"`
errors []error
}

Expand Down
11 changes: 2 additions & 9 deletions rest/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rest

import (
"database/sql"
"encoding/json"
"errors"
"fmt"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
Expand Down Expand Up @@ -367,10 +366,7 @@ func (e *GORMProjection) GetEventHandlers() []EventHandlerConfig {
func (e *GORMProjection) ResourceUpdateHandler(ctx context.Context, logger Log, event *Event, options *EventOptions) (err error) {
basicResource := new(BasicResource)
basicResource.Metadata.SequenceNo = event.Meta.SequenceNo
err = json.Unmarshal(event.Payload, &basicResource)
if err != nil {
return err
}
basicResource.Body = event.Payload
result := options.GORMDB.Save(basicResource)
if result.Error != nil {
return result.Error
Expand All @@ -381,10 +377,7 @@ func (e *GORMProjection) ResourceUpdateHandler(ctx context.Context, logger Log,
// ResourceDeleteHandler handles Delete operations
func (e *GORMProjection) ResourceDeleteHandler(ctx context.Context, logger Log, event *Event, options *EventOptions) (err error) {
basicResource := new(BasicResource)
err = json.Unmarshal(event.Payload, &basicResource)
if err != nil {
return err
}
basicResource.Body = event.Payload
result := options.GORMDB.Delete(basicResource)
if result.Error != nil {
return result.Error
Expand Down
4 changes: 1 addition & 3 deletions rest/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,10 @@ func (r *BasicResource) GetFloat(propertyName string) float64 {
}

func NewResourceEvent(eventType string, resource Resource, tpayload map[string]interface{}) *Event {
var payload json.RawMessage
payload, _ = json.Marshal(tpayload)

return &Event{
Type: eventType,
Payload: payload,
Payload: tpayload,
Version: 2,
Meta: EventMeta{
ResourceID: resource.GetID(),
Expand Down

0 comments on commit 3cdf30b

Please sign in to comment.