feat: asset tags/ids (#142)

* add schema

* run db migration

* bulk seed asset IDs

* breaking: update runtime options

* conditionally increment asset IDs

* update API endpoints

* fix import asset id assignment

* refactor display + marshal/unmarshal

* add docs page

* add to form field

* hide 000-000 values

* update ENV vars
This commit is contained in:
Hayden 2022-11-13 14:17:55 -09:00 committed by GitHub
parent 976f68252d
commit 6dc2ae1bea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 905 additions and 72 deletions

View file

@ -37,6 +37,8 @@ type Item struct {
Insured bool `json:"insured,omitempty"`
// Archived holds the value of the "archived" field.
Archived bool `json:"archived,omitempty"`
// AssetID holds the value of the "asset_id" field.
AssetID int `json:"asset_id,omitempty"`
// SerialNumber holds the value of the "serial_number" field.
SerialNumber string `json:"serial_number,omitempty"`
// ModelNumber holds the value of the "model_number" field.
@ -176,7 +178,7 @@ func (*Item) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullBool)
case item.FieldPurchasePrice, item.FieldSoldPrice:
values[i] = new(sql.NullFloat64)
case item.FieldQuantity:
case item.FieldQuantity, item.FieldAssetID:
values[i] = new(sql.NullInt64)
case item.FieldName, item.FieldDescription, item.FieldImportRef, item.FieldNotes, item.FieldSerialNumber, item.FieldModelNumber, item.FieldManufacturer, item.FieldWarrantyDetails, item.FieldPurchaseFrom, item.FieldSoldTo, item.FieldSoldNotes:
values[i] = new(sql.NullString)
@ -265,6 +267,12 @@ func (i *Item) assignValues(columns []string, values []any) error {
} else if value.Valid {
i.Archived = value.Bool
}
case item.FieldAssetID:
if value, ok := values[j].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field asset_id", values[j])
} else if value.Valid {
i.AssetID = int(value.Int64)
}
case item.FieldSerialNumber:
if value, ok := values[j].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field serial_number", values[j])
@ -454,6 +462,9 @@ func (i *Item) String() string {
builder.WriteString("archived=")
builder.WriteString(fmt.Sprintf("%v", i.Archived))
builder.WriteString(", ")
builder.WriteString("asset_id=")
builder.WriteString(fmt.Sprintf("%v", i.AssetID))
builder.WriteString(", ")
builder.WriteString("serial_number=")
builder.WriteString(i.SerialNumber)
builder.WriteString(", ")