From 0e3ee54e1cba02b80378aa54b7bd76bbf90f6993 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 1 Oct 2024 14:56:13 +0100 Subject: [PATCH] Fix Delverlens import flow --- sevenkeys/database/storagearea.go | 3 ++- sevenkeys/logic/import.go | 4 ++-- sevenkeys/logic/storage.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sevenkeys/database/storagearea.go b/sevenkeys/database/storagearea.go index 42b41e5..a55119f 100644 --- a/sevenkeys/database/storagearea.go +++ b/sevenkeys/database/storagearea.go @@ -6,6 +6,7 @@ import ( ) var ErrStorageAreaDoesNotExist error = errors.New("Storage area does not exist.") +var ErrNoEmptySlotsInBinder error = errors.New("No empty slots in binder.") var StorageAreaTypeBinder string = "Binder" var StorageAreaTypeBox string = "Box" @@ -75,7 +76,7 @@ func GetNextEmptySlotInBinder(db *sql.DB, storageAreaId int) (int, error) { var emptySlotId int err := db.QueryRow(query, storageAreaId).Scan(&emptySlotId) if err == sql.ErrNoRows { - return -1, nil + return -1, ErrNoEmptySlotsInBinder } else if err != nil { return 0, err } diff --git a/sevenkeys/logic/import.go b/sevenkeys/logic/import.go index 351c3f5..5352a29 100644 --- a/sevenkeys/logic/import.go +++ b/sevenkeys/logic/import.go @@ -10,9 +10,9 @@ func ImportDelverLensCards(db *sql.DB, cards []delverlens.DelverLensCard, storag for _, card := range cards { var cardPrintingId string if card.IsFoil { - cardPrintingId = card.ScryfallID + "n" - } else { cardPrintingId = card.ScryfallID + "f" + } else { + cardPrintingId = card.ScryfallID + "n" } cardLocation := database.CardLocation{ diff --git a/sevenkeys/logic/storage.go b/sevenkeys/logic/storage.go index c1b9409..b93fcb3 100644 --- a/sevenkeys/logic/storage.go +++ b/sevenkeys/logic/storage.go @@ -94,7 +94,7 @@ func StoreCard(db *sql.DB, cardLocation database.CardLocation) error { if storageAreaType == database.StorageAreaTypeBinder { nextEmptySlotId, err := database.GetNextEmptySlotInBinder(db, cardLocation.StorageAreaId) - if err == sql.ErrNoRows { + if err == database.ErrNoEmptySlotsInBinder { err = storeAfterLastCard(db, cardLocation) if err != nil { return err