forked from gothinkster/realworld-starter-kit
/
comment.go
43 lines (36 loc) · 1014 Bytes
/
comment.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
39
40
41
42
43
package conduit
import (
"context"
"time"
)
type Comment struct {
ID uint `json:"id"`
ArticleID uint `json:"-" db:"article_id"`
Article *Article `json:"-"`
AuthorID uint `json:"-" db:"author_id"`
Author *User `json:"-"`
AuthorProfile *Profile `json:"author"`
Body string `json:"body"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
}
func (c *Comment) SetAuthorProfile(currentUser *User) {
c.AuthorProfile = &Profile{
Username: c.Author.Username,
Bio: c.Author.Bio,
Image: c.Author.Image,
}
c.AuthorProfile.Following = currentUser.IsFollowing(c.Author)
}
type CommentFilter struct {
ID *uint
ArticleID *uint
AuthorID *uint
Limit int
Offset int
}
type CommentService interface {
CreateComment(context.Context, *Comment) error
CommentByID(context.Context, uint) (*Comment, error)
Comments(context.Context, CommentFilter) ([]*Comment, error)
DeleteComment(context.Context, uint) error
}