feat: items-editor (#5)

* format readme

* update logo

* format html

* add logo to docs

* repository for document and document tokens

* add attachments type and repository

* autogenerate types via scripts

* use autogenerated types

* attachment type updates

* add insured and quantity fields for items

* implement HasID interface for entities

* implement label updates for items

* implement service update method

* WIP item update client side actions

* check err on attachment

* finish types for basic items editor

* remove unused var

* house keeping
This commit is contained in:
Hayden 2022-09-12 14:47:27 -08:00 committed by GitHub
parent fbc364dcd2
commit 95ab14b866
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
125 changed files with 15626 additions and 1791 deletions

View file

@ -12,6 +12,7 @@ import (
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent/attachment"
"github.com/hay-kot/content/backend/ent/group"
"github.com/hay-kot/content/backend/ent/item"
"github.com/hay-kot/content/backend/ent/itemfield"
@ -85,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)
@ -401,6 +437,21 @@ func (iu *ItemUpdate) AddLabel(l ...*Label) *ItemUpdate {
return iu.AddLabelIDs(ids...)
}
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
func (iu *ItemUpdate) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdate {
iu.mutation.AddAttachmentIDs(ids...)
return iu
}
// AddAttachments adds the "attachments" edges to the Attachment entity.
func (iu *ItemUpdate) AddAttachments(a ...*Attachment) *ItemUpdate {
ids := make([]uuid.UUID, len(a))
for i := range a {
ids[i] = a[i].ID
}
return iu.AddAttachmentIDs(ids...)
}
// Mutation returns the ItemMutation object of the builder.
func (iu *ItemUpdate) Mutation() *ItemMutation {
return iu.mutation
@ -460,6 +511,27 @@ func (iu *ItemUpdate) RemoveLabel(l ...*Label) *ItemUpdate {
return iu.RemoveLabelIDs(ids...)
}
// ClearAttachments clears all "attachments" edges to the Attachment entity.
func (iu *ItemUpdate) ClearAttachments() *ItemUpdate {
iu.mutation.ClearAttachments()
return iu
}
// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs.
func (iu *ItemUpdate) RemoveAttachmentIDs(ids ...uuid.UUID) *ItemUpdate {
iu.mutation.RemoveAttachmentIDs(ids...)
return iu
}
// RemoveAttachments removes "attachments" edges to Attachment entities.
func (iu *ItemUpdate) RemoveAttachments(a ...*Attachment) *ItemUpdate {
ids := make([]uuid.UUID, len(a))
for i := range a {
ids[i] = a[i].ID
}
return iu.RemoveAttachmentIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (iu *ItemUpdate) Save(ctx context.Context) (int, error) {
var (
@ -635,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,
@ -978,6 +1071,60 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if iu.mutation.AttachmentsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: item.AttachmentsTable,
Columns: []string{item.AttachmentsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeUUID,
Column: attachment.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := iu.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !iu.mutation.AttachmentsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: item.AttachmentsTable,
Columns: []string{item.AttachmentsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeUUID,
Column: attachment.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := iu.mutation.AttachmentsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: item.AttachmentsTable,
Columns: []string{item.AttachmentsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeUUID,
Column: attachment.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, iu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{item.Label}
@ -1049,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)
@ -1365,6 +1547,21 @@ func (iuo *ItemUpdateOne) AddLabel(l ...*Label) *ItemUpdateOne {
return iuo.AddLabelIDs(ids...)
}
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
func (iuo *ItemUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdateOne {
iuo.mutation.AddAttachmentIDs(ids...)
return iuo
}
// AddAttachments adds the "attachments" edges to the Attachment entity.
func (iuo *ItemUpdateOne) AddAttachments(a ...*Attachment) *ItemUpdateOne {
ids := make([]uuid.UUID, len(a))
for i := range a {
ids[i] = a[i].ID
}
return iuo.AddAttachmentIDs(ids...)
}
// Mutation returns the ItemMutation object of the builder.
func (iuo *ItemUpdateOne) Mutation() *ItemMutation {
return iuo.mutation
@ -1424,6 +1621,27 @@ func (iuo *ItemUpdateOne) RemoveLabel(l ...*Label) *ItemUpdateOne {
return iuo.RemoveLabelIDs(ids...)
}
// ClearAttachments clears all "attachments" edges to the Attachment entity.
func (iuo *ItemUpdateOne) ClearAttachments() *ItemUpdateOne {
iuo.mutation.ClearAttachments()
return iuo
}
// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs.
func (iuo *ItemUpdateOne) RemoveAttachmentIDs(ids ...uuid.UUID) *ItemUpdateOne {
iuo.mutation.RemoveAttachmentIDs(ids...)
return iuo
}
// RemoveAttachments removes "attachments" edges to Attachment entities.
func (iuo *ItemUpdateOne) RemoveAttachments(a ...*Attachment) *ItemUpdateOne {
ids := make([]uuid.UUID, len(a))
for i := range a {
ids[i] = a[i].ID
}
return iuo.RemoveAttachmentIDs(ids...)
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (iuo *ItemUpdateOne) Select(field string, fields ...string) *ItemUpdateOne {
@ -1629,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,
@ -1972,6 +2211,60 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if iuo.mutation.AttachmentsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: item.AttachmentsTable,
Columns: []string{item.AttachmentsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeUUID,
Column: attachment.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := iuo.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !iuo.mutation.AttachmentsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: item.AttachmentsTable,
Columns: []string{item.AttachmentsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeUUID,
Column: attachment.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := iuo.mutation.AttachmentsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: item.AttachmentsTable,
Columns: []string{item.AttachmentsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeUUID,
Column: attachment.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Item{config: iuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues