forked from mirrors/homebox
31b34241e0
* change /content/ -> /homebox/ * add cache to code generators * update env variables to set data storage * update env variables * set env variables in prod container * implement attachment post route (WIP) * get attachment endpoint * attachment download * implement string utilities lib * implement generic drop zone * use explicit truncate * remove clean dir * drop strings composable for lib * update item types and add attachments * add attachment API * implement service context * consolidate API code * implement editing attachments * implement upload limit configuration * improve error handling * add docs for max upload size * fix test cases
480 lines
13 KiB
Go
480 lines
13 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/hay-kot/homebox/backend/ent/authtokens"
|
|
"github.com/hay-kot/homebox/backend/ent/predicate"
|
|
"github.com/hay-kot/homebox/backend/ent/user"
|
|
)
|
|
|
|
// AuthTokensUpdate is the builder for updating AuthTokens entities.
|
|
type AuthTokensUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AuthTokensMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AuthTokensUpdate builder.
|
|
func (atu *AuthTokensUpdate) Where(ps ...predicate.AuthTokens) *AuthTokensUpdate {
|
|
atu.mutation.Where(ps...)
|
|
return atu
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (atu *AuthTokensUpdate) SetUpdatedAt(t time.Time) *AuthTokensUpdate {
|
|
atu.mutation.SetUpdatedAt(t)
|
|
return atu
|
|
}
|
|
|
|
// SetToken sets the "token" field.
|
|
func (atu *AuthTokensUpdate) SetToken(b []byte) *AuthTokensUpdate {
|
|
atu.mutation.SetToken(b)
|
|
return atu
|
|
}
|
|
|
|
// SetExpiresAt sets the "expires_at" field.
|
|
func (atu *AuthTokensUpdate) SetExpiresAt(t time.Time) *AuthTokensUpdate {
|
|
atu.mutation.SetExpiresAt(t)
|
|
return atu
|
|
}
|
|
|
|
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
|
func (atu *AuthTokensUpdate) SetNillableExpiresAt(t *time.Time) *AuthTokensUpdate {
|
|
if t != nil {
|
|
atu.SetExpiresAt(*t)
|
|
}
|
|
return atu
|
|
}
|
|
|
|
// SetUserID sets the "user" edge to the User entity by ID.
|
|
func (atu *AuthTokensUpdate) SetUserID(id uuid.UUID) *AuthTokensUpdate {
|
|
atu.mutation.SetUserID(id)
|
|
return atu
|
|
}
|
|
|
|
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
|
func (atu *AuthTokensUpdate) SetNillableUserID(id *uuid.UUID) *AuthTokensUpdate {
|
|
if id != nil {
|
|
atu = atu.SetUserID(*id)
|
|
}
|
|
return atu
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (atu *AuthTokensUpdate) SetUser(u *User) *AuthTokensUpdate {
|
|
return atu.SetUserID(u.ID)
|
|
}
|
|
|
|
// Mutation returns the AuthTokensMutation object of the builder.
|
|
func (atu *AuthTokensUpdate) Mutation() *AuthTokensMutation {
|
|
return atu.mutation
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (atu *AuthTokensUpdate) ClearUser() *AuthTokensUpdate {
|
|
atu.mutation.ClearUser()
|
|
return atu
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (atu *AuthTokensUpdate) Save(ctx context.Context) (int, error) {
|
|
var (
|
|
err error
|
|
affected int
|
|
)
|
|
atu.defaults()
|
|
if len(atu.hooks) == 0 {
|
|
affected, err = atu.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*AuthTokensMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
atu.mutation = mutation
|
|
affected, err = atu.sqlSave(ctx)
|
|
mutation.done = true
|
|
return affected, err
|
|
})
|
|
for i := len(atu.hooks) - 1; i >= 0; i-- {
|
|
if atu.hooks[i] == nil {
|
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = atu.hooks[i](mut)
|
|
}
|
|
if _, err := mut.Mutate(ctx, atu.mutation); err != nil {
|
|
return 0, err
|
|
}
|
|
}
|
|
return affected, err
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (atu *AuthTokensUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := atu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (atu *AuthTokensUpdate) Exec(ctx context.Context) error {
|
|
_, err := atu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (atu *AuthTokensUpdate) ExecX(ctx context.Context) {
|
|
if err := atu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (atu *AuthTokensUpdate) defaults() {
|
|
if _, ok := atu.mutation.UpdatedAt(); !ok {
|
|
v := authtokens.UpdateDefaultUpdatedAt()
|
|
atu.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
func (atu *AuthTokensUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: authtokens.Table,
|
|
Columns: authtokens.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeUUID,
|
|
Column: authtokens.FieldID,
|
|
},
|
|
},
|
|
}
|
|
if ps := atu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := atu.mutation.UpdatedAt(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeTime,
|
|
Value: value,
|
|
Column: authtokens.FieldUpdatedAt,
|
|
})
|
|
}
|
|
if value, ok := atu.mutation.Token(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeBytes,
|
|
Value: value,
|
|
Column: authtokens.FieldToken,
|
|
})
|
|
}
|
|
if value, ok := atu.mutation.ExpiresAt(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeTime,
|
|
Value: value,
|
|
Column: authtokens.FieldExpiresAt,
|
|
})
|
|
}
|
|
if atu.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: authtokens.UserTable,
|
|
Columns: []string{authtokens.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeUUID,
|
|
Column: user.FieldID,
|
|
},
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := atu.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: authtokens.UserTable,
|
|
Columns: []string{authtokens.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeUUID,
|
|
Column: user.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, atu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{authtokens.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
return n, nil
|
|
}
|
|
|
|
// AuthTokensUpdateOne is the builder for updating a single AuthTokens entity.
|
|
type AuthTokensUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AuthTokensMutation
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (atuo *AuthTokensUpdateOne) SetUpdatedAt(t time.Time) *AuthTokensUpdateOne {
|
|
atuo.mutation.SetUpdatedAt(t)
|
|
return atuo
|
|
}
|
|
|
|
// SetToken sets the "token" field.
|
|
func (atuo *AuthTokensUpdateOne) SetToken(b []byte) *AuthTokensUpdateOne {
|
|
atuo.mutation.SetToken(b)
|
|
return atuo
|
|
}
|
|
|
|
// SetExpiresAt sets the "expires_at" field.
|
|
func (atuo *AuthTokensUpdateOne) SetExpiresAt(t time.Time) *AuthTokensUpdateOne {
|
|
atuo.mutation.SetExpiresAt(t)
|
|
return atuo
|
|
}
|
|
|
|
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
|
func (atuo *AuthTokensUpdateOne) SetNillableExpiresAt(t *time.Time) *AuthTokensUpdateOne {
|
|
if t != nil {
|
|
atuo.SetExpiresAt(*t)
|
|
}
|
|
return atuo
|
|
}
|
|
|
|
// SetUserID sets the "user" edge to the User entity by ID.
|
|
func (atuo *AuthTokensUpdateOne) SetUserID(id uuid.UUID) *AuthTokensUpdateOne {
|
|
atuo.mutation.SetUserID(id)
|
|
return atuo
|
|
}
|
|
|
|
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
|
func (atuo *AuthTokensUpdateOne) SetNillableUserID(id *uuid.UUID) *AuthTokensUpdateOne {
|
|
if id != nil {
|
|
atuo = atuo.SetUserID(*id)
|
|
}
|
|
return atuo
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (atuo *AuthTokensUpdateOne) SetUser(u *User) *AuthTokensUpdateOne {
|
|
return atuo.SetUserID(u.ID)
|
|
}
|
|
|
|
// Mutation returns the AuthTokensMutation object of the builder.
|
|
func (atuo *AuthTokensUpdateOne) Mutation() *AuthTokensMutation {
|
|
return atuo.mutation
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (atuo *AuthTokensUpdateOne) ClearUser() *AuthTokensUpdateOne {
|
|
atuo.mutation.ClearUser()
|
|
return atuo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (atuo *AuthTokensUpdateOne) Select(field string, fields ...string) *AuthTokensUpdateOne {
|
|
atuo.fields = append([]string{field}, fields...)
|
|
return atuo
|
|
}
|
|
|
|
// Save executes the query and returns the updated AuthTokens entity.
|
|
func (atuo *AuthTokensUpdateOne) Save(ctx context.Context) (*AuthTokens, error) {
|
|
var (
|
|
err error
|
|
node *AuthTokens
|
|
)
|
|
atuo.defaults()
|
|
if len(atuo.hooks) == 0 {
|
|
node, err = atuo.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*AuthTokensMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
atuo.mutation = mutation
|
|
node, err = atuo.sqlSave(ctx)
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(atuo.hooks) - 1; i >= 0; i-- {
|
|
if atuo.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = atuo.hooks[i](mut)
|
|
}
|
|
v, err := mut.Mutate(ctx, atuo.mutation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
nv, ok := v.(*AuthTokens)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected node type %T returned from AuthTokensMutation", v)
|
|
}
|
|
node = nv
|
|
}
|
|
return node, err
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (atuo *AuthTokensUpdateOne) SaveX(ctx context.Context) *AuthTokens {
|
|
node, err := atuo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (atuo *AuthTokensUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := atuo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (atuo *AuthTokensUpdateOne) ExecX(ctx context.Context) {
|
|
if err := atuo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (atuo *AuthTokensUpdateOne) defaults() {
|
|
if _, ok := atuo.mutation.UpdatedAt(); !ok {
|
|
v := authtokens.UpdateDefaultUpdatedAt()
|
|
atuo.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
func (atuo *AuthTokensUpdateOne) sqlSave(ctx context.Context) (_node *AuthTokens, err error) {
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: authtokens.Table,
|
|
Columns: authtokens.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeUUID,
|
|
Column: authtokens.FieldID,
|
|
},
|
|
},
|
|
}
|
|
id, ok := atuo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuthTokens.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := atuo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, authtokens.FieldID)
|
|
for _, f := range fields {
|
|
if !authtokens.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != authtokens.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := atuo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := atuo.mutation.UpdatedAt(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeTime,
|
|
Value: value,
|
|
Column: authtokens.FieldUpdatedAt,
|
|
})
|
|
}
|
|
if value, ok := atuo.mutation.Token(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeBytes,
|
|
Value: value,
|
|
Column: authtokens.FieldToken,
|
|
})
|
|
}
|
|
if value, ok := atuo.mutation.ExpiresAt(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeTime,
|
|
Value: value,
|
|
Column: authtokens.FieldExpiresAt,
|
|
})
|
|
}
|
|
if atuo.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: authtokens.UserTable,
|
|
Columns: []string{authtokens.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeUUID,
|
|
Column: user.FieldID,
|
|
},
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := atuo.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: authtokens.UserTable,
|
|
Columns: []string{authtokens.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeUUID,
|
|
Column: user.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &AuthTokens{config: atuo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, atuo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{authtokens.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
return _node, nil
|
|
}
|