From 1de70092df060fa58f432f2c35f2ebdc94cae155 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 23 Oct 2019 17:35:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0mtwmapi.RetailListAll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/mtwmapi/retail.go | 15 +++++++++++ platformapi/mtwmapi/retail_test.go | 41 ++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/platformapi/mtwmapi/retail.go b/platformapi/mtwmapi/retail.go index b44f5c2b..622f5059 100644 --- a/platformapi/mtwmapi/retail.go +++ b/platformapi/mtwmapi/retail.go @@ -193,6 +193,21 @@ func (a *API) RetailList(poiCode string, offset, limit int) (foodList []*AppFood return foodList, err } +func (a *API) RetailListAll(poiCode string) (foodList []*AppFood, err error) { + offset := 0 + for { + batchList, err2 := a.RetailList(poiCode, offset, GeneralMaxLimit) + if err = err2; err == nil { + foodList = append(foodList, batchList...) + } + if len(batchList) < GeneralMaxLimit { + break + } + offset += GeneralMaxLimit + } + return foodList, err +} + func handleRetailBatchResult(result interface{}) (failedFoodList []*AppFoodResult, err error) { if msg, ok := result.(string); ok && msg != "" { err = utils.UnmarshalUseNumber([]byte(msg), &failedFoodList) diff --git a/platformapi/mtwmapi/retail_test.go b/platformapi/mtwmapi/retail_test.go index 709a4b0d..08f8b1ac 100644 --- a/platformapi/mtwmapi/retail_test.go +++ b/platformapi/mtwmapi/retail_test.go @@ -7,7 +7,7 @@ import ( ) func TestRetailCatList(t *testing.T) { - result, err := api.RetailCatList(testPoiCode) + result, err := api.RetailCatList("7875210") if err != nil { t.Fatal(err) } @@ -25,22 +25,22 @@ func TestRetailCatUpdate(t *testing.T) { } func TestRetailCatDelete(t *testing.T) { var err error - err = api.RetailCatDelete(testPoiCode, "", utils.GetUpperUUID()) + err = api.RetailCatDelete(testPoiCode, "" /*utils.GetUpperUUID()*/, "小月饼111") if err == nil { t.Fatal("should return error that can not find such cat") } - uniqueCatName := "一二三四五六七八九十" - // uniqueCatName := "1234567890" //fmt.Sprintf("CAT%d", time.Now().Unix()) - err = api.RetailCatUpdate(testPoiCode, uniqueCatName, &Param4UpdateCat{ - Sequence: 15, - }) - if err != nil { - t.Fatal(err) - } - err = api.RetailCatDelete(testPoiCode, "", uniqueCatName) - if err != nil { - t.Fatal(err) - } + // uniqueCatName := "一二三四五六七八九十" + // // uniqueCatName := "1234567890" //fmt.Sprintf("CAT%d", time.Now().Unix()) + // err = api.RetailCatUpdate(testPoiCode, uniqueCatName, &Param4UpdateCat{ + // Sequence: 15, + // }) + // if err != nil { + // t.Fatal(err) + // } + // err = api.RetailCatDelete(testPoiCode, "", uniqueCatName) + // if err != nil { + // t.Fatal(err) + // } } func TestRetailList(t *testing.T) { @@ -52,6 +52,19 @@ func TestRetailList(t *testing.T) { t.Fatal("should have items") } t.Log(utils.Format4Output(result, false)) + t.Log(len(result)) +} + +func TestRetailListAll(t *testing.T) { + result, err := api.RetailListAll(testPoiCode) + if err != nil { + t.Fatal(err) + } + if len(result) == 0 { + t.Fatal("should have items") + } + t.Log(utils.Format4Output(result, false)) + t.Log(len(result)) } func TestRetailGet(t *testing.T) {