forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
answer.go
38 lines (32 loc) · 737 Bytes
/
answer.go
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
package main
type Answer struct {
Title string
Body string
Votes []Vote
Comments []Comment
Author *User
}
func NewAnswer(title, body string, user *User) *Answer {
return &Answer{
Title: title,
Body: body,
Author: user,
}
}
func (a *Answer) addCommentToList(comment Comment) {
a.Comments = append(a.Comments, comment)
}
func (a *Answer) addVoteToList(vote Vote) {
a.Votes = append(a.Votes, vote)
}
func (a *Answer) PostComment(user *User, body string) {
comment := NewComment(body)
a.addCommentToList(*comment)
user.AddCommentToList(*comment)
}
func (a *Answer) AddVote(user *User, value int) {
vote := NewVote(value)
user.AddVoteToList(vote)
a.addVoteToList(vote)
a.Author.ManageRating(vote)
}