add_comment.go

 1package operations
 2
 3import "github.com/MichaelMure/git-bug/bug"
 4
 5var _ bug.Operation = AddCommentOperation{}
 6
 7type AddCommentOperation struct {
 8	bug.OpBase
 9	Message string     `json:"m"`
10	Author  bug.Person `json:"a"`
11}
12
13func NewAddCommentOp(author bug.Person, message string) AddCommentOperation {
14	return AddCommentOperation{
15		OpBase:  bug.OpBase{OperationType: bug.ADD_COMMENT},
16		Message: message,
17		Author:  author,
18	}
19}
20
21func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
22	comment := bug.Comment{
23		Message: op.Message,
24		Author:  op.Author,
25	}
26
27	snapshot.Comments = append(snapshot.Comments, comment)
28
29	return snapshot
30}