aboutsummaryrefslogtreecommitdiffstats
path: root/bug/op_set_status.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-01-19 19:23:31 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:40:21 +0100
commitd10c76469d40f13e27739fd363145e89bf74c3e0 (patch)
treeff613ef1ce9400f8c208d3381bd703b186958aa3 /bug/op_set_status.go
parent844616baf8dc628360942d57fd69f24e298e08da (diff)
downloadgit-bug-d10c76469d40f13e27739fd363145e89bf74c3e0.tar.gz
identity: somewhat getting closer !
Diffstat (limited to 'bug/op_set_status.go')
-rw-r--r--bug/op_set_status.go49
1 files changed, 48 insertions, 1 deletions
diff --git a/bug/op_set_status.go b/bug/op_set_status.go
index 9fc64e52..6deb1675 100644
--- a/bug/op_set_status.go
+++ b/bug/op_set_status.go
@@ -1,6 +1,8 @@
package bug
import (
+ "encoding/json"
+
"github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
"github.com/pkg/errors"
@@ -11,7 +13,7 @@ var _ Operation = &SetStatusOperation{}
// SetStatusOperation will change the status of a bug
type SetStatusOperation struct {
OpBase
- Status Status `json:"status"`
+ Status Status
}
func (op *SetStatusOperation) base() *OpBase {
@@ -54,6 +56,51 @@ 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
+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() {}