operation.go

 1package bug
 2
 3import "time"
 4
 5type OperationType int
 6
 7const (
 8	_ OperationType = iota
 9	CreateOp
10	SetTitleOp
11	AddCommentOp
12	SetStatusOp
13	LabelChangeOp
14)
15
16type Operation interface {
17	OpType() OperationType
18	Time() time.Time
19	Apply(snapshot Snapshot) Snapshot
20
21	// TODO: data validation (ex: a title is a single line)
22	// Validate() bool
23}
24
25type OpBase struct {
26	OperationType OperationType
27	Author        Person
28	UnixTime      int64
29}
30
31func NewOpBase(opType OperationType, author Person) OpBase {
32	return OpBase{
33		OperationType: opType,
34		Author:        author,
35		UnixTime:      time.Now().Unix(),
36	}
37}
38
39func (op OpBase) OpType() OperationType {
40	return op.OperationType
41}
42
43func (op OpBase) Time() time.Time {
44	return time.Unix(op.UnixTime, 0)
45}