mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-24 22:39:14 +01:00
* Remove documents table (WIP) * Further cleanup of documents table * This should clean up the errors, but actual attachment handling still needs added. * Full generation to update the JS side of things too * Further fixes * Fix cyclic dependency issue * In theory the API side works now * Fix go linting issues * Fix frontend issues * Way closer, but has a foreign key constrant issue * UI actually works now * Fix deduplication feature not working right * Upgrade to `golangci-lint` v2 file * Add ability to set primary during attachment creation * Update swagger with new primary attachment during creation stuff * Files are actually saved now, but there's still a bug * Fix critical issue whith how deletions were working * Fix the byte copy issue * Hopefully everything is fixed now * Fix golangci-lint config and lint files * Fix lint issue * Fix a few more tests * Fix lint issues again * More minor test fixes * Update backend/internal/core/services/service_items_attachments.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix migration (I think) * Fixed postgres migration * Change some migration options to work better * Some more little things that I tried * Fix merge go.mod * Fix migrations * Little lint thing * Fix AttachmentsList.vue with updated API --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
475 lines
14 KiB
Go
475 lines
14 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/google/uuid"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/attachment"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/item"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate"
|
|
)
|
|
|
|
// AttachmentUpdate is the builder for updating Attachment entities.
|
|
type AttachmentUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AttachmentMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AttachmentUpdate builder.
|
|
func (au *AttachmentUpdate) Where(ps ...predicate.Attachment) *AttachmentUpdate {
|
|
au.mutation.Where(ps...)
|
|
return au
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (au *AttachmentUpdate) SetUpdatedAt(t time.Time) *AttachmentUpdate {
|
|
au.mutation.SetUpdatedAt(t)
|
|
return au
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (au *AttachmentUpdate) SetType(a attachment.Type) *AttachmentUpdate {
|
|
au.mutation.SetType(a)
|
|
return au
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (au *AttachmentUpdate) SetNillableType(a *attachment.Type) *AttachmentUpdate {
|
|
if a != nil {
|
|
au.SetType(*a)
|
|
}
|
|
return au
|
|
}
|
|
|
|
// SetPrimary sets the "primary" field.
|
|
func (au *AttachmentUpdate) SetPrimary(b bool) *AttachmentUpdate {
|
|
au.mutation.SetPrimary(b)
|
|
return au
|
|
}
|
|
|
|
// SetNillablePrimary sets the "primary" field if the given value is not nil.
|
|
func (au *AttachmentUpdate) SetNillablePrimary(b *bool) *AttachmentUpdate {
|
|
if b != nil {
|
|
au.SetPrimary(*b)
|
|
}
|
|
return au
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (au *AttachmentUpdate) SetTitle(s string) *AttachmentUpdate {
|
|
au.mutation.SetTitle(s)
|
|
return au
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (au *AttachmentUpdate) SetNillableTitle(s *string) *AttachmentUpdate {
|
|
if s != nil {
|
|
au.SetTitle(*s)
|
|
}
|
|
return au
|
|
}
|
|
|
|
// SetPath sets the "path" field.
|
|
func (au *AttachmentUpdate) SetPath(s string) *AttachmentUpdate {
|
|
au.mutation.SetPath(s)
|
|
return au
|
|
}
|
|
|
|
// SetNillablePath sets the "path" field if the given value is not nil.
|
|
func (au *AttachmentUpdate) SetNillablePath(s *string) *AttachmentUpdate {
|
|
if s != nil {
|
|
au.SetPath(*s)
|
|
}
|
|
return au
|
|
}
|
|
|
|
// SetItemID sets the "item" edge to the Item entity by ID.
|
|
func (au *AttachmentUpdate) SetItemID(id uuid.UUID) *AttachmentUpdate {
|
|
au.mutation.SetItemID(id)
|
|
return au
|
|
}
|
|
|
|
// SetItem sets the "item" edge to the Item entity.
|
|
func (au *AttachmentUpdate) SetItem(i *Item) *AttachmentUpdate {
|
|
return au.SetItemID(i.ID)
|
|
}
|
|
|
|
// Mutation returns the AttachmentMutation object of the builder.
|
|
func (au *AttachmentUpdate) Mutation() *AttachmentMutation {
|
|
return au.mutation
|
|
}
|
|
|
|
// ClearItem clears the "item" edge to the Item entity.
|
|
func (au *AttachmentUpdate) ClearItem() *AttachmentUpdate {
|
|
au.mutation.ClearItem()
|
|
return au
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (au *AttachmentUpdate) Save(ctx context.Context) (int, error) {
|
|
au.defaults()
|
|
return withHooks(ctx, au.sqlSave, au.mutation, au.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (au *AttachmentUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := au.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (au *AttachmentUpdate) Exec(ctx context.Context) error {
|
|
_, err := au.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (au *AttachmentUpdate) ExecX(ctx context.Context) {
|
|
if err := au.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (au *AttachmentUpdate) defaults() {
|
|
if _, ok := au.mutation.UpdatedAt(); !ok {
|
|
v := attachment.UpdateDefaultUpdatedAt()
|
|
au.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (au *AttachmentUpdate) check() error {
|
|
if v, ok := au.mutation.GetType(); ok {
|
|
if err := attachment.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Attachment.type": %w`, err)}
|
|
}
|
|
}
|
|
if au.mutation.ItemCleared() && len(au.mutation.ItemIDs()) > 0 {
|
|
return errors.New(`ent: clearing a required unique edge "Attachment.item"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (au *AttachmentUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
if err := au.check(); err != nil {
|
|
return n, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
|
|
if ps := au.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := au.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := au.mutation.GetType(); ok {
|
|
_spec.SetField(attachment.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := au.mutation.Primary(); ok {
|
|
_spec.SetField(attachment.FieldPrimary, field.TypeBool, value)
|
|
}
|
|
if value, ok := au.mutation.Title(); ok {
|
|
_spec.SetField(attachment.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := au.mutation.Path(); ok {
|
|
_spec.SetField(attachment.FieldPath, field.TypeString, value)
|
|
}
|
|
if au.mutation.ItemCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: attachment.ItemTable,
|
|
Columns: []string{attachment.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := au.mutation.ItemIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: attachment.ItemTable,
|
|
Columns: []string{attachment.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
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, au.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{attachment.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
au.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// AttachmentUpdateOne is the builder for updating a single Attachment entity.
|
|
type AttachmentUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AttachmentMutation
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (auo *AttachmentUpdateOne) SetUpdatedAt(t time.Time) *AttachmentUpdateOne {
|
|
auo.mutation.SetUpdatedAt(t)
|
|
return auo
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (auo *AttachmentUpdateOne) SetType(a attachment.Type) *AttachmentUpdateOne {
|
|
auo.mutation.SetType(a)
|
|
return auo
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (auo *AttachmentUpdateOne) SetNillableType(a *attachment.Type) *AttachmentUpdateOne {
|
|
if a != nil {
|
|
auo.SetType(*a)
|
|
}
|
|
return auo
|
|
}
|
|
|
|
// SetPrimary sets the "primary" field.
|
|
func (auo *AttachmentUpdateOne) SetPrimary(b bool) *AttachmentUpdateOne {
|
|
auo.mutation.SetPrimary(b)
|
|
return auo
|
|
}
|
|
|
|
// SetNillablePrimary sets the "primary" field if the given value is not nil.
|
|
func (auo *AttachmentUpdateOne) SetNillablePrimary(b *bool) *AttachmentUpdateOne {
|
|
if b != nil {
|
|
auo.SetPrimary(*b)
|
|
}
|
|
return auo
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (auo *AttachmentUpdateOne) SetTitle(s string) *AttachmentUpdateOne {
|
|
auo.mutation.SetTitle(s)
|
|
return auo
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (auo *AttachmentUpdateOne) SetNillableTitle(s *string) *AttachmentUpdateOne {
|
|
if s != nil {
|
|
auo.SetTitle(*s)
|
|
}
|
|
return auo
|
|
}
|
|
|
|
// SetPath sets the "path" field.
|
|
func (auo *AttachmentUpdateOne) SetPath(s string) *AttachmentUpdateOne {
|
|
auo.mutation.SetPath(s)
|
|
return auo
|
|
}
|
|
|
|
// SetNillablePath sets the "path" field if the given value is not nil.
|
|
func (auo *AttachmentUpdateOne) SetNillablePath(s *string) *AttachmentUpdateOne {
|
|
if s != nil {
|
|
auo.SetPath(*s)
|
|
}
|
|
return auo
|
|
}
|
|
|
|
// SetItemID sets the "item" edge to the Item entity by ID.
|
|
func (auo *AttachmentUpdateOne) SetItemID(id uuid.UUID) *AttachmentUpdateOne {
|
|
auo.mutation.SetItemID(id)
|
|
return auo
|
|
}
|
|
|
|
// SetItem sets the "item" edge to the Item entity.
|
|
func (auo *AttachmentUpdateOne) SetItem(i *Item) *AttachmentUpdateOne {
|
|
return auo.SetItemID(i.ID)
|
|
}
|
|
|
|
// Mutation returns the AttachmentMutation object of the builder.
|
|
func (auo *AttachmentUpdateOne) Mutation() *AttachmentMutation {
|
|
return auo.mutation
|
|
}
|
|
|
|
// ClearItem clears the "item" edge to the Item entity.
|
|
func (auo *AttachmentUpdateOne) ClearItem() *AttachmentUpdateOne {
|
|
auo.mutation.ClearItem()
|
|
return auo
|
|
}
|
|
|
|
// Where appends a list predicates to the AttachmentUpdate builder.
|
|
func (auo *AttachmentUpdateOne) Where(ps ...predicate.Attachment) *AttachmentUpdateOne {
|
|
auo.mutation.Where(ps...)
|
|
return auo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (auo *AttachmentUpdateOne) Select(field string, fields ...string) *AttachmentUpdateOne {
|
|
auo.fields = append([]string{field}, fields...)
|
|
return auo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Attachment entity.
|
|
func (auo *AttachmentUpdateOne) Save(ctx context.Context) (*Attachment, error) {
|
|
auo.defaults()
|
|
return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (auo *AttachmentUpdateOne) SaveX(ctx context.Context) *Attachment {
|
|
node, err := auo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (auo *AttachmentUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := auo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (auo *AttachmentUpdateOne) ExecX(ctx context.Context) {
|
|
if err := auo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (auo *AttachmentUpdateOne) defaults() {
|
|
if _, ok := auo.mutation.UpdatedAt(); !ok {
|
|
v := attachment.UpdateDefaultUpdatedAt()
|
|
auo.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (auo *AttachmentUpdateOne) check() error {
|
|
if v, ok := auo.mutation.GetType(); ok {
|
|
if err := attachment.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Attachment.type": %w`, err)}
|
|
}
|
|
}
|
|
if auo.mutation.ItemCleared() && len(auo.mutation.ItemIDs()) > 0 {
|
|
return errors.New(`ent: clearing a required unique edge "Attachment.item"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (auo *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment, err error) {
|
|
if err := auo.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
|
|
id, ok := auo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Attachment.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := auo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, attachment.FieldID)
|
|
for _, f := range fields {
|
|
if !attachment.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != attachment.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := auo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := auo.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := auo.mutation.GetType(); ok {
|
|
_spec.SetField(attachment.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := auo.mutation.Primary(); ok {
|
|
_spec.SetField(attachment.FieldPrimary, field.TypeBool, value)
|
|
}
|
|
if value, ok := auo.mutation.Title(); ok {
|
|
_spec.SetField(attachment.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := auo.mutation.Path(); ok {
|
|
_spec.SetField(attachment.FieldPath, field.TypeString, value)
|
|
}
|
|
if auo.mutation.ItemCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: attachment.ItemTable,
|
|
Columns: []string{attachment.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := auo.mutation.ItemIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: attachment.ItemTable,
|
|
Columns: []string{attachment.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &Attachment{config: auo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{attachment.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
auo.mutation.done = true
|
|
return _node, nil
|
|
}
|