37 lines
844 B
Go
37 lines
844 B
Go
|
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
|
||
|
}
|