Show the number of times the selected card was inserted
This commit is contained in:
parent
7031bc7b07
commit
845204320b
|
@ -8,12 +8,23 @@ import (
|
||||||
"sevenkeys/logic"
|
"sevenkeys/logic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var output string
|
||||||
|
|
||||||
|
func showOutput() {
|
||||||
|
if output != "" {
|
||||||
|
fmt.Println(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func MainCliLoop(db *sql.DB) {
|
func MainCliLoop(db *sql.DB) {
|
||||||
var command string
|
var command string
|
||||||
|
|
||||||
for {
|
for {
|
||||||
ShowSplashScreen()
|
ShowSplashScreen()
|
||||||
ShowStorageInfo()
|
showStorageInfo()
|
||||||
|
showSearchCriteria()
|
||||||
|
showSelectedCard()
|
||||||
|
showCopiesInserted()
|
||||||
|
|
||||||
command = GetStringResponse("SEVENKEYS $")
|
command = GetStringResponse("SEVENKEYS $")
|
||||||
|
|
||||||
|
@ -21,23 +32,31 @@ func MainCliLoop(db *sql.DB) {
|
||||||
case "quit":
|
case "quit":
|
||||||
return
|
return
|
||||||
case "storage":
|
case "storage":
|
||||||
GetStorageOptions()
|
getStorageOptions()
|
||||||
break
|
break
|
||||||
case "criteria":
|
case "criteria":
|
||||||
getSearchCriteria()
|
getSearchCriteria()
|
||||||
break
|
break
|
||||||
case "search":
|
case "search":
|
||||||
getSearchOptions(db)
|
getSearchOptions(db)
|
||||||
|
|
||||||
|
var previousCardPrintingId = cardStorageLocation.CardPrintingId
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
selectedCardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
|
cardStorageLocation.CardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
|
||||||
var exitError *exec.ExitError
|
var exitError *exec.ExitError
|
||||||
if errors.As(err, &exitError) {
|
if errors.As(err, &exitError) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
logic.Check(err)
|
logic.Check(err)
|
||||||
|
|
||||||
|
output = ""
|
||||||
|
if cardStorageLocation.CardPrintingId != previousCardPrintingId {
|
||||||
|
copiesInserted = 0
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case "insert":
|
case "insert":
|
||||||
InsertSelectedCard(db)
|
insertSelectedCard(db)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
fmt.Println("Unrecognized command:", command)
|
fmt.Println("Unrecognized command:", command)
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"sevenkeys/logic"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
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 getTriadicDisplay(triadic logic.Triadic) string {
|
||||||
|
if triadic == logic.True {
|
||||||
|
return "True"
|
||||||
|
}
|
||||||
|
|
||||||
|
if triadic == logic.False {
|
||||||
|
return "False"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Either"
|
||||||
|
}
|
||||||
|
|
||||||
|
func showSearchCriteria() {
|
||||||
|
fmt.Println("SEARCH CRITERIA")
|
||||||
|
|
||||||
|
setCodeDisplay := getInfoDisplay(searchCriteria.SetCode)
|
||||||
|
foilDisplay := getTriadicDisplay(searchCriteria.Foil)
|
||||||
|
promoDisplay := getTriadicDisplay(searchCriteria.Promo)
|
||||||
|
languageDisplay := getInfoDisplay(searchCriteria.Language)
|
||||||
|
|
||||||
|
fmt.Println("Set code:", setCodeDisplay)
|
||||||
|
fmt.Println("Foil:", foilDisplay)
|
||||||
|
fmt.Println("Promo:", promoDisplay)
|
||||||
|
fmt.Println("Language:", languageDisplay)
|
||||||
|
|
||||||
|
fmt.Print("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func showSelectedCard() {
|
||||||
|
selectedCardDisplay := getInfoDisplay(selectedCardPrintingSearchLine)
|
||||||
|
fmt.Println("Selected card:", selectedCardDisplay)
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,94 +0,0 @@
|
||||||
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")
|
|
||||||
}
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"sevenkeys/database"
|
||||||
|
"sevenkeys/logic"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
cardStorageLocation database.CardStorageLocation
|
||||||
|
selectedCardPrintingSearchLine string
|
||||||
|
|
||||||
|
copiesInserted int
|
||||||
|
)
|
||||||
|
|
||||||
|
func getInfoDisplay(info string) string {
|
||||||
|
if info == "" {
|
||||||
|
return "[EMPTY]"
|
||||||
|
}
|
||||||
|
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
func showStorageInfo() {
|
||||||
|
fmt.Println("STORAGE SETTINGS")
|
||||||
|
|
||||||
|
storageBoxDisplay := getInfoDisplay(cardStorageLocation.StorageBox)
|
||||||
|
sourceDisplay := getInfoDisplay(cardStorageLocation.Source)
|
||||||
|
conditionDisplay := getInfoDisplay(cardStorageLocation.CardCondition)
|
||||||
|
|
||||||
|
fmt.Println("Storage location:", storageBoxDisplay)
|
||||||
|
fmt.Println("Source:", sourceDisplay)
|
||||||
|
fmt.Println("Condition:", conditionDisplay)
|
||||||
|
|
||||||
|
fmt.Print("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func showCopiesInserted() {
|
||||||
|
fmt.Println("Copies inserted:", copiesInserted)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStorageOptions() {
|
||||||
|
cardStorageLocation.StorageBox = GetStringResponse("Storage box label:")
|
||||||
|
cardStorageLocation.Source = GetStringResponse("Card source:")
|
||||||
|
cardStorageLocation.CardCondition = GetStringResponse("Card condition:")
|
||||||
|
}
|
||||||
|
|
||||||
|
func insertSelectedCard(db *sql.DB) {
|
||||||
|
if cardStorageLocation.CardPrintingId == "" {
|
||||||
|
output = "No card selected, please [search] for a card printing."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if cardStorageLocation.StorageBox == "" || cardStorageLocation.CardCondition == "" {
|
||||||
|
getStorageOptions()
|
||||||
|
}
|
||||||
|
|
||||||
|
err := logic.StoreCard(db, cardStorageLocation)
|
||||||
|
logic.Check(err)
|
||||||
|
|
||||||
|
copiesInserted++
|
||||||
|
}
|
Loading…
Reference in New Issue