fix create claim

This commit is contained in:
katefort 2025-04-21 20:43:02 -05:00
parent a042866e86
commit fa4561d90b
6 changed files with 44 additions and 28 deletions

View file

@ -7,18 +7,20 @@ import (
"github.com/vingarcia/ksql"
)
func (d *Database) FindProductIDByBarcode(system string, barcode string) (id int, err error) {
func (d *Database) FindProductByBarcode(system string, barcode string) (*Product, error) {
ctx := context.Background()
ctx = ksql.InjectLogger(ctx, ksql.Logger)
err = d.db.QueryOne(ctx, &id, "SELECT id FROM products WHERE system = ? AND barcode = ?", system, barcode)
var product Product
err := d.db.QueryOne(ctx, &product, "FROM products WHERE system = $1 AND barcode = $2", system, barcode)
if err == ksql.ErrRecordNotFound {
return -1, nil
return nil, nil
}
if err != nil {
return -1, err
return nil, err
}
return
return &product, nil
}
func (d *Database) CreateProduct(system string, barcode string) (*Product, error) {