From f90f747690eb9016108a5202592d47b2eb2f6974 Mon Sep 17 00:00:00 2001 From: Nagy Date: Mon, 24 Aug 2020 10:51:28 +0300 Subject: [PATCH] Added save assignment --- pkg/api/sales/assignmentModels.go | 11 +++++++++ pkg/api/sales/assignmentRequests.go | 26 ++++++++++++++++++++ pkg/api/sales/assignmentRequests_test.go | 31 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 pkg/api/sales/assignmentModels.go create mode 100644 pkg/api/sales/assignmentRequests.go create mode 100644 pkg/api/sales/assignmentRequests_test.go diff --git a/pkg/api/sales/assignmentModels.go b/pkg/api/sales/assignmentModels.go new file mode 100644 index 0000000..4aa5a40 --- /dev/null +++ b/pkg/api/sales/assignmentModels.go @@ -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"` +} diff --git a/pkg/api/sales/assignmentRequests.go b/pkg/api/sales/assignmentRequests.go new file mode 100644 index 0000000..b7a0fa0 --- /dev/null +++ b/pkg/api/sales/assignmentRequests.go @@ -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 +} diff --git a/pkg/api/sales/assignmentRequests_test.go b/pkg/api/sales/assignmentRequests_test.go new file mode 100644 index 0000000..4658f94 --- /dev/null +++ b/pkg/api/sales/assignmentRequests_test.go @@ -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) +}