Compare commits
2 Commits
99ba02ef05
...
a82355cf47
Author | SHA1 | Date |
---|---|---|
|
a82355cf47 | |
|
62c7e621d5 |
|
@ -17,7 +17,7 @@ printf "Storage area name: "
|
||||||
read storageAreaName
|
read storageAreaName
|
||||||
|
|
||||||
ADD_CARDS=0
|
ADD_CARDS=0
|
||||||
echo "scantap: Beginning scan loop"
|
echo "card_scanner: Beginning scan loop"
|
||||||
while true; do
|
while true; do
|
||||||
rng="$(cat /dev/random | tr -cd 'a-f0-9' | head -c 32)"
|
rng="$(cat /dev/random | tr -cd 'a-f0-9' | head -c 32)"
|
||||||
filename="$STORAGE_DIR/$rng.png"
|
filename="$STORAGE_DIR/$rng.png"
|
||||||
|
@ -28,7 +28,7 @@ while true; do
|
||||||
if test $? -eq 7; then
|
if test $? -eq 7; then
|
||||||
if test $ADD_CARDS -eq 0; then
|
if test $ADD_CARDS -eq 0; then
|
||||||
ADD_CARDS=1
|
ADD_CARDS=1
|
||||||
echo "scantap: No more cards in feeder" >&2
|
echo "card_scanner: No more cards in feeder" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If we have generated a zero-length file, then delete it
|
# If we have generated a zero-length file, then delete it
|
||||||
|
@ -44,13 +44,13 @@ while true; do
|
||||||
convert -rotate 180 "$filename" "$filename"
|
convert -rotate 180 "$filename" "$filename"
|
||||||
check_error "convert"
|
check_error "convert"
|
||||||
|
|
||||||
cardLocationId="$(./sevenkeys --profile="$profile" store --storagearea="$storageAreaName" --id="00000000-0000-0000-0000-0000000000000")"
|
cardLocationId="$(./sevenkeys --profile="$profile" store --storagearea="$storageAreaName" --id="-1")"
|
||||||
check_error "sevenkeys"
|
check_error "sevenkeys"
|
||||||
|
|
||||||
if test "$profile" == "development"; then
|
if test "$profile" == "development"; then
|
||||||
databaseName="sevenkeys_development"
|
databaseName="sevenkeys_dev"
|
||||||
else
|
else
|
||||||
databaseName="sevenkeys"
|
databaseName="sevenkeys_prod"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql)" \
|
mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql)" \
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
cache/
|
cache/
|
||||||
config.development.json
|
config.dev.json
|
||||||
config.production.json
|
config.prod.json
|
||||||
sevenkeys.sql
|
sevenkeys.sql
|
||||||
|
log.txt
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
package database
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CardLocation struct {
|
|
||||||
Id int
|
|
||||||
CardPrintingId string
|
|
||||||
StorageAreaId int
|
|
||||||
Position int
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetLastPositionInStorageArea(db *sql.DB, storageAreaId int) (int, error) {
|
|
||||||
query := "SELECT Position FROM CardLocation WHERE StorageAreaId = ? ORDER BY Position DESC LIMIT 1;"
|
|
||||||
|
|
||||||
var lastPosition int
|
|
||||||
err := db.QueryRow(query, storageAreaId).Scan(&lastPosition)
|
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
return 0, nil
|
|
||||||
} else if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastPosition, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func InsertCardLocation(db *sql.DB, storageLocation CardLocation) (int64, error) {
|
|
||||||
query := `INSERT INTO CardLocation
|
|
||||||
(CardPrintingId, StorageAreaId, Position)
|
|
||||||
VALUES (?, ?, ?);`
|
|
||||||
|
|
||||||
insert, err := db.Prepare(query)
|
|
||||||
if err != nil {
|
|
||||||
return -1, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := insert.Exec(storageLocation.CardPrintingId, storageLocation.StorageAreaId, storageLocation.Position)
|
|
||||||
if err != nil {
|
|
||||||
return -1, err
|
|
||||||
}
|
|
||||||
|
|
||||||
id, err := result.LastInsertId()
|
|
||||||
if err != nil {
|
|
||||||
return -1, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return id, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func InsertCardInExistingLocation(db *sql.DB, cardLocation CardLocation) error {
|
|
||||||
query := `UPDATE CardLocation SET CardPrintingId = ? WHERE Id = ?;`
|
|
||||||
|
|
||||||
update, err := db.Prepare(query)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = update.Exec(cardLocation.CardPrintingId, cardLocation.Id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -62,7 +62,7 @@ func GetAllCardtraderBlueprints(db *sql.DB) ([]cardtrader.Blueprint, error) {
|
||||||
|
|
||||||
var blueprint cardtrader.Blueprint
|
var blueprint cardtrader.Blueprint
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err := rows.Scan(&blueprint.Id, &blueprint.CategoryId, &blueprint.ExpansionId, &blueprint.Name, &blueprint.FixedProperties.Number)
|
err := rows.Scan(&blueprint.Id, &blueprint.ScryfallId, &blueprint.CategoryId, &blueprint.ExpansionId, &blueprint.Name, &blueprint.FixedProperties.Number)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return blueprints, err
|
return blueprints, err
|
||||||
}
|
}
|
||||||
|
@ -72,3 +72,15 @@ func GetAllCardtraderBlueprints(db *sql.DB) ([]cardtrader.Blueprint, error) {
|
||||||
|
|
||||||
return blueprints, nil
|
return blueprints, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetCardtraderBlueprintIdByScryfallId(db *sql.DB, scryfallId string) (int, error) {
|
||||||
|
query := `SELECT Id FROM CardtraderBlueprint WHERE ScryfallCardId = ?;`
|
||||||
|
|
||||||
|
var cardtraderBlueprintId int
|
||||||
|
err := db.QueryRow(query, scryfallId).Scan(&cardtraderBlueprintId)
|
||||||
|
if err != nil {
|
||||||
|
return cardtraderBlueprintId, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cardtraderBlueprintId, nil
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
-- +goose StatementBegin
|
-- +goose StatementBegin
|
||||||
CREATE TABLE IF NOT EXISTS CardScan (
|
CREATE TABLE IF NOT EXISTS CardScan (
|
||||||
Id INT PRIMARY KEY AUTO_INCREMENT,
|
Id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
CardLocationId INT NOT NULL,
|
ProductLocationId INT NOT NULL,
|
||||||
|
FOREIGN KEY (ProductLocationId) REFERENCES ProductLocation(Id),
|
||||||
Filename VARCHAR(100) NOT NULL
|
Filename VARCHAR(100) NOT NULL
|
||||||
);
|
);
|
||||||
-- +goose StatementEnd
|
-- +goose StatementEnd
|
|
@ -0,0 +1,91 @@
|
||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProductLocation struct {
|
||||||
|
Id int
|
||||||
|
CardtraderBlueprintId int
|
||||||
|
StorageAreaId int
|
||||||
|
Position int
|
||||||
|
CardtraderProductId int
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetLastPositionInStorageArea(db *sql.DB, storageAreaId int) (int, error) {
|
||||||
|
query := "SELECT Position FROM ProductLocation WHERE StorageAreaId = ? ORDER BY Position DESC LIMIT 1;"
|
||||||
|
|
||||||
|
var lastPosition int
|
||||||
|
err := db.QueryRow(query, storageAreaId).Scan(&lastPosition)
|
||||||
|
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
return 0, nil
|
||||||
|
} else if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastPosition, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func InsertProductLocation(db *sql.DB, productLocation ProductLocation) (int64, error) {
|
||||||
|
query := `INSERT INTO ProductLocation
|
||||||
|
(CardtraderBlueprintId, StorageAreaId, Position)
|
||||||
|
VALUES (?, ?, ?);`
|
||||||
|
|
||||||
|
insert, err := db.Prepare(query)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := insert.Exec(productLocation.CardtraderBlueprintId, productLocation.StorageAreaId, productLocation.Position)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := result.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func InsertProductInExistingLocation(db *sql.DB, productLocation ProductLocation) error {
|
||||||
|
query := `UPDATE ProductLocation SET CardtraderBlueprintId = ? WHERE Id = ?;`
|
||||||
|
|
||||||
|
update, err := db.Prepare(query)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = update.Exec(productLocation.CardtraderBlueprintId, productLocation.Id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAllProductsInStorageArea(db *sql.DB, storageAreaId int) ([]ProductLocation, error) {
|
||||||
|
var productLocations []ProductLocation
|
||||||
|
|
||||||
|
query := `SELECT * FROM ProductLocation WHERE StorageAreaId = ?;`
|
||||||
|
|
||||||
|
rows, err := db.Query(query)
|
||||||
|
defer rows.Close()
|
||||||
|
if err != nil {
|
||||||
|
return productLocations, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var productLocation ProductLocation
|
||||||
|
for rows.Next() {
|
||||||
|
err = rows.Scan(&productLocation.Id, &productLocation.CardtraderBlueprintId, &productLocation.StorageAreaId, &productLocation.Position, &productLocation.CardtraderProductId)
|
||||||
|
if err != nil {
|
||||||
|
return productLocations, err
|
||||||
|
}
|
||||||
|
|
||||||
|
productLocations = append(productLocations, productLocation)
|
||||||
|
}
|
||||||
|
|
||||||
|
return productLocations, nil
|
||||||
|
}
|
|
@ -71,7 +71,7 @@ func GetStorageAreaTypeById(db *sql.DB, storageAreaId int) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetNextEmptySlotInBinder(db *sql.DB, storageAreaId int) (int, error) {
|
func GetNextEmptySlotInBinder(db *sql.DB, storageAreaId int) (int, error) {
|
||||||
query := `SELECT Id FROM CardLocation WHERE CardPrintingId IS NULL AND StorageAreaId = ? ORDER BY Position ASC LIMIT 1;`
|
query := `SELECT Id FROM ProductLocation WHERE CardtraderBlueprintId IS NULL AND StorageAreaId = ? ORDER BY Position ASC LIMIT 1;`
|
||||||
|
|
||||||
var emptySlotId int
|
var emptySlotId int
|
||||||
err := db.QueryRow(query, storageAreaId).Scan(&emptySlotId)
|
err := db.QueryRow(query, storageAreaId).Scan(&emptySlotId)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type DelverLensCard struct {
|
type DelverLensCard struct {
|
||||||
ScryfallID string
|
ScryfallId string
|
||||||
IsFoil bool
|
IsFoil bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func ParseExportFile(filename string) ([]DelverLensCard, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
card := DelverLensCard{
|
card := DelverLensCard{
|
||||||
ScryfallID: record[0],
|
ScryfallId: record[0],
|
||||||
IsFoil: record[1] == "Foil",
|
IsFoil: record[1] == "Foil",
|
||||||
}
|
}
|
||||||
cards = append(cards, card)
|
cards = append(cards, card)
|
||||||
|
|
|
@ -2,25 +2,27 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"log"
|
||||||
"sevenkeys/database"
|
"sevenkeys/database"
|
||||||
"sevenkeys/delverlens"
|
"sevenkeys/delverlens"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ImportDelverLensCards(db *sql.DB, cards []delverlens.DelverLensCard, storageAreaId int) error {
|
func ImportDelverLensCards(db *sql.DB, cards []delverlens.DelverLensCard, storageAreaId int) error {
|
||||||
for _, card := range cards {
|
for _, card := range cards {
|
||||||
var cardPrintingId string
|
cardtraderBlueprintId, err := database.GetCardtraderBlueprintIdByScryfallId(db, card.ScryfallId)
|
||||||
if card.IsFoil {
|
if err == sql.ErrNoRows {
|
||||||
cardPrintingId = card.ScryfallID + "f"
|
log.Printf("import: No Cardtrader product found for Scryfall ID: %s, inserting placeholder\n", card.ScryfallId)
|
||||||
} else {
|
cardtraderBlueprintId = -1
|
||||||
cardPrintingId = card.ScryfallID + "n"
|
} else if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cardLocation := database.CardLocation{
|
productLocation := database.ProductLocation{
|
||||||
CardPrintingId: cardPrintingId,
|
CardtraderBlueprintId: cardtraderBlueprintId,
|
||||||
StorageAreaId: storageAreaId,
|
StorageAreaId: storageAreaId,
|
||||||
}
|
}
|
||||||
|
|
||||||
StoreCard(db, cardLocation)
|
StoreProduct(db, productLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -3,9 +3,29 @@ package logic
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"sevenkeys/database"
|
"sevenkeys/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func CreateStorageArea(db *sql.DB, storageArea database.StorageArea) error {
|
||||||
|
// TODO: Check if there's already a storage are with the same name
|
||||||
|
// TODO: Check if the type entered is valid
|
||||||
|
err := database.InsertStorageArea(db, storageArea)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAllStorageAreas(db *sql.DB) ([]database.StorageArea, error) {
|
||||||
|
storageAreas, err := database.GetAllStorageAreas(db)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return storageAreas, err
|
||||||
|
}
|
||||||
|
|
||||||
var ErrCouldNotGetStorageAreaId error = errors.New("Could not get storage area ID.")
|
var ErrCouldNotGetStorageAreaId error = errors.New("Could not get storage area ID.")
|
||||||
|
|
||||||
func GetStorageAreaId(db *sql.DB, storageAreaName string) (int, error) {
|
func GetStorageAreaId(db *sql.DB, storageAreaName string) (int, error) {
|
||||||
|
@ -31,17 +51,6 @@ func GetStorageAreaId(db *sql.DB, storageAreaName string) (int, error) {
|
||||||
return id, ErrCouldNotGetStorageAreaId
|
return id, ErrCouldNotGetStorageAreaId
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateStorageArea(db *sql.DB, storageArea database.StorageArea) error {
|
|
||||||
// TODO: Check if there's already a storage are with the same name
|
|
||||||
// TODO: Check if the type entered is valid
|
|
||||||
err := database.InsertStorageArea(db, storageArea)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type StorageAreaSearchOptions map[string]int
|
type StorageAreaSearchOptions map[string]int
|
||||||
|
|
||||||
func GetStorageAreaSearchOptions(db *sql.DB) (StorageAreaSearchOptions, error) {
|
func GetStorageAreaSearchOptions(db *sql.DB) (StorageAreaSearchOptions, error) {
|
||||||
|
@ -59,15 +68,15 @@ func GetStorageAreaSearchOptions(db *sql.DB) (StorageAreaSearchOptions, error) {
|
||||||
return options, nil
|
return options, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func storeAfterLastCard(db *sql.DB, cardLocation database.CardLocation) (int64, error) {
|
func storeAfterLastCard(db *sql.DB, productLocation database.ProductLocation) (int64, error) {
|
||||||
lastPosition, err := database.GetLastPositionInStorageArea(db, cardLocation.StorageAreaId)
|
lastPosition, err := database.GetLastPositionInStorageArea(db, productLocation.StorageAreaId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cardLocation.Position = lastPosition + 1
|
productLocation.Position = lastPosition + 1
|
||||||
|
|
||||||
id, err := database.InsertCardLocation(db, cardLocation)
|
id, err := database.InsertProductLocation(db, productLocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -75,9 +84,9 @@ func storeAfterLastCard(db *sql.DB, cardLocation database.CardLocation) (int64,
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func storeInEmptySlot(db *sql.DB, cardLocation database.CardLocation, cardLocationId int) error {
|
func storeInEmptySlot(db *sql.DB, productLocation database.ProductLocation, productLocationId int) error {
|
||||||
cardLocation.Id = cardLocationId
|
productLocation.Id = productLocationId
|
||||||
err := database.InsertCardInExistingLocation(db, cardLocation)
|
err := database.InsertProductInExistingLocation(db, productLocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -85,17 +94,17 @@ func storeInEmptySlot(db *sql.DB, cardLocation database.CardLocation, cardLocati
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func StoreCard(db *sql.DB, cardLocation database.CardLocation) (int64, error) {
|
func StoreProduct(db *sql.DB, productLocation database.ProductLocation) (int64, error) {
|
||||||
storageAreaType, err := database.GetStorageAreaTypeById(db, cardLocation.StorageAreaId)
|
storageAreaType, err := database.GetStorageAreaTypeById(db, productLocation.StorageAreaId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if storageAreaType == database.StorageAreaTypeBinder {
|
if storageAreaType == database.StorageAreaTypeBinder {
|
||||||
nextEmptySlotId, err := database.GetNextEmptySlotInBinder(db, cardLocation.StorageAreaId)
|
nextEmptySlotId, err := database.GetNextEmptySlotInBinder(db, productLocation.StorageAreaId)
|
||||||
|
|
||||||
if err == database.ErrNoEmptySlotsInBinder {
|
if err == database.ErrNoEmptySlotsInBinder {
|
||||||
id, err := storeAfterLastCard(db, cardLocation)
|
id, err := storeAfterLastCard(db, productLocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -104,7 +113,7 @@ func StoreCard(db *sql.DB, cardLocation database.CardLocation) (int64, error) {
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
} else {
|
} else {
|
||||||
err = storeInEmptySlot(db, cardLocation, nextEmptySlotId)
|
err = storeInEmptySlot(db, productLocation, nextEmptySlotId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -113,7 +122,7 @@ func StoreCard(db *sql.DB, cardLocation database.CardLocation) (int64, error) {
|
||||||
return int64(nextEmptySlotId), nil
|
return int64(nextEmptySlotId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := storeAfterLastCard(db, cardLocation)
|
id, err := storeAfterLastCard(db, productLocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -121,11 +130,16 @@ func StoreCard(db *sql.DB, cardLocation database.CardLocation) (int64, error) {
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Replace(db *sql.DB, cardLocationId int, cardPrintingId string) error {
|
func Replace(db *sql.DB, productLocationId int, cardtraderBlueprintId int) error {
|
||||||
cardLocation := database.CardLocation{
|
productLocation := database.ProductLocation{
|
||||||
Id: cardLocationId,
|
Id: productLocationId,
|
||||||
CardPrintingId: cardPrintingId,
|
CardtraderBlueprintId: cardtraderBlueprintId,
|
||||||
}
|
}
|
||||||
|
|
||||||
return database.InsertCardInExistingLocation(db, cardLocation)
|
return database.InsertProductInExistingLocation(db, productLocation)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAllProductsInStorageArea(db *sql.DB, storageAreaId int) ([]database.ProductLocation, error) {
|
||||||
|
productLocations, err := database.GetAllProductsInStorageArea(db, storageAreaId)
|
||||||
|
return productLocations, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"sevenkeys/delverlens"
|
"sevenkeys/delverlens"
|
||||||
"sevenkeys/logic"
|
"sevenkeys/logic"
|
||||||
"sevenkeys/update"
|
"sevenkeys/update"
|
||||||
|
"sevenkeys/webui"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -23,11 +24,15 @@ const (
|
||||||
AddSubcommand string = "add"
|
AddSubcommand string = "add"
|
||||||
RemoveSubcommand string = "remove"
|
RemoveSubcommand string = "remove"
|
||||||
ReplaceSubcommand string = "replace"
|
ReplaceSubcommand string = "replace"
|
||||||
|
WebUiSubcommand string = "webui"
|
||||||
|
BlueprintsCommand string = "blueprints"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
|
||||||
var profile string
|
var profile string
|
||||||
flag.StringVar(&profile, "profile", "development", "The database profile to use.")
|
flag.StringVar(&profile, "profile", "dev", "The database profile to use.")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -60,9 +65,9 @@ func main() {
|
||||||
break
|
break
|
||||||
case StoreSubcommand:
|
case StoreSubcommand:
|
||||||
storeCmd := flag.NewFlagSet(StoreSubcommand, flag.ExitOnError)
|
storeCmd := flag.NewFlagSet(StoreSubcommand, flag.ExitOnError)
|
||||||
storageArea := storeCmd.String("storagearea", "",
|
id := storeCmd.Int("id", -1, "The CardPrintingId of the card to store.")
|
||||||
|
storageArea := storeCmd.String("storage-area", "",
|
||||||
"The name of the StorageArea the card should be inserted to.")
|
"The name of the StorageArea the card should be inserted to.")
|
||||||
id := storeCmd.String("id", "", "The CardPrintingId of the card to store.")
|
|
||||||
|
|
||||||
storeCmd.Parse(flag.Args()[1:])
|
storeCmd.Parse(flag.Args()[1:])
|
||||||
|
|
||||||
|
@ -72,14 +77,14 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
cardLocation := database.CardLocation{
|
productLocation := database.ProductLocation{
|
||||||
CardPrintingId: *id,
|
CardtraderBlueprintId: *id,
|
||||||
StorageAreaId: storageAreaId,
|
StorageAreaId: storageAreaId,
|
||||||
}
|
}
|
||||||
cardLocationId, err := logic.StoreCard(db, cardLocation)
|
productLocationId, err := logic.StoreProduct(db, productLocation)
|
||||||
logic.Check(err)
|
logic.Check(err)
|
||||||
|
|
||||||
fmt.Printf("%d\n", cardLocationId)
|
fmt.Printf("%d\n", productLocationId)
|
||||||
break
|
break
|
||||||
|
|
||||||
case ImportSubcommand:
|
case ImportSubcommand:
|
||||||
|
@ -147,8 +152,8 @@ func main() {
|
||||||
case AddSubcommand:
|
case AddSubcommand:
|
||||||
addCmd := flag.NewFlagSet(AddSubcommand, flag.ExitOnError)
|
addCmd := flag.NewFlagSet(AddSubcommand, flag.ExitOnError)
|
||||||
|
|
||||||
cardPrintingId := addCmd.String("card-printing-id", "", "The ID of the card printing to add to storage.")
|
cardtraderBlueprintId := addCmd.Int("blueprint-id", -1, "The Cardtrader Bluepritn ID of the product to add to storage.")
|
||||||
storageArea := addCmd.String("storagearea", "",
|
storageArea := addCmd.String("storage-area", "",
|
||||||
"The name of the StorageArea where cards should be imported.")
|
"The name of the StorageArea where cards should be imported.")
|
||||||
|
|
||||||
addCmd.Parse(flag.Args()[1:])
|
addCmd.Parse(flag.Args()[1:])
|
||||||
|
@ -160,11 +165,11 @@ func main() {
|
||||||
}
|
}
|
||||||
logic.Check(err)
|
logic.Check(err)
|
||||||
|
|
||||||
cardLocation := database.CardLocation{
|
productLocation := database.ProductLocation{
|
||||||
CardPrintingId: *cardPrintingId,
|
CardtraderBlueprintId: *cardtraderBlueprintId,
|
||||||
StorageAreaId: storageAreaId,
|
StorageAreaId: storageAreaId,
|
||||||
}
|
}
|
||||||
logic.StoreCard(db, cardLocation)
|
logic.StoreProduct(db, productLocation)
|
||||||
break
|
break
|
||||||
case RemoveSubcommand:
|
case RemoveSubcommand:
|
||||||
removeCmd := flag.NewFlagSet(RemoveSubcommand, flag.ExitOnError)
|
removeCmd := flag.NewFlagSet(RemoveSubcommand, flag.ExitOnError)
|
||||||
|
@ -188,19 +193,35 @@ func main() {
|
||||||
replaceCmd := flag.NewFlagSet(ReplaceSubcommand, flag.ExitOnError)
|
replaceCmd := flag.NewFlagSet(ReplaceSubcommand, flag.ExitOnError)
|
||||||
|
|
||||||
cardLocationId := replaceCmd.Int("card-location-id", -1, "The card location to replace the card at.")
|
cardLocationId := replaceCmd.Int("card-location-id", -1, "The card location to replace the card at.")
|
||||||
cardPrintingId := replaceCmd.String("card-printing-id", "", "The card printing to put at the specified location.")
|
cardtraderBlueprintId := replaceCmd.Int("blueprint-id", -1, "The card printing to put at the specified location.")
|
||||||
|
|
||||||
replaceCmd.Parse(flag.Args()[1:])
|
replaceCmd.Parse(flag.Args()[1:])
|
||||||
|
|
||||||
if *cardLocationId == -1 {
|
if *cardLocationId == -1 {
|
||||||
log.Fatal(errors.New("No CardLocationId given."))
|
log.Fatal(errors.New("No CardLocationId given."))
|
||||||
}
|
}
|
||||||
if *cardPrintingId == "" {
|
|
||||||
log.Fatal(errors.New("No CardPrintingId given."))
|
err := logic.Replace(db, *cardLocationId, *cardtraderBlueprintId)
|
||||||
|
logic.Check(err)
|
||||||
|
break
|
||||||
|
case WebUiSubcommand:
|
||||||
|
webui.Start(db)
|
||||||
|
/*
|
||||||
|
storageAreas, err := database.GetAllStorageAreas(db)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(storageAreas)
|
||||||
|
*/
|
||||||
|
break
|
||||||
|
case BlueprintsCommand:
|
||||||
|
blueprints, err := database.GetAllCardtraderBlueprints(db)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := logic.Replace(db, *cardLocationId, *cardPrintingId)
|
fmt.Println(blueprints)
|
||||||
logic.Check(err)
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "Unrecognized subcommand: %s\n", os.Args[1])
|
fmt.Fprintf(os.Stderr, "Unrecognized subcommand: %s\n", os.Args[1])
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package webui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"html/template"
|
||||||
|
"net/http"
|
||||||
|
"sevenkeys/logic"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BaseHandler struct {
|
||||||
|
db *sql.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBaseHandler(db *sql.DB) *BaseHandler {
|
||||||
|
return &BaseHandler{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BaseHandler) storageAreasHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
storageAreas, err := logic.GetAllStorageAreas(h.db)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const tmpl = `
|
||||||
|
<html>
|
||||||
|
<head><title>Sevenkeys</title></head>
|
||||||
|
<body>
|
||||||
|
{{range $val := .}}
|
||||||
|
<a href="/storage/{{$val.Id}}">{{$val.Name}} ({{$val.StorageType}})</a><br>
|
||||||
|
{{end}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
||||||
|
t := template.Must(template.New("tmpl").Parse(tmpl))
|
||||||
|
t.Execute(w, storageAreas)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BaseHandler) storageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
storageAreaIdParam := r.PathValue("id")
|
||||||
|
|
||||||
|
storageAreaId, err := strconv.Atoi(storageAreaIdParam)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
productLocations, err := logic.GetAllProductsInStorageArea(h.db, storageAreaId)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const tmpl = `
|
||||||
|
<html>
|
||||||
|
<head><title>Sevenkeys</title></head>
|
||||||
|
<body>
|
||||||
|
<ol>
|
||||||
|
{{range $val := .}}
|
||||||
|
<li>{{$val}}</li>
|
||||||
|
{{end}}
|
||||||
|
<ol>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
||||||
|
t := template.Must(template.New("tmpl").Parse(tmpl))
|
||||||
|
t.Execute(w, productLocations)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Start(db *sql.DB) {
|
||||||
|
handlers := NewBaseHandler(db)
|
||||||
|
|
||||||
|
http.HandleFunc("/", handlers.storageAreasHandler)
|
||||||
|
http.HandleFunc("/storage/{id}", handlers.storageHandler)
|
||||||
|
http.ListenAndServe(":8080", nil)
|
||||||
|
}
|
Loading…
Reference in New Issue