diff --git a/cardsinfo/format.go b/cardsinfo/format.go index 7344c7b..ba78791 100644 --- a/cardsinfo/format.go +++ b/cardsinfo/format.go @@ -8,8 +8,15 @@ func FormatCardPrices(name string, prices []CardPrice) string { message := fmt.Sprintf("Оригинальное название: %v\n", name) message += fmt.Sprintf("Результатов: %v\n", len(prices)) for i, v := range prices { - message += fmt.Sprintf("%v. %v: $%v\n", i+1, v.Edition, v.Price) + message += fmt.Sprintf("%v. %v\nRegular: %v\nFoil: %v\n", i+1, v.Edition, formatPrice(v.Price), formatPrice(v.PriceFoil)) message += fmt.Sprintf("%v\n", v.Link) } return message } + +func formatPrice(price string) string { + if price == "" { + return "-" + } + return fmt.Sprintf("$%v", price) +} diff --git a/cardsinfo/prices.go b/cardsinfo/prices.go index 1f7984c..02e5d8b 100644 --- a/cardsinfo/prices.go +++ b/cardsinfo/prices.go @@ -20,15 +20,14 @@ func GetPrices(name string) ([]CardPrice, error) { var prices []CardPrice for _, card := range resp.Cards { foilString := "" - price := card.Prices.USD - if card.Foil { - foilString = "(Foil)" - price = card.Prices.USDFoil - } edition := card.SetName + foilString + if card.Prices.USD == "" && card.Prices.USDFoil == "" { + continue + } cardPrice := CardPrice { Edition: edition, - Price: price, + Price: card.Prices.USD, + PriceFoil: card.Prices.USDFoil, Name: card.Name, Link: card.PurchaseURIs.TCGPlayer, } diff --git a/cardsinfo/structs.go b/cardsinfo/structs.go index 3fb3653..628a203 100644 --- a/cardsinfo/structs.go +++ b/cardsinfo/structs.go @@ -7,6 +7,7 @@ import ( type CardPrice struct { Name string Price string + PriceFoil string Link string Edition string } diff --git a/tests/price_format_test.go b/tests/price_format_test.go index 01097ab..28f0332 100644 --- a/tests/price_format_test.go +++ b/tests/price_format_test.go @@ -10,7 +10,7 @@ func TestFormat(t *testing.T) { data := []cardsinfo.CardPrice{ { Name: "Green lotus", - Price: "22.8", + PriceFoil: "22.8", Link: "scg.com/1", Edition: "alpha", }, @@ -22,6 +22,6 @@ func TestFormat(t *testing.T) { }, } res := cardsinfo.FormatCardPrices("Black Lotus", data) - ans := "Оригинальное название: Black Lotus\nРезультатов: 2\n1. alpha: $22.8\nscg.com/1\n2. gamma: $3.22\nscg.com/2\n" + ans := "Оригинальное название: Black Lotus\nРезультатов: 2\n1. alpha\nRegular: -\nFoil: $22.8\nscg.com/1\n2. gamma\nRegular: $3.22\nFoil: -\nscg.com/2\n" assert.Equal(t, res, ans) }