mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 08:10:28 +00:00
add insured and quantity fields for items
This commit is contained in:
parent
16fc2aaa29
commit
6dca8ffdda
16 changed files with 513 additions and 19 deletions
|
@ -49,7 +49,7 @@ const docTemplate = `{
|
|||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/types.ItemOut"
|
||||
"$ref": "#/definitions/types.ItemSummary"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -899,6 +899,9 @@ const docTemplate = `{
|
|||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"insured": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"labels": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
@ -936,6 +939,9 @@ const docTemplate = `{
|
|||
"description": "Purchase",
|
||||
"type": "string"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "integer"
|
||||
},
|
||||
"serialNumber": {
|
||||
"description": "Identifications",
|
||||
"type": "string"
|
||||
|
@ -976,6 +982,9 @@ const docTemplate = `{
|
|||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"insured": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"labels": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
@ -1013,6 +1022,9 @@ const docTemplate = `{
|
|||
"description": "Purchase",
|
||||
"type": "string"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "integer"
|
||||
},
|
||||
"serialNumber": {
|
||||
"description": "Identifications",
|
||||
"type": "string"
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/types.ItemOut"
|
||||
"$ref": "#/definitions/types.ItemSummary"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -891,6 +891,9 @@
|
|||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"insured": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"labels": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
@ -928,6 +931,9 @@
|
|||
"description": "Purchase",
|
||||
"type": "string"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "integer"
|
||||
},
|
||||
"serialNumber": {
|
||||
"description": "Identifications",
|
||||
"type": "string"
|
||||
|
@ -968,6 +974,9 @@
|
|||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"insured": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"labels": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
@ -1005,6 +1014,9 @@
|
|||
"description": "Purchase",
|
||||
"type": "string"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "integer"
|
||||
},
|
||||
"serialNumber": {
|
||||
"description": "Identifications",
|
||||
"type": "string"
|
||||
|
|
|
@ -73,6 +73,8 @@ definitions:
|
|||
type: string
|
||||
id:
|
||||
type: string
|
||||
insured:
|
||||
type: boolean
|
||||
labels:
|
||||
items:
|
||||
$ref: '#/definitions/types.LabelSummary'
|
||||
|
@ -99,6 +101,8 @@ definitions:
|
|||
purchaseTime:
|
||||
description: Purchase
|
||||
type: string
|
||||
quantity:
|
||||
type: integer
|
||||
serialNumber:
|
||||
description: Identifications
|
||||
type: string
|
||||
|
@ -126,6 +130,8 @@ definitions:
|
|||
type: string
|
||||
id:
|
||||
type: string
|
||||
insured:
|
||||
type: boolean
|
||||
labels:
|
||||
items:
|
||||
$ref: '#/definitions/types.LabelSummary'
|
||||
|
@ -152,6 +158,8 @@ definitions:
|
|||
purchaseTime:
|
||||
description: Purchase
|
||||
type: string
|
||||
quantity:
|
||||
type: integer
|
||||
serialNumber:
|
||||
description: Identifications
|
||||
type: string
|
||||
|
@ -335,7 +343,7 @@ paths:
|
|||
- properties:
|
||||
items:
|
||||
items:
|
||||
$ref: '#/definitions/types.ItemOut'
|
||||
$ref: '#/definitions/types.ItemSummary'
|
||||
type: array
|
||||
type: object
|
||||
security:
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
// @Summary Get All Items
|
||||
// @Tags Items
|
||||
// @Produce json
|
||||
// @Success 200 {object} server.Results{items=[]types.ItemOut}
|
||||
// @Success 200 {object} server.Results{items=[]types.ItemSummary}
|
||||
// @Router /v1/items [GET]
|
||||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleItemsGetAll() http.HandlerFunc {
|
||||
|
|
|
@ -29,6 +29,10 @@ type Item struct {
|
|||
Description string `json:"description,omitempty"`
|
||||
// Notes holds the value of the "notes" field.
|
||||
Notes string `json:"notes,omitempty"`
|
||||
// Quantity holds the value of the "quantity" field.
|
||||
Quantity int `json:"quantity,omitempty"`
|
||||
// Insured holds the value of the "insured" field.
|
||||
Insured bool `json:"insured,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.
|
||||
|
@ -137,10 +141,12 @@ func (*Item) scanValues(columns []string) ([]interface{}, error) {
|
|||
values := make([]interface{}, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case item.FieldLifetimeWarranty:
|
||||
case item.FieldInsured, item.FieldLifetimeWarranty:
|
||||
values[i] = new(sql.NullBool)
|
||||
case item.FieldPurchasePrice, item.FieldSoldPrice:
|
||||
values[i] = new(sql.NullFloat64)
|
||||
case item.FieldQuantity:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case item.FieldName, item.FieldDescription, item.FieldNotes, item.FieldSerialNumber, item.FieldModelNumber, item.FieldManufacturer, item.FieldWarrantyDetails, item.FieldPurchaseFrom, item.FieldSoldTo, item.FieldSoldNotes:
|
||||
values[i] = new(sql.NullString)
|
||||
case item.FieldCreatedAt, item.FieldUpdatedAt, item.FieldWarrantyExpires, item.FieldPurchaseTime, item.FieldSoldTime:
|
||||
|
@ -202,6 +208,18 @@ func (i *Item) assignValues(columns []string, values []interface{}) error {
|
|||
} else if value.Valid {
|
||||
i.Notes = value.String
|
||||
}
|
||||
case item.FieldQuantity:
|
||||
if value, ok := values[j].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field quantity", values[j])
|
||||
} else if value.Valid {
|
||||
i.Quantity = int(value.Int64)
|
||||
}
|
||||
case item.FieldInsured:
|
||||
if value, ok := values[j].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field insured", values[j])
|
||||
} else if value.Valid {
|
||||
i.Insured = value.Bool
|
||||
}
|
||||
case item.FieldSerialNumber:
|
||||
if value, ok := values[j].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field serial_number", values[j])
|
||||
|
@ -362,6 +380,12 @@ func (i *Item) String() string {
|
|||
builder.WriteString("notes=")
|
||||
builder.WriteString(i.Notes)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("quantity=")
|
||||
builder.WriteString(fmt.Sprintf("%v", i.Quantity))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("insured=")
|
||||
builder.WriteString(fmt.Sprintf("%v", i.Insured))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("serial_number=")
|
||||
builder.WriteString(i.SerialNumber)
|
||||
builder.WriteString(", ")
|
||||
|
|
|
@ -23,6 +23,10 @@ const (
|
|||
FieldDescription = "description"
|
||||
// FieldNotes holds the string denoting the notes field in the database.
|
||||
FieldNotes = "notes"
|
||||
// FieldQuantity holds the string denoting the quantity field in the database.
|
||||
FieldQuantity = "quantity"
|
||||
// FieldInsured holds the string denoting the insured field in the database.
|
||||
FieldInsured = "insured"
|
||||
// FieldSerialNumber holds the string denoting the serial_number field in the database.
|
||||
FieldSerialNumber = "serial_number"
|
||||
// FieldModelNumber holds the string denoting the model_number field in the database.
|
||||
|
@ -104,6 +108,8 @@ var Columns = []string{
|
|||
FieldName,
|
||||
FieldDescription,
|
||||
FieldNotes,
|
||||
FieldQuantity,
|
||||
FieldInsured,
|
||||
FieldSerialNumber,
|
||||
FieldModelNumber,
|
||||
FieldManufacturer,
|
||||
|
@ -160,6 +166,10 @@ var (
|
|||
DescriptionValidator func(string) error
|
||||
// NotesValidator is a validator for the "notes" field. It is called by the builders before save.
|
||||
NotesValidator func(string) error
|
||||
// DefaultQuantity holds the default value on creation for the "quantity" field.
|
||||
DefaultQuantity int
|
||||
// DefaultInsured holds the default value on creation for the "insured" field.
|
||||
DefaultInsured bool
|
||||
// SerialNumberValidator is a validator for the "serial_number" field. It is called by the builders before save.
|
||||
SerialNumberValidator func(string) error
|
||||
// ModelNumberValidator is a validator for the "model_number" field. It is called by the builders before save.
|
||||
|
|
|
@ -117,6 +117,20 @@ func Notes(v string) predicate.Item {
|
|||
})
|
||||
}
|
||||
|
||||
// Quantity applies equality check predicate on the "quantity" field. It's identical to QuantityEQ.
|
||||
func Quantity(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldQuantity), v))
|
||||
})
|
||||
}
|
||||
|
||||
// Insured applies equality check predicate on the "insured" field. It's identical to InsuredEQ.
|
||||
func Insured(v bool) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldInsured), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SerialNumber applies equality check predicate on the "serial_number" field. It's identical to SerialNumberEQ.
|
||||
func SerialNumber(v string) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
|
@ -661,6 +675,84 @@ func NotesContainsFold(v string) predicate.Item {
|
|||
})
|
||||
}
|
||||
|
||||
// QuantityEQ applies the EQ predicate on the "quantity" field.
|
||||
func QuantityEQ(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldQuantity), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QuantityNEQ applies the NEQ predicate on the "quantity" field.
|
||||
func QuantityNEQ(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldQuantity), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QuantityIn applies the In predicate on the "quantity" field.
|
||||
func QuantityIn(vs ...int) predicate.Item {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.In(s.C(FieldQuantity), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// QuantityNotIn applies the NotIn predicate on the "quantity" field.
|
||||
func QuantityNotIn(vs ...int) predicate.Item {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.NotIn(s.C(FieldQuantity), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// QuantityGT applies the GT predicate on the "quantity" field.
|
||||
func QuantityGT(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldQuantity), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QuantityGTE applies the GTE predicate on the "quantity" field.
|
||||
func QuantityGTE(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldQuantity), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QuantityLT applies the LT predicate on the "quantity" field.
|
||||
func QuantityLT(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldQuantity), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QuantityLTE applies the LTE predicate on the "quantity" field.
|
||||
func QuantityLTE(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldQuantity), v))
|
||||
})
|
||||
}
|
||||
|
||||
// InsuredEQ applies the EQ predicate on the "insured" field.
|
||||
func InsuredEQ(v bool) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldInsured), v))
|
||||
})
|
||||
}
|
||||
|
||||
// InsuredNEQ applies the NEQ predicate on the "insured" field.
|
||||
func InsuredNEQ(v bool) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldInsured), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SerialNumberEQ applies the EQ predicate on the "serial_number" field.
|
||||
func SerialNumberEQ(v string) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
|
|
|
@ -88,6 +88,34 @@ func (ic *ItemCreate) SetNillableNotes(s *string) *ItemCreate {
|
|||
return ic
|
||||
}
|
||||
|
||||
// SetQuantity sets the "quantity" field.
|
||||
func (ic *ItemCreate) SetQuantity(i int) *ItemCreate {
|
||||
ic.mutation.SetQuantity(i)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
|
||||
func (ic *ItemCreate) SetNillableQuantity(i *int) *ItemCreate {
|
||||
if i != nil {
|
||||
ic.SetQuantity(*i)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetInsured sets the "insured" field.
|
||||
func (ic *ItemCreate) SetInsured(b bool) *ItemCreate {
|
||||
ic.mutation.SetInsured(b)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableInsured sets the "insured" field if the given value is not nil.
|
||||
func (ic *ItemCreate) SetNillableInsured(b *bool) *ItemCreate {
|
||||
if b != nil {
|
||||
ic.SetInsured(*b)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetSerialNumber sets the "serial_number" field.
|
||||
func (ic *ItemCreate) SetSerialNumber(s string) *ItemCreate {
|
||||
ic.mutation.SetSerialNumber(s)
|
||||
|
@ -444,6 +472,14 @@ func (ic *ItemCreate) defaults() {
|
|||
v := item.DefaultUpdatedAt()
|
||||
ic.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
if _, ok := ic.mutation.Quantity(); !ok {
|
||||
v := item.DefaultQuantity
|
||||
ic.mutation.SetQuantity(v)
|
||||
}
|
||||
if _, ok := ic.mutation.Insured(); !ok {
|
||||
v := item.DefaultInsured
|
||||
ic.mutation.SetInsured(v)
|
||||
}
|
||||
if _, ok := ic.mutation.LifetimeWarranty(); !ok {
|
||||
v := item.DefaultLifetimeWarranty
|
||||
ic.mutation.SetLifetimeWarranty(v)
|
||||
|
@ -488,6 +524,12 @@ func (ic *ItemCreate) check() error {
|
|||
return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "Item.notes": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := ic.mutation.Quantity(); !ok {
|
||||
return &ValidationError{Name: "quantity", err: errors.New(`ent: missing required field "Item.quantity"`)}
|
||||
}
|
||||
if _, ok := ic.mutation.Insured(); !ok {
|
||||
return &ValidationError{Name: "insured", err: errors.New(`ent: missing required field "Item.insured"`)}
|
||||
}
|
||||
if v, ok := ic.mutation.SerialNumber(); ok {
|
||||
if err := item.SerialNumberValidator(v); err != nil {
|
||||
return &ValidationError{Name: "serial_number", err: fmt.Errorf(`ent: validator failed for field "Item.serial_number": %w`, err)}
|
||||
|
@ -601,6 +643,22 @@ func (ic *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) {
|
|||
})
|
||||
_node.Notes = value
|
||||
}
|
||||
if value, ok := ic.mutation.Quantity(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
_node.Quantity = value
|
||||
}
|
||||
if value, ok := ic.mutation.Insured(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldInsured,
|
||||
})
|
||||
_node.Insured = value
|
||||
}
|
||||
if value, ok := ic.mutation.SerialNumber(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
|
|
|
@ -86,6 +86,41 @@ func (iu *ItemUpdate) ClearNotes() *ItemUpdate {
|
|||
return iu
|
||||
}
|
||||
|
||||
// SetQuantity sets the "quantity" field.
|
||||
func (iu *ItemUpdate) SetQuantity(i int) *ItemUpdate {
|
||||
iu.mutation.ResetQuantity()
|
||||
iu.mutation.SetQuantity(i)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
|
||||
func (iu *ItemUpdate) SetNillableQuantity(i *int) *ItemUpdate {
|
||||
if i != nil {
|
||||
iu.SetQuantity(*i)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// AddQuantity adds i to the "quantity" field.
|
||||
func (iu *ItemUpdate) AddQuantity(i int) *ItemUpdate {
|
||||
iu.mutation.AddQuantity(i)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetInsured sets the "insured" field.
|
||||
func (iu *ItemUpdate) SetInsured(b bool) *ItemUpdate {
|
||||
iu.mutation.SetInsured(b)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableInsured sets the "insured" field if the given value is not nil.
|
||||
func (iu *ItemUpdate) SetNillableInsured(b *bool) *ItemUpdate {
|
||||
if b != nil {
|
||||
iu.SetInsured(*b)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetSerialNumber sets the "serial_number" field.
|
||||
func (iu *ItemUpdate) SetSerialNumber(s string) *ItemUpdate {
|
||||
iu.mutation.SetSerialNumber(s)
|
||||
|
@ -672,6 +707,27 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
Column: item.FieldNotes,
|
||||
})
|
||||
}
|
||||
if value, ok := iu.mutation.Quantity(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
}
|
||||
if value, ok := iu.mutation.AddedQuantity(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
}
|
||||
if value, ok := iu.mutation.Insured(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldInsured,
|
||||
})
|
||||
}
|
||||
if value, ok := iu.mutation.SerialNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
|
@ -1140,6 +1196,41 @@ func (iuo *ItemUpdateOne) ClearNotes() *ItemUpdateOne {
|
|||
return iuo
|
||||
}
|
||||
|
||||
// SetQuantity sets the "quantity" field.
|
||||
func (iuo *ItemUpdateOne) SetQuantity(i int) *ItemUpdateOne {
|
||||
iuo.mutation.ResetQuantity()
|
||||
iuo.mutation.SetQuantity(i)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
|
||||
func (iuo *ItemUpdateOne) SetNillableQuantity(i *int) *ItemUpdateOne {
|
||||
if i != nil {
|
||||
iuo.SetQuantity(*i)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// AddQuantity adds i to the "quantity" field.
|
||||
func (iuo *ItemUpdateOne) AddQuantity(i int) *ItemUpdateOne {
|
||||
iuo.mutation.AddQuantity(i)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetInsured sets the "insured" field.
|
||||
func (iuo *ItemUpdateOne) SetInsured(b bool) *ItemUpdateOne {
|
||||
iuo.mutation.SetInsured(b)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableInsured sets the "insured" field if the given value is not nil.
|
||||
func (iuo *ItemUpdateOne) SetNillableInsured(b *bool) *ItemUpdateOne {
|
||||
if b != nil {
|
||||
iuo.SetInsured(*b)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetSerialNumber sets the "serial_number" field.
|
||||
func (iuo *ItemUpdateOne) SetSerialNumber(s string) *ItemUpdateOne {
|
||||
iuo.mutation.SetSerialNumber(s)
|
||||
|
@ -1756,6 +1847,27 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error)
|
|||
Column: item.FieldNotes,
|
||||
})
|
||||
}
|
||||
if value, ok := iuo.mutation.Quantity(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
}
|
||||
if value, ok := iuo.mutation.AddedQuantity(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
}
|
||||
if value, ok := iuo.mutation.Insured(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldInsured,
|
||||
})
|
||||
}
|
||||
if value, ok := iuo.mutation.SerialNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
|
|
|
@ -143,6 +143,8 @@ var (
|
|||
{Name: "name", Type: field.TypeString, Size: 255},
|
||||
{Name: "description", Type: field.TypeString, Nullable: true, Size: 1000},
|
||||
{Name: "notes", Type: field.TypeString, Nullable: true, Size: 1000},
|
||||
{Name: "quantity", Type: field.TypeInt, Default: 1},
|
||||
{Name: "insured", Type: field.TypeBool, Default: false},
|
||||
{Name: "serial_number", Type: field.TypeString, Nullable: true, Size: 255},
|
||||
{Name: "model_number", Type: field.TypeString, Nullable: true, Size: 255},
|
||||
{Name: "manufacturer", Type: field.TypeString, Nullable: true, Size: 255},
|
||||
|
@ -167,13 +169,13 @@ var (
|
|||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "items_groups_items",
|
||||
Columns: []*schema.Column{ItemsColumns[19]},
|
||||
Columns: []*schema.Column{ItemsColumns[21]},
|
||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "items_locations_items",
|
||||
Columns: []*schema.Column{ItemsColumns[20]},
|
||||
Columns: []*schema.Column{ItemsColumns[22]},
|
||||
RefColumns: []*schema.Column{LocationsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
|
@ -187,17 +189,17 @@ var (
|
|||
{
|
||||
Name: "item_manufacturer",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{ItemsColumns[8]},
|
||||
Columns: []*schema.Column{ItemsColumns[10]},
|
||||
},
|
||||
{
|
||||
Name: "item_model_number",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{ItemsColumns[7]},
|
||||
Columns: []*schema.Column{ItemsColumns[9]},
|
||||
},
|
||||
{
|
||||
Name: "item_serial_number",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{ItemsColumns[6]},
|
||||
Columns: []*schema.Column{ItemsColumns[8]},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -3414,6 +3414,9 @@ type ItemMutation struct {
|
|||
name *string
|
||||
description *string
|
||||
notes *string
|
||||
quantity *int
|
||||
addquantity *int
|
||||
insured *bool
|
||||
serial_number *string
|
||||
model_number *string
|
||||
manufacturer *string
|
||||
|
@ -3758,6 +3761,98 @@ func (m *ItemMutation) ResetNotes() {
|
|||
delete(m.clearedFields, item.FieldNotes)
|
||||
}
|
||||
|
||||
// SetQuantity sets the "quantity" field.
|
||||
func (m *ItemMutation) SetQuantity(i int) {
|
||||
m.quantity = &i
|
||||
m.addquantity = nil
|
||||
}
|
||||
|
||||
// Quantity returns the value of the "quantity" field in the mutation.
|
||||
func (m *ItemMutation) Quantity() (r int, exists bool) {
|
||||
v := m.quantity
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldQuantity returns the old "quantity" field's value of the Item entity.
|
||||
// If the Item object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ItemMutation) OldQuantity(ctx context.Context) (v int, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldQuantity is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldQuantity requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldQuantity: %w", err)
|
||||
}
|
||||
return oldValue.Quantity, nil
|
||||
}
|
||||
|
||||
// AddQuantity adds i to the "quantity" field.
|
||||
func (m *ItemMutation) AddQuantity(i int) {
|
||||
if m.addquantity != nil {
|
||||
*m.addquantity += i
|
||||
} else {
|
||||
m.addquantity = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedQuantity returns the value that was added to the "quantity" field in this mutation.
|
||||
func (m *ItemMutation) AddedQuantity() (r int, exists bool) {
|
||||
v := m.addquantity
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ResetQuantity resets all changes to the "quantity" field.
|
||||
func (m *ItemMutation) ResetQuantity() {
|
||||
m.quantity = nil
|
||||
m.addquantity = nil
|
||||
}
|
||||
|
||||
// SetInsured sets the "insured" field.
|
||||
func (m *ItemMutation) SetInsured(b bool) {
|
||||
m.insured = &b
|
||||
}
|
||||
|
||||
// Insured returns the value of the "insured" field in the mutation.
|
||||
func (m *ItemMutation) Insured() (r bool, exists bool) {
|
||||
v := m.insured
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldInsured returns the old "insured" field's value of the Item entity.
|
||||
// If the Item object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ItemMutation) OldInsured(ctx context.Context) (v bool, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldInsured is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldInsured requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldInsured: %w", err)
|
||||
}
|
||||
return oldValue.Insured, nil
|
||||
}
|
||||
|
||||
// ResetInsured resets all changes to the "insured" field.
|
||||
func (m *ItemMutation) ResetInsured() {
|
||||
m.insured = nil
|
||||
}
|
||||
|
||||
// SetSerialNumber sets the "serial_number" field.
|
||||
func (m *ItemMutation) SetSerialNumber(s string) {
|
||||
m.serial_number = &s
|
||||
|
@ -4655,7 +4750,7 @@ func (m *ItemMutation) Type() string {
|
|||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *ItemMutation) Fields() []string {
|
||||
fields := make([]string, 0, 18)
|
||||
fields := make([]string, 0, 20)
|
||||
if m.created_at != nil {
|
||||
fields = append(fields, item.FieldCreatedAt)
|
||||
}
|
||||
|
@ -4671,6 +4766,12 @@ func (m *ItemMutation) Fields() []string {
|
|||
if m.notes != nil {
|
||||
fields = append(fields, item.FieldNotes)
|
||||
}
|
||||
if m.quantity != nil {
|
||||
fields = append(fields, item.FieldQuantity)
|
||||
}
|
||||
if m.insured != nil {
|
||||
fields = append(fields, item.FieldInsured)
|
||||
}
|
||||
if m.serial_number != nil {
|
||||
fields = append(fields, item.FieldSerialNumber)
|
||||
}
|
||||
|
@ -4728,6 +4829,10 @@ func (m *ItemMutation) Field(name string) (ent.Value, bool) {
|
|||
return m.Description()
|
||||
case item.FieldNotes:
|
||||
return m.Notes()
|
||||
case item.FieldQuantity:
|
||||
return m.Quantity()
|
||||
case item.FieldInsured:
|
||||
return m.Insured()
|
||||
case item.FieldSerialNumber:
|
||||
return m.SerialNumber()
|
||||
case item.FieldModelNumber:
|
||||
|
@ -4773,6 +4878,10 @@ func (m *ItemMutation) OldField(ctx context.Context, name string) (ent.Value, er
|
|||
return m.OldDescription(ctx)
|
||||
case item.FieldNotes:
|
||||
return m.OldNotes(ctx)
|
||||
case item.FieldQuantity:
|
||||
return m.OldQuantity(ctx)
|
||||
case item.FieldInsured:
|
||||
return m.OldInsured(ctx)
|
||||
case item.FieldSerialNumber:
|
||||
return m.OldSerialNumber(ctx)
|
||||
case item.FieldModelNumber:
|
||||
|
@ -4843,6 +4952,20 @@ func (m *ItemMutation) SetField(name string, value ent.Value) error {
|
|||
}
|
||||
m.SetNotes(v)
|
||||
return nil
|
||||
case item.FieldQuantity:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetQuantity(v)
|
||||
return nil
|
||||
case item.FieldInsured:
|
||||
v, ok := value.(bool)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetInsured(v)
|
||||
return nil
|
||||
case item.FieldSerialNumber:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
|
@ -4942,6 +5065,9 @@ func (m *ItemMutation) SetField(name string, value ent.Value) error {
|
|||
// this mutation.
|
||||
func (m *ItemMutation) AddedFields() []string {
|
||||
var fields []string
|
||||
if m.addquantity != nil {
|
||||
fields = append(fields, item.FieldQuantity)
|
||||
}
|
||||
if m.addpurchase_price != nil {
|
||||
fields = append(fields, item.FieldPurchasePrice)
|
||||
}
|
||||
|
@ -4956,6 +5082,8 @@ func (m *ItemMutation) AddedFields() []string {
|
|||
// was not set, or was not defined in the schema.
|
||||
func (m *ItemMutation) AddedField(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case item.FieldQuantity:
|
||||
return m.AddedQuantity()
|
||||
case item.FieldPurchasePrice:
|
||||
return m.AddedPurchasePrice()
|
||||
case item.FieldSoldPrice:
|
||||
|
@ -4969,6 +5097,13 @@ func (m *ItemMutation) AddedField(name string) (ent.Value, bool) {
|
|||
// type.
|
||||
func (m *ItemMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case item.FieldQuantity:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddQuantity(v)
|
||||
return nil
|
||||
case item.FieldPurchasePrice:
|
||||
v, ok := value.(float64)
|
||||
if !ok {
|
||||
|
@ -5100,6 +5235,12 @@ func (m *ItemMutation) ResetField(name string) error {
|
|||
case item.FieldNotes:
|
||||
m.ResetNotes()
|
||||
return nil
|
||||
case item.FieldQuantity:
|
||||
m.ResetQuantity()
|
||||
return nil
|
||||
case item.FieldInsured:
|
||||
m.ResetInsured()
|
||||
return nil
|
||||
case item.FieldSerialNumber:
|
||||
m.ResetSerialNumber()
|
||||
return nil
|
||||
|
|
|
@ -231,36 +231,44 @@ func init() {
|
|||
itemDescNotes := itemFields[0].Descriptor()
|
||||
// item.NotesValidator is a validator for the "notes" field. It is called by the builders before save.
|
||||
item.NotesValidator = itemDescNotes.Validators[0].(func(string) error)
|
||||
// itemDescQuantity is the schema descriptor for quantity field.
|
||||
itemDescQuantity := itemFields[1].Descriptor()
|
||||
// item.DefaultQuantity holds the default value on creation for the quantity field.
|
||||
item.DefaultQuantity = itemDescQuantity.Default.(int)
|
||||
// itemDescInsured is the schema descriptor for insured field.
|
||||
itemDescInsured := itemFields[2].Descriptor()
|
||||
// item.DefaultInsured holds the default value on creation for the insured field.
|
||||
item.DefaultInsured = itemDescInsured.Default.(bool)
|
||||
// itemDescSerialNumber is the schema descriptor for serial_number field.
|
||||
itemDescSerialNumber := itemFields[1].Descriptor()
|
||||
itemDescSerialNumber := itemFields[3].Descriptor()
|
||||
// item.SerialNumberValidator is a validator for the "serial_number" field. It is called by the builders before save.
|
||||
item.SerialNumberValidator = itemDescSerialNumber.Validators[0].(func(string) error)
|
||||
// itemDescModelNumber is the schema descriptor for model_number field.
|
||||
itemDescModelNumber := itemFields[2].Descriptor()
|
||||
itemDescModelNumber := itemFields[4].Descriptor()
|
||||
// item.ModelNumberValidator is a validator for the "model_number" field. It is called by the builders before save.
|
||||
item.ModelNumberValidator = itemDescModelNumber.Validators[0].(func(string) error)
|
||||
// itemDescManufacturer is the schema descriptor for manufacturer field.
|
||||
itemDescManufacturer := itemFields[3].Descriptor()
|
||||
itemDescManufacturer := itemFields[5].Descriptor()
|
||||
// item.ManufacturerValidator is a validator for the "manufacturer" field. It is called by the builders before save.
|
||||
item.ManufacturerValidator = itemDescManufacturer.Validators[0].(func(string) error)
|
||||
// itemDescLifetimeWarranty is the schema descriptor for lifetime_warranty field.
|
||||
itemDescLifetimeWarranty := itemFields[4].Descriptor()
|
||||
itemDescLifetimeWarranty := itemFields[6].Descriptor()
|
||||
// item.DefaultLifetimeWarranty holds the default value on creation for the lifetime_warranty field.
|
||||
item.DefaultLifetimeWarranty = itemDescLifetimeWarranty.Default.(bool)
|
||||
// itemDescWarrantyDetails is the schema descriptor for warranty_details field.
|
||||
itemDescWarrantyDetails := itemFields[6].Descriptor()
|
||||
itemDescWarrantyDetails := itemFields[8].Descriptor()
|
||||
// item.WarrantyDetailsValidator is a validator for the "warranty_details" field. It is called by the builders before save.
|
||||
item.WarrantyDetailsValidator = itemDescWarrantyDetails.Validators[0].(func(string) error)
|
||||
// itemDescPurchasePrice is the schema descriptor for purchase_price field.
|
||||
itemDescPurchasePrice := itemFields[9].Descriptor()
|
||||
itemDescPurchasePrice := itemFields[11].Descriptor()
|
||||
// item.DefaultPurchasePrice holds the default value on creation for the purchase_price field.
|
||||
item.DefaultPurchasePrice = itemDescPurchasePrice.Default.(float64)
|
||||
// itemDescSoldPrice is the schema descriptor for sold_price field.
|
||||
itemDescSoldPrice := itemFields[12].Descriptor()
|
||||
itemDescSoldPrice := itemFields[14].Descriptor()
|
||||
// item.DefaultSoldPrice holds the default value on creation for the sold_price field.
|
||||
item.DefaultSoldPrice = itemDescSoldPrice.Default.(float64)
|
||||
// itemDescSoldNotes is the schema descriptor for sold_notes field.
|
||||
itemDescSoldNotes := itemFields[13].Descriptor()
|
||||
itemDescSoldNotes := itemFields[15].Descriptor()
|
||||
// item.SoldNotesValidator is a validator for the "sold_notes" field. It is called by the builders before save.
|
||||
item.SoldNotesValidator = itemDescSoldNotes.Validators[0].(func(string) error)
|
||||
// itemDescID is the schema descriptor for id field.
|
||||
|
|
|
@ -37,6 +37,10 @@ func (Item) Fields() []ent.Field {
|
|||
field.String("notes").
|
||||
MaxLen(1000).
|
||||
Optional(),
|
||||
field.Int("quantity").
|
||||
Default(1),
|
||||
field.Bool("insured").
|
||||
Default(false),
|
||||
|
||||
// ------------------------------------
|
||||
// item identification
|
||||
|
|
|
@ -36,6 +36,9 @@ func ToItemSummary(item *ent.Item) *types.ItemSummary {
|
|||
CreatedAt: item.CreatedAt,
|
||||
UpdatedAt: item.UpdatedAt,
|
||||
|
||||
Quantity: item.Quantity,
|
||||
Insured: item.Insured,
|
||||
|
||||
// Edges
|
||||
Location: location,
|
||||
Labels: labels,
|
||||
|
|
|
@ -19,6 +19,8 @@ type ItemUpdate struct {
|
|||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Quantity int `json:"quantity"`
|
||||
Insured bool `json:"insured"`
|
||||
|
||||
// Edges
|
||||
LocationID uuid.UUID `json:"locationId"`
|
||||
|
@ -56,6 +58,8 @@ type ItemSummary struct {
|
|||
Description string `json:"description"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
Quantity int `json:"quantity"`
|
||||
Insured bool `json:"insured"`
|
||||
|
||||
// Edges
|
||||
Location *LocationSummary `json:"location"`
|
||||
|
|
|
@ -55,6 +55,7 @@ export interface ItemOut {
|
|||
createdAt: Date;
|
||||
description: string;
|
||||
id: string;
|
||||
insured: boolean;
|
||||
labels: LabelSummary[];
|
||||
|
||||
/** Warranty */
|
||||
|
@ -73,6 +74,7 @@ export interface ItemOut {
|
|||
|
||||
/** Purchase */
|
||||
purchaseTime: Date;
|
||||
quantity: number;
|
||||
|
||||
/** Identifications */
|
||||
serialNumber: string;
|
||||
|
@ -91,6 +93,7 @@ export interface ItemSummary {
|
|||
createdAt: Date;
|
||||
description: string;
|
||||
id: string;
|
||||
insured: boolean;
|
||||
labels: LabelSummary[];
|
||||
|
||||
/** Warranty */
|
||||
|
@ -109,6 +112,7 @@ export interface ItemSummary {
|
|||
|
||||
/** Purchase */
|
||||
purchaseTime: Date;
|
||||
quantity: number;
|
||||
|
||||
/** Identifications */
|
||||
serialNumber: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue