-
Notifications
You must be signed in to change notification settings - Fork 1
/
doc_comments.go
91 lines (73 loc) · 2.91 KB
/
doc_comments.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package guildedgo
import (
"errors"
"strconv"
)
type DocComment struct {
ID int `json:"id"`
Content string `json:"content"`
CreatedAt string `json:"createdAt"`
CreatedBy string `json:"createdBy"`
UpdatedAt string `json:"updatedAt,omitempty"`
ChannelID string `json:"channelId"`
DocID int `json:"docId"`
Mentions `json:"mentions,omitempty"`
}
type docCommentEndpoints struct{}
func (e *docCommentEndpoints) Default(channelID string, docID int) string {
return guildedApi + "/channels/" + channelID + "/docs/" + strconv.Itoa(docID) + "/comments"
}
func (e *docCommentEndpoints) Get(channelID string, docID int, commentID int) string {
return guildedApi + "/channels/" + channelID + "/docs/" + strconv.Itoa(docID) + "/comments/" + strconv.Itoa(commentID)
}
type DocCommentService interface {
Create(channelID string, docID int, content string) (*DocComment, error)
GetComments(channelID string, docID int) ([]DocComment, error)
GetDocComment(channelID string, docID int, commentID int) (*DocComment, error)
UpdateDocComment(channelID string, docID int, commentID int, content string) (*DocComment, error)
DeleteDocComment(channelID string, docID int, commentID int) error
}
type docCommentService struct {
client *Client
endpoints *docCommentEndpoints
}
var _ DocCommentService = &docCommentService{}
func (s *docCommentService) Create(channelID string, docID int, content string) (*DocComment, error) {
var comment DocComment
err := s.client.PostRequestV2(s.endpoints.Default(channelID, docID), content, &comment)
if err != nil {
return nil, errors.New("error creating doc comment: " + err.Error())
}
return &comment, nil
}
func (s *docCommentService) GetComments(channelID string, docID int) ([]DocComment, error) {
var comments []DocComment
err := s.client.GetRequestV2(s.endpoints.Default(channelID, docID), &comments)
if err != nil {
return nil, errors.New("error getting doc comments: " + err.Error())
}
return comments, nil
}
func (s *docCommentService) GetDocComment(channelID string, docID int, commentID int) (*DocComment, error) {
var comment DocComment
err := s.client.GetRequestV2(s.endpoints.Get(channelID, docID, commentID), &comment)
if err != nil {
return nil, errors.New("error getting doc comment: " + err.Error())
}
return &comment, nil
}
func (s *docCommentService) UpdateDocComment(channelID string, docID int, commentID int, content string) (*DocComment, error) {
var comment DocComment
err := s.client.PatchRequest(s.endpoints.Get(channelID, docID, commentID), content, &comment)
if err != nil {
return nil, errors.New("error updating doc comment: " + err.Error())
}
return &comment, nil
}
func (s *docCommentService) DeleteDocComment(channelID string, docID int, commentID int) error {
_, err := s.client.DeleteRequest(s.endpoints.Get(channelID, docID, commentID))
if err != nil {
return errors.New("error deleting doc comment: " + err.Error())
}
return nil
}