Get list of available search options
This commit is contained in:
parent
dd70490290
commit
5e2d8e7cff
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue