Get list of available search options

This commit is contained in:
The Magician 2024-05-30 15:19:31 +01:00
parent dd70490290
commit 5e2d8e7cff
1 changed files with 36 additions and 0 deletions

36
sevenkeys/logic/search.go Normal file
View File

@ -0,0 +1,36 @@
package logic
import (
"database/sql"
"fmt"
"sevenkeys/database"
)
// The SearchOptions type is a map of `string`s (which can be searched using fzf)
// to `int`s (which represent a primary key in the CardPrintings table)
type SearchOptions map[string]int
func GetAllSearchOptions(db *sql.DB) (SearchOptions, error) {
var searchOptions SearchOptions = make(map[string]int)
cardPrintings, err := database.GetAllCardPrintings(db)
if err != nil {
return searchOptions, err
}
for _, printing := range cardPrintings {
searchString := fmt.Sprintf("%s (%s %s) [%s]", printing.Name, printing.SetCode, printing.CollectorNumber, printing.Language)
if printing.IsFoil {
searchString += " FOIL"
}
if printing.IsPromo {
searchString += " PROMO"
}
searchOptions[searchString] = printing.Id
}
return searchOptions, err
}