2024-05-30 12:03:12 +00:00
|
|
|
package database
|
|
|
|
|
2024-06-01 21:18:33 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
)
|
2024-05-30 12:03:12 +00:00
|
|
|
|
|
|
|
type CardStorageLocation struct {
|
|
|
|
Id int
|
2024-06-03 16:08:15 +00:00
|
|
|
CardPrintingId string
|
2024-06-11 15:13:42 +00:00
|
|
|
CardCondition string
|
2024-05-30 12:03:12 +00:00
|
|
|
StorageBox string
|
|
|
|
Position int
|
|
|
|
Source string
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetLastPositionInBox(db *sql.DB, storageBox string) (int, error) {
|
2024-06-01 21:18:33 +00:00
|
|
|
query := "SELECT Position FROM CardStorageLocation WHERE StorageBox = ? ORDER BY Position DESC LIMIT 1;"
|
2024-05-30 12:03:12 +00:00
|
|
|
|
|
|
|
var lastPosition int
|
2024-05-30 13:33:37 +00:00
|
|
|
err := db.QueryRow(query, storageBox).Scan(&lastPosition)
|
2024-05-30 12:03:12 +00:00
|
|
|
|
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
return 0, nil
|
2024-06-01 21:18:33 +00:00
|
|
|
} else if err != nil {
|
2024-05-30 12:03:12 +00:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return lastPosition, nil
|
|
|
|
}
|
|
|
|
|
2024-05-31 19:32:44 +00:00
|
|
|
func InsertCardStorageLocation(db *sql.DB, storageLocation CardStorageLocation) error {
|
2024-05-30 12:03:12 +00:00
|
|
|
query := `INSERT INTO CardStorageLocation
|
2024-06-11 15:13:42 +00:00
|
|
|
(CardPrintingId, CardCondition, StorageBox, Position, Source)
|
|
|
|
VALUES (?, ?, ?, ?, ?);`
|
2024-05-30 12:03:12 +00:00
|
|
|
|
|
|
|
insert, err := db.Prepare(query)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-06-11 15:13:42 +00:00
|
|
|
_, err = insert.Exec(storageLocation.CardPrintingId, storageLocation.CardCondition, storageLocation.StorageBox, storageLocation.Position, storageLocation.Source)
|
2024-05-30 12:03:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-05-30 13:33:37 +00:00
|
|
|
|
|
|
|
return nil
|
2024-05-30 12:03:12 +00:00
|
|
|
}
|