diff options
Diffstat (limited to 'bug/op_set_status.go')
-rw-r--r-- | bug/op_set_status.go | 45 |
1 files changed, 7 insertions, 38 deletions
diff --git a/bug/op_set_status.go b/bug/op_set_status.go index e22ded54..33afd795 100644 --- a/bug/op_set_status.go +++ b/bug/op_set_status.go @@ -1,11 +1,10 @@ package bug import ( - "encoding/json" - "github.com/pkg/errors" "github.com/MichaelMure/git-bug/entity" + "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/util/timestamp" ) @@ -14,21 +13,21 @@ var _ Operation = &SetStatusOperation{} // SetStatusOperation will change the status of a bug type SetStatusOperation struct { - OpBase + dag.OpBase Status Status `json:"status"` } func (op *SetStatusOperation) Id() entity.Id { - return idOperation(op, &op.OpBase) + return dag.IdOperation(op, &op.OpBase) } func (op *SetStatusOperation) Apply(snapshot *Snapshot) { snapshot.Status = op.Status - snapshot.addActor(op.Author_) + snapshot.addActor(op.Author()) item := &SetStatusTimelineItem{ id: op.Id(), - Author: op.Author_, + Author: op.Author(), UnixTime: timestamp.Timestamp(op.UnixTime), Status: op.Status, } @@ -48,39 +47,9 @@ func (op *SetStatusOperation) Validate() error { return nil } -// UnmarshalJSON is a two step JSON unmarshalling -// This workaround is necessary to avoid the inner OpBase.MarshalJSON -// overriding the outer op's MarshalJSON -func (op *SetStatusOperation) UnmarshalJSON(data []byte) error { - // Unmarshal OpBase and the op separately - - base := OpBase{} - err := json.Unmarshal(data, &base) - if err != nil { - return err - } - - aux := struct { - Status Status `json:"status"` - }{} - - err = json.Unmarshal(data, &aux) - if err != nil { - return err - } - - op.OpBase = base - op.Status = aux.Status - - return nil -} - -// Sign post method for gqlgen -func (op *SetStatusOperation) IsAuthored() {} - func NewSetStatusOp(author identity.Interface, unixTime int64, status Status) *SetStatusOperation { return &SetStatusOperation{ - OpBase: newOpBase(SetStatusOp, author, unixTime), + OpBase: dag.NewOpBase(SetStatusOp, author, unixTime), Status: status, } } @@ -96,7 +65,7 @@ func (s SetStatusTimelineItem) Id() entity.Id { return s.id } -// Sign post method for gqlgen +// IsAuthored is a sign post method for gqlgen func (s *SetStatusTimelineItem) IsAuthored() {} // Convenience function to apply the operation |