Fix Delverlens import flow
This commit is contained in:
parent
73dc06d78f
commit
0e3ee54e1c
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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{
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue