diff --git a/services/area.go b/services/area.go index a3ca0a7..0e85a8c 100644 --- a/services/area.go +++ b/services/area.go @@ -1,49 +1,50 @@ package services import ( - "apple-store-helper/model" - "github.com/thoas/go-funk" - "github.com/tidwall/gjson" + "apple-store-helper/model" + "github.com/thoas/go-funk" + "github.com/tidwall/gjson" ) var Area = areaService{} + type areaService struct{} func (s *areaService) ProductsByCode(code string) []model.Product { - - area := funk.Find(model.Areas, func(x model.Area) bool { - return x.Code == code - }).(model.Area) - - var products []model.Product - - for _, result := range gjson.Parse(area.ProductsJson).Array() { - products = append(products, model.Product{ - Title: result.Get("familyType").String() + result.Get("seoUrlToken").String(), - Type: result.Get("familyType").String(), - Code: result.Get("partNumber").String(), - }) - } - - return products + + area := funk.Find(model.Areas, func(x model.Area) bool { + return x.Code == code + }).(model.Area) + + var products []model.Product + + for _, result := range gjson.Parse(area.ProductsJson).Array() { + products = append(products, model.Product{ + Title: result.Get("familyType").String() + "-" + result.Get("seoUrlToken").String(), + Type: result.Get("familyType").String(), + Code: result.Get("partNumber").String(), + }) + } + + return products } func (s *areaService) ForOptions() []string { - return funk.Get(model.Areas, "Title").([]string) + return funk.Get(model.Areas, "Title").([]string) } func (s *areaService) Title2Code(title string) string { - area := funk.Find(model.Areas, func(x model.Area) bool { - return x.Title == title - }).(model.Area) - - return area.Code + area := funk.Find(model.Areas, func(x model.Area) bool { + return x.Title == title + }).(model.Area) + + return area.Code } func (s *areaService) GetArea(title string) model.Area { - area := funk.Find(model.Areas, func(x model.Area) bool { - return x.Title == title - }).(model.Area) - - return area -} \ No newline at end of file + area := funk.Find(model.Areas, func(x model.Area) bool { + return x.Title == title + }).(model.Area) + + return area +} diff --git a/services/store.go b/services/store.go index 4e25fc5..cb3dc18 100644 --- a/services/store.go +++ b/services/store.go @@ -27,11 +27,11 @@ func (s *storeService) ByAreaCode(areaCode string) []model.Store { if len(errs) != 0 { panic(errs[0]) } - + for _, store := range gjson.Get(bd, "stores").Array() { s.stores[areaCode] = append(s.stores[areaCode], model.Store{ StoreNumber: store.Get("storeNumber").String(), - CityStoreName: store.Get("city").String() + store.Get("storeName").String(), + CityStoreName: store.Get("city").String() + "-" + store.Get("storeName").String(), }) } @@ -45,7 +45,7 @@ func (s *storeService) ByAreaTitleForOptions(areaTitle string) []string { func (s *storeService) GetStore(areaTitle string, storeTitle string) model.Store { code := Area.Title2Code(areaTitle) - + return funk.Find(s.stores[code], func(x model.Store) bool { return x.CityStoreName == storeTitle }).(model.Store)