2024-09-05 09:53:14 +00:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2024-09-07 23:24:24 +00:00
|
|
|
"fmt"
|
2024-09-05 09:53:14 +00:00
|
|
|
"sevenkeys/database"
|
|
|
|
)
|
|
|
|
|
2024-09-07 23:24:24 +00:00
|
|
|
const SLOTS_PER_BINDER_PAGE = 18 // TODO: Make this configurable
|
|
|
|
|
|
|
|
func GetBinderLocationDescription(position int) string {
|
|
|
|
var page int = (position / SLOTS_PER_BINDER_PAGE) + 1
|
|
|
|
|
|
|
|
var pagePosition int = position % SLOTS_PER_BINDER_PAGE
|
|
|
|
|
|
|
|
var slot int
|
|
|
|
var frontOrBack string
|
|
|
|
|
|
|
|
if pagePosition <= (SLOTS_PER_BINDER_PAGE / 2) {
|
|
|
|
slot = pagePosition
|
|
|
|
frontOrBack = "front"
|
|
|
|
} else {
|
|
|
|
slot = pagePosition - (SLOTS_PER_BINDER_PAGE / 2)
|
|
|
|
frontOrBack = "back"
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf(" on page %d in %s slot %d", page, frontOrBack, slot)
|
|
|
|
}
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
func LocateCards(db *sql.DB, cardNames []string, criteria SearchCriteria) ([]database.LocateCardResult, error) {
|
2024-09-07 23:24:24 +00:00
|
|
|
results, err := database.GetLocateResults(db, cardNames)
|
|
|
|
if err != nil {
|
2024-09-13 11:32:18 +00:00
|
|
|
return results, err
|
2024-09-07 23:24:24 +00:00
|
|
|
}
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
var filteredResults []database.LocateCardResult
|
|
|
|
|
2024-09-07 23:24:24 +00:00
|
|
|
for _, result := range results {
|
2024-09-12 12:31:42 +00:00
|
|
|
printing := database.CardPrinting{
|
|
|
|
SetCode: result.SetCode,
|
|
|
|
IsFoil: result.IsFoil,
|
|
|
|
IsPromo: result.IsPromo,
|
|
|
|
Language: result.Language,
|
|
|
|
}
|
|
|
|
|
|
|
|
filter := filterPrinting(printing, criteria)
|
|
|
|
if filter {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
filteredResults = append(filteredResults, result)
|
|
|
|
}
|
2024-09-07 23:24:24 +00:00
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
return filteredResults, nil
|
|
|
|
}
|
2024-09-07 23:24:24 +00:00
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
func GetLocationDescription(location database.LocateCardResult) string {
|
|
|
|
var description string
|
2024-09-07 23:24:24 +00:00
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
description = fmt.Sprintf("%s (%s %s) [%s]",
|
|
|
|
location.CardName,
|
|
|
|
location.SetCode,
|
|
|
|
location.CollectorNumber,
|
|
|
|
location.Language)
|
|
|
|
|
|
|
|
if location.IsFoil {
|
|
|
|
description += " FOIL"
|
|
|
|
}
|
|
|
|
if location.IsPromo {
|
|
|
|
description += " PROMO"
|
|
|
|
}
|
|
|
|
|
|
|
|
description += fmt.Sprintf(" in %s \"%s\"",
|
|
|
|
location.StorageAreaType,
|
|
|
|
location.StorageAreaName)
|
2024-09-07 23:24:24 +00:00
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
if location.StorageAreaType == "Binder" {
|
|
|
|
description += GetBinderLocationDescription(location.Position)
|
|
|
|
} else if location.StorageAreaType == "Box" {
|
|
|
|
description += fmt.Sprintf(" at position %d", location.Position)
|
2024-09-07 23:24:24 +00:00
|
|
|
}
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
return description
|
2024-09-05 09:53:14 +00:00
|
|
|
}
|