Fix issue printing correct currency values in set and card
This commit is contained in:
parent
884fbdf96d
commit
b4f0067b4a
@ -80,7 +80,7 @@ func Cards(rarity, set, sortby, name, oracle, cardType string, reserved, foil bo
|
|||||||
var sortStage bson.D
|
var sortStage bson.D
|
||||||
switch sortby {
|
switch sortby {
|
||||||
case "value":
|
case "value":
|
||||||
if getCurrency() == "EUR" {
|
if getCurrency() == EUR {
|
||||||
sortStage = bson.D{{"prices.eur", 1}}
|
sortStage = bson.D{{"prices.eur", 1}}
|
||||||
} else {
|
} else {
|
||||||
sortStage = bson.D{{"prices.usd", 1}}
|
sortStage = bson.D{{"prices.usd", 1}}
|
||||||
|
|||||||
@ -5,6 +5,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const EUR = "€"
|
||||||
|
const USD = "$"
|
||||||
|
|
||||||
func getMongoDBURI() string {
|
func getMongoDBURI() string {
|
||||||
uri := os.Getenv("MONGODB_URI")
|
uri := os.Getenv("MONGODB_URI")
|
||||||
if uri == "" {
|
if uri == "" {
|
||||||
@ -19,13 +22,11 @@ func getMongoDBURI() string {
|
|||||||
func getCurrency() string {
|
func getCurrency() string {
|
||||||
switch os.Getenv("SERRA_CURRENCY") {
|
switch os.Getenv("SERRA_CURRENCY") {
|
||||||
case "EUR":
|
case "EUR":
|
||||||
return "€"
|
return EUR
|
||||||
case "USD":
|
case "USD":
|
||||||
|
return USD
|
||||||
|
default:
|
||||||
|
LogMessage("Warning: You did not configure SERRA_CURRENCY. Assuming \"USD\"", "yellow")
|
||||||
return "$"
|
return "$"
|
||||||
}
|
}
|
||||||
|
|
||||||
// default
|
|
||||||
LogMessage("Warning: You did not configure SERRA_CURRENCY. Assuming \"USD\"", "yellow")
|
|
||||||
|
|
||||||
return "USD"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ func Gains(limit float64, sort int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currencyField := "$serra_prices.usd"
|
currencyField := "$serra_prices.usd"
|
||||||
if getCurrency() == "EUR" {
|
if getCurrency() == EUR {
|
||||||
currencyField = "$serra_prices.eur"
|
currencyField = "$serra_prices.eur"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -167,14 +167,16 @@ func showPriceHistory(prices []PriceEntry, prefix string, total bool) {
|
|||||||
|
|
||||||
var value float64
|
var value float64
|
||||||
if total {
|
if total {
|
||||||
value = e.Usd + e.UsdFoil + e.UsdEtched
|
if getCurrency() == EUR {
|
||||||
if getCurrency() == "EUR" {
|
|
||||||
value = e.Eur + e.EurFoil
|
value = e.Eur + e.EurFoil
|
||||||
|
} else {
|
||||||
|
value = e.Usd + e.UsdFoil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = e.Usd
|
if getCurrency() == EUR {
|
||||||
if getCurrency() == "EUR" {
|
|
||||||
value = e.Eur
|
value = e.Eur
|
||||||
|
} else {
|
||||||
|
value = e.Usd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -119,7 +119,7 @@ type Card struct {
|
|||||||
|
|
||||||
// Getter for currency specific value
|
// Getter for currency specific value
|
||||||
func (c Card) getValue(foil bool) float64 {
|
func (c Card) getValue(foil bool) float64 {
|
||||||
if getCurrency() == "EUR" {
|
if getCurrency() == EUR {
|
||||||
if foil {
|
if foil {
|
||||||
return c.Prices.EurFoil
|
return c.Prices.EurFoil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,7 +92,7 @@ func ShowSet(setname string) error {
|
|||||||
|
|
||||||
// fetch all cards in set ordered by currently used currency
|
// fetch all cards in set ordered by currently used currency
|
||||||
cardSortCurrency := bson.D{{"prices.usd", -1}}
|
cardSortCurrency := bson.D{{"prices.usd", -1}}
|
||||||
if getCurrency() == "EUR" {
|
if getCurrency() == EUR {
|
||||||
cardSortCurrency = bson.D{{"prices.eur", -1}}
|
cardSortCurrency = bson.D{{"prices.eur", -1}}
|
||||||
}
|
}
|
||||||
cards, err := coll.storageFind(bson.D{{"set", setname}}, cardSortCurrency, 0, 0)
|
cards, err := coll.storageFind(bson.D{{"set", setname}}, cardSortCurrency, 0, 0)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user