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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func LocateCards(db *sql.DB, cardNames []string, criteria SearchCriteria) ([]string, error) {
|
|
|
|
var locations []string
|
|
|
|
|
|
|
|
results, err := database.GetLocateResults(db, cardNames)
|
|
|
|
if err != nil {
|
|
|
|
return locations, err
|
|
|
|
}
|
|
|
|
// TODO: Filter by search criteria
|
|
|
|
|
|
|
|
var location string
|
|
|
|
for _, result := range results {
|
|
|
|
location = fmt.Sprintf("%s (%s %s) [%s]",
|
|
|
|
result.CardName,
|
|
|
|
result.SetCode,
|
|
|
|
result.CollectorNumber,
|
|
|
|
result.Language)
|
|
|
|
|
|
|
|
if result.IsFoil {
|
|
|
|
location += " FOIL"
|
|
|
|
}
|
|
|
|
if result.IsPromo {
|
|
|
|
location += " PROMO"
|
|
|
|
}
|
|
|
|
|
|
|
|
location += fmt.Sprintf(" in %s \"%s\"",
|
|
|
|
result.StorageAreaType,
|
|
|
|
result.StorageAreaName)
|
|
|
|
|
|
|
|
if result.StorageAreaType == "Binder" {
|
|
|
|
location += GetBinderLocationDescription(result.Position)
|
|
|
|
} else if result.StorageAreaType == "Box" {
|
|
|
|
location += fmt.Sprintf(" at position %d", result.Position)
|
|
|
|
}
|
|
|
|
|
|
|
|
locations = append(locations, location)
|
|
|
|
}
|
|
|
|
|
|
|
|
return locations, nil
|
2024-09-05 09:53:14 +00:00
|
|
|
}
|