From 3d454d9dc8ba2409046c0938618a70864e6eb8ef Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 25 Jul 2022 13:16:16 +0200 Subject: entity/dag: proper base operation for simplified implementation - reduce boilerplace necessary to implement an operation - consolidate what an operation is in the core, which in turn pave the way for a generic cache layer mechanism - avoid the previously complex unmarshalling process - support operation metadata from the core - simplified testing --- bug/op_edit_comment.go | 43 ++++--------------------------------------- 1 file changed, 4 insertions(+), 39 deletions(-) (limited to 'bug/op_edit_comment.go') diff --git a/bug/op_edit_comment.go b/bug/op_edit_comment.go index 4740f37b..36c31663 100644 --- a/bug/op_edit_comment.go +++ b/bug/op_edit_comment.go @@ -1,7 +1,6 @@ package bug import ( - "encoding/json" "fmt" "github.com/pkg/errors" @@ -20,14 +19,14 @@ var _ dag.OperationWithFiles = &EditCommentOperation{} // EditCommentOperation will change a comment in the bug type EditCommentOperation struct { - OpBase + dag.OpBase Target entity.Id `json:"target"` Message string `json:"message"` Files []repository.Hash `json:"files"` } func (op *EditCommentOperation) Id() entity.Id { - return idOperation(op, &op.OpBase) + return dag.IdOperation(op, &op.OpBase) } func (op *EditCommentOperation) Apply(snapshot *Snapshot) { @@ -68,7 +67,7 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) { return } - snapshot.addActor(op.Author_) + snapshot.addActor(op.Author()) // Updating the corresponding comment @@ -101,43 +100,9 @@ func (op *EditCommentOperation) Validate() error { return nil } -// UnmarshalJSON is two steps JSON unmarshalling -// This workaround is necessary to avoid the inner OpBase.MarshalJSON -// overriding the outer op's MarshalJSON -func (op *EditCommentOperation) UnmarshalJSON(data []byte) error { - // Unmarshal OpBase and the op separately - - base := OpBase{} - err := json.Unmarshal(data, &base) - if err != nil { - return err - } - - aux := struct { - Target entity.Id `json:"target"` - Message string `json:"message"` - Files []repository.Hash `json:"files"` - }{} - - err = json.Unmarshal(data, &aux) - if err != nil { - return err - } - - op.OpBase = base - op.Target = aux.Target - op.Message = aux.Message - op.Files = aux.Files - - return nil -} - -// Sign post method for gqlgen -func (op *EditCommentOperation) IsAuthored() {} - func NewEditCommentOp(author identity.Interface, unixTime int64, target entity.Id, message string, files []repository.Hash) *EditCommentOperation { return &EditCommentOperation{ - OpBase: newOpBase(EditCommentOp, author, unixTime), + OpBase: dag.NewOpBase(EditCommentOp, author, unixTime), Target: target, Message: message, Files: files, -- cgit