aboutsummaryrefslogtreecommitdiffstats
path: root/bug/op_set_status.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-28 20:39:39 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-29 00:51:54 +0200
commit1bf268cebc84a9de1e538cbb54bcc0f434022192 (patch)
treedaeb92cd6b15d56a7a7102f95b73756e5b9597d0 /bug/op_set_status.go
parent8af6f7d98f2fd98f85d6a17bcda49983c272cf48 (diff)
downloadgit-bug-1bf268cebc84a9de1e538cbb54bcc0f434022192.tar.gz
merge package operations into bug, they are tightly coupled anyway
Diffstat (limited to 'bug/op_set_status.go')
-rw-r--r--bug/op_set_status.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/bug/op_set_status.go b/bug/op_set_status.go
new file mode 100644
index 00000000..d6df3da4
--- /dev/null
+++ b/bug/op_set_status.go
@@ -0,0 +1,63 @@
+package bug
+
+import (
+ "github.com/pkg/errors"
+)
+
+// SetStatusOperation will change the status of a bug
+
+var _ Operation = SetStatusOperation{}
+
+type SetStatusOperation struct {
+ *OpBase
+ Status Status `json:"status"`
+}
+
+func (op SetStatusOperation) base() *OpBase {
+ return op.OpBase
+}
+
+func (op SetStatusOperation) Apply(snapshot Snapshot) Snapshot {
+ snapshot.Status = op.Status
+
+ return snapshot
+}
+
+func (op SetStatusOperation) Validate() error {
+ if err := opBaseValidate(op, SetStatusOp); err != nil {
+ return err
+ }
+
+ if err := op.Status.Validate(); err != nil {
+ return errors.Wrap(err, "status")
+ }
+
+ return nil
+}
+
+func NewSetStatusOp(author Person, unixTime int64, status Status) SetStatusOperation {
+ return SetStatusOperation{
+ OpBase: newOpBase(SetStatusOp, author, unixTime),
+ Status: status,
+ }
+}
+
+// Convenience function to apply the operation
+func Open(b Interface, author Person, unixTime int64) error {
+ op := NewSetStatusOp(author, unixTime, OpenStatus)
+ if err := op.Validate(); err != nil {
+ return err
+ }
+ b.Append(op)
+ return nil
+}
+
+// Convenience function to apply the operation
+func Close(b Interface, author Person, unixTime int64) error {
+ op := NewSetStatusOp(author, unixTime, ClosedStatus)
+ if err := op.Validate(); err != nil {
+ return err
+ }
+ b.Append(op)
+ return nil
+}