Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hteen committed Sep 19, 2021
1 parent 1df9e77 commit 44b93bf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
63 changes: 32 additions & 31 deletions services/area.go
Original file line number Diff line number Diff line change
@@ -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
}
area := funk.Find(model.Areas, func(x model.Area) bool {
return x.Title == title
}).(model.Area)

return area
}
6 changes: 3 additions & 3 deletions services/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}

Expand All @@ -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)
Expand Down

0 comments on commit 44b93bf

Please sign in to comment.