TheMathemagicians/sevenkeys/cli/stashui.go

95 lines
2.2 KiB
Go
Raw Normal View History

2024-06-10 15:34:16 +00:00
package cli
import (
2024-06-11 09:43:30 +00:00
"database/sql"
2024-06-10 15:34:16 +00:00
"fmt"
2024-06-11 09:43:30 +00:00
"sevenkeys/database"
2024-06-10 15:34:16 +00:00
"sevenkeys/logic"
)
var (
selectedCardPrintingId string
selectedCardPrintingSearchLine string
2024-06-11 09:43:30 +00:00
storageBoxLabel string
source string
cardCondition string
2024-06-11 09:57:02 +00:00
2024-06-11 15:28:17 +00:00
searchCriteria logic.SearchCriteria = logic.SearchCriteria{
SetCode: "",
Foil: logic.Either,
Promo: logic.Either,
Language: "",
2024-06-11 15:28:17 +00:00
}
shouldRefreshSearch bool = true
searchOptions logic.SearchOptions
2024-06-10 15:34:16 +00:00
)
2024-06-11 16:02:02 +00:00
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
2024-06-11 16:02:02 +00:00
}
2024-06-11 09:57:02 +00:00
func getSearchOptions(db *sql.DB) {
if shouldRefreshSearch {
2024-06-11 09:57:02 +00:00
fmt.Println("LOADING")
2024-06-11 15:28:17 +00:00
options, err := logic.GetAllSearchOptions(db, searchCriteria)
2024-06-11 09:57:02 +00:00
logic.Check(err)
searchOptions = options
shouldRefreshSearch = false
2024-06-11 09:57:02 +00:00
fmt.Println("READY")
fmt.Println("RUN")
}
}
func getInfoDisplay(info string) string {
if info == "" {
return "[EMPTY]"
}
return info
}
2024-06-11 09:43:30 +00:00
func ShowStorageInfo() {
2024-06-11 09:57:02 +00:00
storageBoxDisplay := getInfoDisplay(storageBoxLabel)
sourceDisplay := getInfoDisplay(source)
conditionDisplay := getInfoDisplay(cardCondition)
fmt.Println("Storage location:", storageBoxDisplay, "|", "Source:", sourceDisplay, "|", "Condition:", conditionDisplay)
2024-06-11 09:43:30 +00:00
2024-06-10 15:34:16 +00:00
if selectedCardPrintingId != "" {
fmt.Println("Selected card:", selectedCardPrintingSearchLine)
}
}
2024-06-11 09:43:30 +00:00
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
}
2024-06-11 15:28:17 +00:00
if storageBoxLabel == "" || cardCondition == "" {
2024-06-11 09:43:30 +00:00
GetStorageOptions()
}
storageLocation := database.CardStorageLocation{
CardPrintingId: selectedCardPrintingId,
StorageBox: storageBoxLabel,
Source: source,
2024-06-11 09:57:11 +00:00
CardCondition: cardCondition,
2024-06-11 09:43:30 +00:00
}
2024-06-11 09:57:02 +00:00
err := logic.StoreCard(db, storageLocation)
logic.Check(err)
fmt.Println("Inserted card")
2024-06-11 09:43:30 +00:00
}