package logic import ( "database/sql" "fmt" "sevenkeys/database" ) 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) ([]database.LocateCardResult, error) { results, err := database.GetLocateResults(db, cardNames) if err != nil { return results, err } var filteredResults []database.LocateCardResult for _, result := range results { printing := database.CardPrinting{ SetCode: result.SetCode, IsFoil: result.IsFoil, IsPromo: result.IsPromo, Language: result.Language, } filter := filterPrinting(printing, criteria) if filter { continue } filteredResults = append(filteredResults, result) } return filteredResults, nil } func GetLocationDescription(location database.LocateCardResult) string { var description string 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) if location.StorageAreaType == "Binder" { description += GetBinderLocationDescription(location.Position) } else if location.StorageAreaType == "Box" { description += fmt.Sprintf(" at position %d", location.Position) } return description }