-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_card_comments.go
114 lines (92 loc) · 2.78 KB
/
client_card_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* Copyright (c) 2023 Sebastian Borchers
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
package wego
import (
"context"
"errors"
"io"
)
// GetAllComments performs a get_all_comments request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_all_comments
func (c *Client) GetAllComments(ctx context.Context, boardID, cardID string) (comments []GetAllComment, err error) {
endpoint := c.endpoint("boards", boardID, "cards", cardID, "comments")
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &comments)
if err != nil {
return
}
return
}
// NewComment performs a new_comment request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#new_comment
func (c *Client) NewComment(ctx context.Context, boardID, cardID string, data NewCommentRequest) (r NewCommentResponse, err error) {
endpoint := c.endpoint("boards", boardID, "cards", cardID, "comments")
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, data)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// GetComment performs a get_comment request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_comment
//
// Returns ErrNotFound, if the comment could not be found.
func (c *Client) GetComment(ctx context.Context, boardID, cardID, commentID string) (comment GetComment, err error) {
endpoint := c.endpoint("boards", boardID, "cards", cardID, "comments", commentID)
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &comment)
if err != nil {
if errors.Is(err, io.EOF) {
err = ErrNotFound
}
return
}
return
}
// DeleteComment performs a delete_comment request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#delete_comment
func (c *Client) DeleteComment(ctx context.Context, boardID, cardID, commentID string) (err error) {
endpoint := c.endpoint("boards", boardID, "cards", cardID, "comments", commentID)
req, err := c.newAuthenticatedDELETERequest(ctx, endpoint)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
//#############//
//### Types ###//
//#############//
type GetAllComment struct {
ID string `json:"_id"`
Comment string `json:"comment"`
AuthorID string `json:"authorId"`
}
type NewCommentRequest struct {
AuthorID string `json:"authorId"`
Comment string `json:"comment"`
}
type NewCommentResponse struct {
ID string `json:"_id"`
}
type GetComment struct {
BoardID string `json:"boardId"`
CardID string `json:"cardId"`
Text string `json:"text"`
CreatedAt string `json:"createdAt"`
ModifiedAt string `json:"modifiedAt"`
UserID string `json:"userId"`
}