From c2f88b459d6c9fa7f67e01a2ece9fcb0123a1f13 Mon Sep 17 00:00:00 2001 From: Mysh! Date: Mon, 30 Mar 2020 21:55:38 +0800 Subject: [PATCH] [upd] Replace two maps with one --- API/importBatchAdvanced/importBatchAdvanced.go | 9 ++++----- responses/importBatchAdvanced.go | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/API/importBatchAdvanced/importBatchAdvanced.go b/API/importBatchAdvanced/importBatchAdvanced.go index ef2f2bb..b3a3162 100644 --- a/API/importBatchAdvanced/importBatchAdvanced.go +++ b/API/importBatchAdvanced/importBatchAdvanced.go @@ -2,6 +2,7 @@ package importBatchAdvanced import ( "encoding/json" + "errors" "github.com/hugmouse/gocapitalist/internal" "github.com/hugmouse/gocapitalist/requests" "github.com/hugmouse/gocapitalist/responses" @@ -15,8 +16,7 @@ type ImportBatchAdvanced struct { // https://capitalist.net/developers/api/page/import_batch_advanced func (b *ImportBatchAdvanced) Import(request requests.ImportBatchAdvanced) (*responses.ImportBatchAdvanced, error) { data, errResponse := new(responses.ImportBatchAdvanced), new(responses.ErrorResponse) - data.Data.CSVErrorsFull = make(map[int]string) - data.Data.CSVErrorsID = make(map[int]string) + data.Data.CSVErrorsWithID = make(map[string]error) httpParams, logParams, err := request.Params() if err != nil { @@ -61,10 +61,9 @@ func (b *ImportBatchAdvanced) Import(request requests.ImportBatchAdvanced) (*res if len(data.Data.Errors) > 0 { s := strings.Split(httpParams["batch"], "\n") - for x, y := range data.Data.Errors { + for _, y := range data.Data.Errors { moreInfoFromError := strings.Split(s[y.Line-1], ";") - data.Data.CSVErrorsFull[x] = s[y.Line-1] - data.Data.CSVErrorsID[x] = moreInfoFromError[4] // payment number from your system + data.Data.CSVErrorsWithID[moreInfoFromError[4]] = errors.New(s[y.Line-1]) } } diff --git a/responses/importBatchAdvanced.go b/responses/importBatchAdvanced.go index 7a6452b..fe9d92f 100644 --- a/responses/importBatchAdvanced.go +++ b/responses/importBatchAdvanced.go @@ -33,6 +33,5 @@ type DataBatch struct { Fee Fee `json:"fee"` NettoSummary NettoSummary `json:"nettoSummary"` Errors []Errors `json:"errors,omitempty"` - CSVErrorsFull map[int]string - CSVErrorsID map[int]string + CSVErrorsWithID map[string]error }