aboutsummaryrefslogtreecommitdiffstats
path: root/bug/op_set_status.go
diff options
context:
space:
mode:
authorAmine <hilalyamine@gmail.com>2019-08-13 16:47:24 +0200
committerGitHub <noreply@github.com>2019-08-13 16:47:24 +0200
commitcf960bc7a5bd0b7af28d35de33131fb0b5ce5253 (patch)
tree5df133c91bb4e1ccc5f9fbeb4664416b93d23bf5 /bug/op_set_status.go
parent146894a5657d3b20dbaf769a950b12bd19df499c (diff)
parentc809d37152ea87a66fc281730042dcb4299a8263 (diff)
downloadgit-bug-cf960bc7a5bd0b7af28d35de33131fb0b5ce5253.tar.gz
Merge pull request #193 from MichaelMure/immutableID
Future proof the operation's ID
Diffstat (limited to 'bug/op_set_status.go')
-rw-r--r--bug/op_set_status.go50
1 files changed, 13 insertions, 37 deletions
diff --git a/bug/op_set_status.go b/bug/op_set_status.go
index 52ba8135..8a245184 100644
--- a/bug/op_set_status.go
+++ b/bug/op_set_status.go
@@ -3,10 +3,11 @@ package bug
import (
"encoding/json"
+ "github.com/pkg/errors"
+
+ "github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/identity"
- "github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/timestamp"
- "github.com/pkg/errors"
)
var _ Operation = &SetStatusOperation{}
@@ -14,30 +15,23 @@ var _ Operation = &SetStatusOperation{}
// SetStatusOperation will change the status of a bug
type SetStatusOperation struct {
OpBase
- Status Status
+ Status Status `json:"status"`
}
func (op *SetStatusOperation) base() *OpBase {
return &op.OpBase
}
-func (op *SetStatusOperation) Hash() (git.Hash, error) {
- return hashOperation(op)
+func (op *SetStatusOperation) Id() entity.Id {
+ return idOperation(op)
}
func (op *SetStatusOperation) Apply(snapshot *Snapshot) {
snapshot.Status = op.Status
snapshot.addActor(op.Author)
- hash, err := op.Hash()
- if err != nil {
- // Should never error unless a programming error happened
- // (covered in OpBase.Validate())
- panic(err)
- }
-
item := &SetStatusTimelineItem{
- hash: hash,
+ id: op.Id(),
Author: op.Author,
UnixTime: timestamp.Timestamp(op.UnixTime),
Status: op.Status,
@@ -58,27 +52,9 @@ func (op *SetStatusOperation) Validate() error {
return nil
}
-// Workaround to avoid the inner OpBase.MarshalJSON overriding the outer op
-// MarshalJSON
-func (op *SetStatusOperation) MarshalJSON() ([]byte, error) {
- base, err := json.Marshal(op.OpBase)
- if err != nil {
- return nil, err
- }
-
- // revert back to a flat map to be able to add our own fields
- var data map[string]interface{}
- if err := json.Unmarshal(base, &data); err != nil {
- return nil, err
- }
-
- data["status"] = op.Status
-
- return json.Marshal(data)
-}
-
-// Workaround to avoid the inner OpBase.MarshalJSON overriding the outer op
-// MarshalJSON
+// UnmarshalJSON is a two step JSON unmarshaling
+// 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
@@ -114,14 +90,14 @@ func NewSetStatusOp(author identity.Interface, unixTime int64, status Status) *S
}
type SetStatusTimelineItem struct {
- hash git.Hash
+ id entity.Id
Author identity.Interface
UnixTime timestamp.Timestamp
Status Status
}
-func (s SetStatusTimelineItem) Hash() git.Hash {
- return s.hash
+func (s SetStatusTimelineItem) Id() entity.Id {
+ return s.id
}
// Sign post method for gqlgen