Skip to content

Commit

Permalink
[upd] Replace two maps with one
Browse files Browse the repository at this point in the history
  • Loading branch information
hugmouse committed Mar 30, 2020
1 parent 793f4a5 commit c2f88b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 4 additions & 5 deletions API/importBatchAdvanced/importBatchAdvanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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])
}
}

Expand Down
3 changes: 1 addition & 2 deletions responses/importBatchAdvanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c2f88b4

Please sign in to comment.