TheMathemagicians/sevenkeys/cli/stashui.go

95 lines
2.2 KiB
Go

package cli
import (
"database/sql"
"fmt"
"sevenkeys/database"
"sevenkeys/logic"
)
var (
selectedCardPrintingId string
selectedCardPrintingSearchLine string
storageBoxLabel string
source string
cardCondition string
searchCriteria logic.SearchCriteria = logic.SearchCriteria{
SetCode: "",
Foil: logic.Either,
Promo: logic.Either,
Language: "",
}
shouldRefreshSearch bool = true
searchOptions logic.SearchOptions
)
func getSearchCriteria() {
searchCriteria.SetCode = GetStringResponse("Set code:")
searchCriteria.Foil = GetTriadicResponse("Foil (y/n/E):")
searchCriteria.Promo = GetTriadicResponse("Promo (y/n/E):")
searchCriteria.Language = GetStringResponse("Language:")
shouldRefreshSearch = true
}
func getSearchOptions(db *sql.DB) {
if shouldRefreshSearch {
fmt.Println("LOADING")
options, err := logic.GetAllSearchOptions(db, searchCriteria)
logic.Check(err)
searchOptions = options
shouldRefreshSearch = false
fmt.Println("READY")
fmt.Println("RUN")
}
}
func getInfoDisplay(info string) string {
if info == "" {
return "[EMPTY]"
}
return info
}
func ShowStorageInfo() {
storageBoxDisplay := getInfoDisplay(storageBoxLabel)
sourceDisplay := getInfoDisplay(source)
conditionDisplay := getInfoDisplay(cardCondition)
fmt.Println("Storage location:", storageBoxDisplay, "|", "Source:", sourceDisplay, "|", "Condition:", conditionDisplay)
if selectedCardPrintingId != "" {
fmt.Println("Selected card:", selectedCardPrintingSearchLine)
}
}
func GetStorageOptions() {
storageBoxLabel = GetStringResponse("Storage box label:")
source = GetStringResponse("Card source:")
cardCondition = GetStringResponse("Card condition:")
}
func InsertSelectedCard(db *sql.DB) {
if selectedCardPrintingId == "" {
fmt.Println("No card selected, please [search] for a card printing.")
return
}
if storageBoxLabel == "" || cardCondition == "" {
GetStorageOptions()
}
storageLocation := database.CardStorageLocation{
CardPrintingId: selectedCardPrintingId,
StorageBox: storageBoxLabel,
Source: source,
CardCondition: cardCondition,
}
err := logic.StoreCard(db, storageLocation)
logic.Check(err)
fmt.Println("Inserted card")
}