single card view

This commit is contained in:
Florian Baumann 2022-01-07 13:08:52 +01:00
parent b15db42f55
commit a4fd256c2e
2 changed files with 19 additions and 1 deletions

View File

@ -4,8 +4,10 @@ import (
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
"time"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
) )
func modify_count_of_card(coll *Collection, c *Card, amount int64) error { func modify_count_of_card(coll *Collection, c *Card, amount int64) error {
@ -46,3 +48,19 @@ func find_card_by_setcollectornumber(coll *Collection, setcode string, collector
return &stored_cards[0], nil return &stored_cards[0], nil
} }
func stringToTime(s primitive.DateTime) string {
return time.UnixMilli(int64(s)).Format("2006-01-02")
}
func show_card_details(card *Card) error {
fmt.Printf("* %dx %s%s%s (%s/%s)\n", card.SerraCount, Purple, card.Name, Reset, card.Set, card.CollectorNumber)
fmt.Printf(" Added: %s\n", stringToTime(card.SerraCreated))
fmt.Printf(" Current Value: %s%.2f EUR%s\n", Yellow, card.Prices.Eur, Reset)
fmt.Printf(" History:\n")
for _, e := range card.SerraPrices {
fmt.Printf(" * %s %.2f EUR\n", stringToTime(e.Date), e.Value)
}
return nil
}

View File

@ -105,7 +105,7 @@ func ShowCard(cardids []string) {
cards, _ := coll.storage_find(bson.D{{"set", strings.Split(v, "/")[0]}, {"collectornumber", strings.Split(v, "/")[1]}}, bson.D{{"name", 1}}) cards, _ := coll.storage_find(bson.D{{"set", strings.Split(v, "/")[0]}, {"collectornumber", strings.Split(v, "/")[1]}}, bson.D{{"name", 1}})
for _, card := range cards { for _, card := range cards {
LogMessage(fmt.Sprintf("* %dx %s%s%s (%s/%d) %s%.2f EUR%s", card.SerraCount, Purple, card.Name, Reset, card.Set, card.CollectorNumber, Yellow, card.Prices.Eur, Reset), "normal") show_card_details(&card)
} }
} }
} }