Skip to content

Commit

Permalink
Merge pull request #42 from erply/feature/add-saveAssignment
Browse files Browse the repository at this point in the history
Added save assignment
  • Loading branch information
Dysar authored Aug 24, 2020
2 parents ff1902f + f90f747 commit c41af84
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/api/sales/assignmentModels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sales

import common2 "github.com/erply/api-go-wrapper/pkg/api/common"

//saveAssignmentResponse ...
type saveAssignment struct {
Status common2.Status `json:"status"`
Records []struct {
AssignmentID int64 `json:"assignmentID"`
} `json:"records"`
}
26 changes: 26 additions & 0 deletions pkg/api/sales/assignmentRequests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sales

import (
"context"
"encoding/json"
"github.com/erply/api-go-wrapper/internal/common"
erro "github.com/erply/api-go-wrapper/internal/errors"
)

//GetVatRatesByVatRateID ...
func (cli *Client) SaveAssignment(ctx context.Context, filters map[string]string) (int64, error) {
resp, err := cli.SendRequest(ctx, "saveAssignment", filters)
if err != nil {
return 0, err
}
res := &saveAssignment{}
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
return 0, erro.NewFromError("unmarshaling saveAssignment failed", err)
}

if !common.IsJSONResponseOK(&res.Status) {
return 0, erro.NewFromResponseStatus(&res.Status)
}

return res.Records[0].AssignmentID, nil
}
31 changes: 31 additions & 0 deletions pkg/api/sales/assignmentRequests_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package sales

import (
"context"
"github.com/erply/api-go-wrapper/internal/common"
"testing"
)

//works
func TestSaveAssignment(t *testing.T) {
const (
//fill your data here
sk = ""
cc = ""
vatRateID = ""
)
var (
ctx = context.Background()
)
cli := NewClient(common.NewClient(sk, cc, "", nil, nil))

resp, err := cli.SaveAssignment(ctx, map[string]string{
"customerComment1": "Test",
})

if err != nil {
t.Error(err)
return
}
t.Log(resp)
}

0 comments on commit c41af84

Please sign in to comment.