TheMathemagicians/sevenkeys/logic/search.go

37 lines
844 B
Go
Raw Normal View History

2024-05-30 14:19:31 +00:00
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
}