kiotviet #11

Merged
sinhluu merged 7 commits from kiotviet into master 2023-10-20 09:15:33 +00:00
4 changed files with 48 additions and 0 deletions
Showing only changes of commit 03b68fd7e4 - Show all commits

View File

@ -3,6 +3,7 @@ package kiotviet
const (
apiPathListBranches = "/branches"
apiPathListProductOnHands = "/productOnHands"
apiPathListWebhook = "/webhooks"
apiPathRegisterWebhook = "/webhooks"
apiPathUnregisterWebhook = "/webhooks/%d" // %s -> webhook id

View File

@ -122,6 +122,34 @@ func (c *Client) GetBranches(req ListBranchesReq) (*ListBranchesRes, error) {
return &data, nil
}
func (c *Client) ListWebhooks(req ListWebhookReq) (*ListWebhookRes, error) {
apiURL := c.getURL(apiPathListWebhook)
natsPayload := model.CommunicationRequestHttp{
ResponseImmediately: true,
Payload: model.HttpRequest{
URL: apiURL,
Method: http.MethodGet,
Header: c.getRequestHeader(),
},
LogTarget: logTarget,
}
r, err := c.requestHttpViaNats(natsPayload)
if err != nil {
log.Printf("kiotviet.Client.ListWebhooks - requestHttpViaNats: %v, %s\n", err, apiURL)
return nil, err
}
res := r.Response
if res.StatusCode >= http.StatusBadRequest {
return nil, fmt.Errorf("kiotviet.Client.ListWebhooks - requestHttpViaNats bad request %s", res.Body)
}
var data ListWebhookRes
if err = r.ParseResponseData(&data); err != nil {
return nil, fmt.Errorf("kiotviet.Client.ListWebhooks - requestHttpViaNats parse response %v, %s", err, res.Body)
}
return &data, nil
}
func (c *Client) RegisterWebhook(req RegisterWebhookReq) (*RegisterWebhookRes, error) {
apiURL := c.getURL(apiPathRegisterWebhook)
natsPayload := model.CommunicationRequestHttp{

View File

@ -23,6 +23,9 @@ type ListBranchesReq struct {
IncludeRemoveIDs string `json:"includeRemoveIds,omitempty"` // true/ false
}
type ListWebhookReq struct {
}
type WebhookReq struct {
Type string `json:"Type"`
Url string `json:"Url"`

View File

@ -67,3 +67,19 @@ type RError struct {
ErrorCode string `json:"errorCode"`
Message string `json:"message"`
}
type Webhook struct {
Id int `json:"id"`
Type string `json:"type"`
Url string `json:"url"`
IsActive bool `json:"isActive"`
RetailerId int `json:"retailerId"`
ModifiedDate time.Time `json:"modifiedDate"`
}
type ListWebhookRes struct {
Total int `json:"total"`
PageSize int `json:"pageSize"`
Data []Webhook `json:"data"`
Timestamp time.Time `json:"timestamp"`
}