Filter for foil and reserved list.

This commit is contained in:
Florian Baumann 2023-04-27 08:05:29 +02:00
parent 7b6addcb05
commit af4af39adc
3 changed files with 21 additions and 9 deletions

View File

@ -17,6 +17,8 @@ func init() {
cardCmd.Flags().StringVarP(&oracle, "oracle", "o", "", "Contains string in card text") cardCmd.Flags().StringVarP(&oracle, "oracle", "o", "", "Contains string in card text")
cardCmd.Flags().StringVarP(&cardType, "type", "t", "", "Contains string in card type line") cardCmd.Flags().StringVarP(&cardType, "type", "t", "", "Contains string in card type line")
cardCmd.Flags().BoolVarP(&detail, "detail", "d", false, "Show details for cards (url)") cardCmd.Flags().BoolVarP(&detail, "detail", "d", false, "Show details for cards (url)")
cardCmd.Flags().BoolVarP(&reserved, "reserved", "w", false, "If card is on reserved list")
cardCmd.Flags().BoolVarP(&foil, "foil", "f", false, "If card is foil list")
rootCmd.AddCommand(cardCmd) rootCmd.AddCommand(cardCmd)
} }
@ -30,8 +32,8 @@ otherwise you'll get a list of cards as a search result.`,
SilenceErrors: true, SilenceErrors: true,
RunE: func(cmd *cobra.Command, cards []string) error { RunE: func(cmd *cobra.Command, cards []string) error {
if len(cards) == 0 { if len(cards) == 0 {
card_list := Cards(rarity, set, sortby, name, oracle, cardType) cardList := Cards(rarity, set, sortby, name, oracle, cardType, reserved, foil)
showCardList(card_list, detail) showCardList(cardList, detail)
} else { } else {
ShowCard(cards) ShowCard(cards)
} }
@ -58,7 +60,7 @@ func ShowCard(cardids []string) {
} }
} }
func Cards(rarity, set, sortby, name, oracle, cardType string) []Card { func Cards(rarity, set, sortby, name, oracle, cardType string, reserved, foil bool) []Card {
client := storageConnect() client := storageConnect()
coll := &Collection{client.Database("serra").Collection("cards")} coll := &Collection{client.Database("serra").Collection("cards")}
defer storageDisconnect(client) defer storageDisconnect(client)
@ -108,7 +110,16 @@ func Cards(rarity, set, sortby, name, oracle, cardType string) []Card {
filter = append(filter, bson.E{"typeline", bson.D{{"$regex", ".*" + cardType + ".*"}, {"$options", "i"}}}) filter = append(filter, bson.E{"typeline", bson.D{{"$regex", ".*" + cardType + ".*"}, {"$options", "i"}}})
} }
if reserved {
filter = append(filter, bson.E{"reserved", true})
}
if foil {
filter = append(filter, bson.E{"serra_count_foil", bson.D{{"$gt", 0}}})
}
cards, _ := coll.storageFind(filter, sortStage) cards, _ := coll.storageFind(filter, sortStage)
fmt.Println(filter)
// This is needed because collectornumbers are strings (ie. "23a") but still we // This is needed because collectornumbers are strings (ie. "23a") but still we
// want it to be sorted numerically ... 1,2,3,10,11,100. // want it to be sorted numerically ... 1,2,3,10,11,100.

View File

@ -9,22 +9,23 @@ import (
var ( var (
Version = "unknown" Version = "unknown"
address string
cardType string
count int64 count int64
detail bool detail bool
limit float64 foil bool
interactive bool interactive bool
limit float64
name string name string
oracle string oracle string
port uint64
rarity string rarity string
reserved bool
set string set string
sinceBeginning bool sinceBeginning bool
sinceLastUpdate bool sinceLastUpdate bool
sortby string sortby string
cardType string
unique bool unique bool
foil bool
address string
port uint64
) )
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{

View File

@ -47,7 +47,7 @@ func startWeb() error {
func landingPage(c *gin.Context) { func landingPage(c *gin.Context) {
var query Query var query Query
if c.ShouldBind(&query) == nil { if c.ShouldBind(&query) == nil {
cards := Cards("", query.Set, query.Sort, query.Name, "", "") cards := Cards("", query.Set, query.Sort, query.Name, "", "", false, false)
sets := Sets("release") sets := Sets("release")
c.HTML(http.StatusOK, "index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Serra", "title": "Serra",