2024-09-05 09:53:14 +00:00
|
|
|
package database
|
|
|
|
|
2024-09-07 23:24:24 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
)
|
2024-09-05 09:53:14 +00:00
|
|
|
|
|
|
|
type LocateCardResult struct {
|
2024-09-13 11:32:18 +00:00
|
|
|
CardLocationId int
|
2024-09-05 09:53:14 +00:00
|
|
|
CardName string
|
|
|
|
SetCode string
|
|
|
|
IsFoil bool
|
|
|
|
IsPromo bool
|
|
|
|
CollectorNumber string
|
|
|
|
Language string
|
2024-09-13 11:32:18 +00:00
|
|
|
StorageAreaId int
|
2024-09-05 09:53:14 +00:00
|
|
|
StorageAreaType string
|
|
|
|
StorageAreaName string
|
|
|
|
Position int
|
|
|
|
}
|
|
|
|
|
2024-09-07 23:24:24 +00:00
|
|
|
func GetLocateResults(db *sql.DB, cardNames []string) ([]LocateCardResult, error) {
|
2024-09-05 09:53:14 +00:00
|
|
|
var results []LocateCardResult
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
query := `SELECT CardLocation.Id,
|
|
|
|
CardPrinting.Name,
|
|
|
|
CardPrinting.SetCode,
|
|
|
|
CardPrinting.IsFoil,
|
|
|
|
CardPrinting.IsPromo,
|
|
|
|
CardPrinting.CollectorNumber,
|
|
|
|
CardPrinting.Language,
|
|
|
|
StorageArea.Id,
|
|
|
|
StorageArea.StorageType,
|
|
|
|
StorageArea.Name,
|
|
|
|
CardLocation.Position
|
|
|
|
FROM CardLocation
|
|
|
|
JOIN CardPrinting ON CardLocation.CardPrintingId = CardPrinting.Id
|
|
|
|
JOIN StorageArea ON CardLocation.StorageAreaId = StorageArea.Id
|
|
|
|
WHERE CardPrinting.Name IN (?);`
|
2024-09-07 23:24:24 +00:00
|
|
|
query, args, err := sqlx.In(query, cardNames)
|
|
|
|
if err != nil {
|
|
|
|
return results, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rows, err := db.Query(query, args...)
|
2024-09-05 09:53:14 +00:00
|
|
|
defer rows.Close()
|
|
|
|
if err != nil {
|
|
|
|
return results, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var result LocateCardResult
|
|
|
|
for rows.Next() {
|
2024-09-13 11:32:18 +00:00
|
|
|
err := rows.Scan(&result.CardLocationId, &result.CardName, &result.SetCode, &result.IsFoil, &result.IsPromo, &result.CollectorNumber, &result.Language, &result.StorageAreaId, &result.StorageAreaType, &result.StorageAreaName, &result.Position)
|
2024-09-05 09:53:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return results, err
|
|
|
|
}
|
|
|
|
|
|
|
|
results = append(results, result)
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, nil
|
|
|
|
}
|