-
Notifications
You must be signed in to change notification settings - Fork 4
/
note.go
66 lines (54 loc) · 2.16 KB
/
note.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
package woocommerce
import "fmt"
const (
orderNoteBasePath = "orders"
)
// OrderNoteService operate Woo-Commerce Order note, eg: create, view, and delete individual order notes.
// https://woocommerce.github.io/woocommerce-rest-api-docs/#order-notes
type OrderNoteService interface {
Create(orderId int64, text string) (*OrderNote, error)
Get(orderId int64, noteId int64) (*OrderNote, error)
List(orderId int64, options interface{}) (*[]OrderNote, error)
Delete(orderId int64, noteId int64, options interface{}) (*OrderNote, error)
}
// OrderNote represent a WooCommerce Order note
// https://woocommerce.github.io/woocommerce-rest-api-docs/#order-notes
type OrderNote struct {
ID int64 `json:"id,omitempty"`
Author string `json:"author,omitempty"`
DateCreated string `json:"date_created,omitempty"`
DateCreatedGmt string `json:"date_created_gmt,omitempty"`
Note string `json:"note,omitempty"`
CustomerNote string `json:"customer_note,omitempty"`
AddedByUser bool `json:"added_by_user,omitempty"`
}
type OrderNoteServiceOp struct {
client *Client
}
func (n *OrderNoteServiceOp) Create(orderId int64, text string) (*OrderNote, error) {
path := fmt.Sprintf("%s/%d/notes", orderNoteBasePath, orderId)
resource := new(OrderNote)
insertOrderNote := OrderNote{
Note: text,
}
err := n.client.Post(path, insertOrderNote, resource)
return resource, err
}
func (n *OrderNoteServiceOp) Get(orderId int64, noteId int64) (*OrderNote, error) {
path := fmt.Sprintf("%s/%d/notes/%d", orderNoteBasePath, orderId, noteId)
resource := new(OrderNote)
err := n.client.Get(path, resource, nil)
return resource, err
}
func (n *OrderNoteServiceOp) List(orderId int64, options interface{}) (*[]OrderNote, error) {
path := fmt.Sprintf("%s/%d/notes", orderNoteBasePath, orderId)
resource := new([]OrderNote)
err := n.client.Get(path, resource, options)
return resource, err
}
func (n *OrderNoteServiceOp) Delete(orderId int64, noteId int64, options interface{}) (*OrderNote, error) {
path := fmt.Sprintf("%s/%d/notes/%d", orderNoteBasePath, orderId, noteId)
resource := new(OrderNote)
err := n.client.Delete(path, options, &resource)
return resource, err
}