Add storage areas to database
This commit is contained in:
parent
e5f5fbaee2
commit
8fe02f46d6
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"sevenkeys/database"
|
||||
"sevenkeys/logic"
|
||||
)
|
||||
|
||||
|
@ -28,16 +29,25 @@ func MainCliLoop(db *sql.DB) {
|
|||
|
||||
command = GetStringResponse("SEVENKEYS $")
|
||||
|
||||
var err error
|
||||
|
||||
switch command {
|
||||
case "q", "quit":
|
||||
return
|
||||
case "n", "newstorage":
|
||||
var storageArea database.StorageArea
|
||||
storageArea.Name = GetStringResponse("Storage area name:")
|
||||
storageArea.Type = GetStringResponse("Storage area type (Binder/Box):")
|
||||
err = logic.CreateStorageArea(db, storageArea)
|
||||
logic.Check(err)
|
||||
break
|
||||
case "l", "location":
|
||||
cardStorageLocation.StorageBox = GetStringResponse("Storage location:")
|
||||
break
|
||||
case "r", "source":
|
||||
cardStorageLocation.Source = GetStringResponse("Card source:")
|
||||
break
|
||||
case "n", "condition":
|
||||
case "p", "condition":
|
||||
cardStorageLocation.CardCondition = GetStringResponse("Card condition:")
|
||||
break
|
||||
case "c", "criteria":
|
||||
|
@ -48,7 +58,6 @@ func MainCliLoop(db *sql.DB) {
|
|||
|
||||
var previousCardPrintingId = cardStorageLocation.CardPrintingId
|
||||
|
||||
var err error
|
||||
cardStorageLocation.CardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
|
||||
var exitError *exec.ExitError
|
||||
if errors.As(err, &exitError) {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package database
|
||||
|
||||
import "database/sql"
|
||||
|
||||
type StorageArea struct {
|
||||
Id int
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
func InsertStorageArea(db *sql.DB, storageArea StorageArea) error {
|
||||
query := `INSERT INTO StorageArea (Name, StorageType) VALUES (?, ?);`
|
||||
|
||||
insert, err := db.Prepare(query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = insert.Exec(storageArea.Name, storageArea.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -5,6 +5,17 @@ import (
|
|||
"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 StoreCard(db *sql.DB, storageLocation database.CardStorageLocation) error {
|
||||
lastPosition, err := database.GetLastPositionInBox(db, storageLocation.StorageBox)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue