Merge branch 'kiotviet' into develop
This commit is contained in:
		
						commit
						0f678ff28a
					
				| 
						 | 
					@ -3,6 +3,7 @@ package kiotviet
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	apiPathListBranches       = "/branches"
 | 
						apiPathListBranches       = "/branches"
 | 
				
			||||||
	apiPathListProductOnHands = "/productOnHands"
 | 
						apiPathListProductOnHands = "/productOnHands"
 | 
				
			||||||
 | 
						apiPathListWebhook        = "/webhooks"
 | 
				
			||||||
	apiPathRegisterWebhook    = "/webhooks"
 | 
						apiPathRegisterWebhook    = "/webhooks"
 | 
				
			||||||
	apiPathUnregisterWebhook  = "/webhooks/%d" // %s -> webhook id
 | 
						apiPathUnregisterWebhook  = "/webhooks/%d" // %s -> webhook id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -122,6 +122,34 @@ func (c *Client) GetBranches(req ListBranchesReq) (*ListBranchesRes, error) {
 | 
				
			||||||
	return &data, nil
 | 
						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) {
 | 
					func (c *Client) RegisterWebhook(req RegisterWebhookReq) (*RegisterWebhookRes, error) {
 | 
				
			||||||
	apiURL := c.getURL(apiPathRegisterWebhook)
 | 
						apiURL := c.getURL(apiPathRegisterWebhook)
 | 
				
			||||||
	natsPayload := model.CommunicationRequestHttp{
 | 
						natsPayload := model.CommunicationRequestHttp{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,6 +23,9 @@ type ListBranchesReq struct {
 | 
				
			||||||
	IncludeRemoveIDs string `json:"includeRemoveIds,omitempty"` // true/ false
 | 
						IncludeRemoveIDs string `json:"includeRemoveIds,omitempty"` // true/ false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ListWebhookReq struct {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type WebhookReq struct {
 | 
					type WebhookReq struct {
 | 
				
			||||||
	Type     string `json:"Type"`
 | 
						Type     string `json:"Type"`
 | 
				
			||||||
	Url      string `json:"Url"`
 | 
						Url      string `json:"Url"`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,3 +67,19 @@ type RError struct {
 | 
				
			||||||
	ErrorCode string `json:"errorCode"`
 | 
						ErrorCode string `json:"errorCode"`
 | 
				
			||||||
	Message   string `json:"message"`
 | 
						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"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue