aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operation.go
blob: 15374f08e2619194a225aec0c78ecf459947b753 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package bug

import "time"

type OperationType int

const (
	_ OperationType = iota
	CreateOp
	SetTitleOp
	AddCommentOp
	SetStatusOp
)

type Operation interface {
	OpType() OperationType
	Time() time.Time
	Apply(snapshot Snapshot) Snapshot
}

type OpBase struct {
	OperationType OperationType
	Author        Person
	UnixTime      int64
}

func NewOpBase(opType OperationType, author Person) OpBase {
	return OpBase{
		OperationType: opType,
		Author:        author,
		UnixTime:      time.Now().Unix(),
	}
}

func (op OpBase) OpType() OperationType {
	return op.OperationType
}

func (op OpBase) Time() time.Time {
	return time.Unix(op.UnixTime, 0)
}