Fix Delverlens import flow

This commit is contained in:
The Magician 2024-10-01 14:56:13 +01:00
parent 73dc06d78f
commit 0e3ee54e1c
3 changed files with 5 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import (
) )
var ErrStorageAreaDoesNotExist error = errors.New("Storage area does not exist.") 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 StorageAreaTypeBinder string = "Binder"
var StorageAreaTypeBox string = "Box" var StorageAreaTypeBox string = "Box"
@ -75,7 +76,7 @@ func GetNextEmptySlotInBinder(db *sql.DB, storageAreaId int) (int, error) {
var emptySlotId int var emptySlotId int
err := db.QueryRow(query, storageAreaId).Scan(&emptySlotId) err := db.QueryRow(query, storageAreaId).Scan(&emptySlotId)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return -1, nil return -1, ErrNoEmptySlotsInBinder
} else if err != nil { } else if err != nil {
return 0, err return 0, err
} }

View File

@ -10,9 +10,9 @@ func ImportDelverLensCards(db *sql.DB, cards []delverlens.DelverLensCard, storag
for _, card := range cards { for _, card := range cards {
var cardPrintingId string var cardPrintingId string
if card.IsFoil { if card.IsFoil {
cardPrintingId = card.ScryfallID + "n"
} else {
cardPrintingId = card.ScryfallID + "f" cardPrintingId = card.ScryfallID + "f"
} else {
cardPrintingId = card.ScryfallID + "n"
} }
cardLocation := database.CardLocation{ cardLocation := database.CardLocation{

View File

@ -94,7 +94,7 @@ func StoreCard(db *sql.DB, cardLocation database.CardLocation) error {
if storageAreaType == database.StorageAreaTypeBinder { if storageAreaType == database.StorageAreaTypeBinder {
nextEmptySlotId, err := database.GetNextEmptySlotInBinder(db, cardLocation.StorageAreaId) nextEmptySlotId, err := database.GetNextEmptySlotInBinder(db, cardLocation.StorageAreaId)
if err == sql.ErrNoRows { if err == database.ErrNoEmptySlotsInBinder {
err = storeAfterLastCard(db, cardLocation) err = storeAfterLastCard(db, cardLocation)
if err != nil { if err != nil {
return err return err