mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-24 14:31:55 +01:00
* ent re-generation
* add oidc integration
* document oidc integration
* go fmt
* address backend linter findings
* run prettier on index.vue
* State cookie domain can mismatch when Hostname override is used (breaks CSRF check). Add SameSite.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* Delete state cookie with matching domain and MaxAge; add SameSite.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* Fix endpoint path in comments and error to include /api/v1.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* Also use request context when verifying the ID token.
* Do not return raw auth errors to clients (user-enumeration risk).
* consistently set cookie the same way across function
* remove baseURL after declaration
* only enable OIDC routes if OIDC is enabled
* swagger doc for failure
* Only block when provider=local; move the check after parsing provider
* fix extended session comment
* reduce pii logging
* futher reduce pii logging
* remove unused DiscoveryDocument
* remove unused offline_access from default oidc scopes
* remove offline access from AuthCodeURL
* support host from X-Forwarded-Host
* set sane default claim names if unset
* error strings should not be capitalized
* Revert "run prettier on index.vue"
This reverts commit aa22330a23.
* Add timeout to provider discovery
* Split scopes robustly
* refactor hostname calculation
* address frontend prettier findings
* add property oidc on type APISummary
* LoginOIDC: Normalize inputs, only create if not found
* add oidc email verification
* oidc handleCallback: clear state cookie before each return
* add support for oidc nonce parameter
* Harden first-login race: handle concurrent creates gracefully and fix log key.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* support email verified claim as bool or string
* fail fast on empty email
* PKCE verifier
* fix: add timing delay to attachment test to resolve CI race condition
The attachment test was failing intermittently in CI due to a race condition
between attachment creation and retrieval. Adding a small 100ms delay after
attachment creation ensures the file system and database operations complete
before the test attempts to verify the attachment exists.
* Revert "fix: add timing delay to attachment test to resolve CI race condition"
This reverts commit 4aa8b2a0d829753e8d2dd1ba76f4b1e04e28c45e.
* oidc error state, use ref
* rename oidc.force to oidc.authRedirect
* remove hardcoded oidc error timeout
* feat: sub/iss based identity matching and userinfo endpoint collection
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Matthew Kilgore <matthew@kilgore.dev>
627 lines
18 KiB
Go
Generated
627 lines
18 KiB
Go
Generated
// 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 (_u *AttachmentUpdate) Where(ps ...predicate.Attachment) *AttachmentUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *AttachmentUpdate) SetUpdatedAt(v time.Time) *AttachmentUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *AttachmentUpdate) SetType(v attachment.Type) *AttachmentUpdate {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *AttachmentUpdate) SetNillableType(v *attachment.Type) *AttachmentUpdate {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPrimary sets the "primary" field.
|
|
func (_u *AttachmentUpdate) SetPrimary(v bool) *AttachmentUpdate {
|
|
_u.mutation.SetPrimary(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePrimary sets the "primary" field if the given value is not nil.
|
|
func (_u *AttachmentUpdate) SetNillablePrimary(v *bool) *AttachmentUpdate {
|
|
if v != nil {
|
|
_u.SetPrimary(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (_u *AttachmentUpdate) SetTitle(v string) *AttachmentUpdate {
|
|
_u.mutation.SetTitle(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (_u *AttachmentUpdate) SetNillableTitle(v *string) *AttachmentUpdate {
|
|
if v != nil {
|
|
_u.SetTitle(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPath sets the "path" field.
|
|
func (_u *AttachmentUpdate) SetPath(v string) *AttachmentUpdate {
|
|
_u.mutation.SetPath(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePath sets the "path" field if the given value is not nil.
|
|
func (_u *AttachmentUpdate) SetNillablePath(v *string) *AttachmentUpdate {
|
|
if v != nil {
|
|
_u.SetPath(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMimeType sets the "mime_type" field.
|
|
func (_u *AttachmentUpdate) SetMimeType(v string) *AttachmentUpdate {
|
|
_u.mutation.SetMimeType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMimeType sets the "mime_type" field if the given value is not nil.
|
|
func (_u *AttachmentUpdate) SetNillableMimeType(v *string) *AttachmentUpdate {
|
|
if v != nil {
|
|
_u.SetMimeType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItemID sets the "item" edge to the Item entity by ID.
|
|
func (_u *AttachmentUpdate) SetItemID(id uuid.UUID) *AttachmentUpdate {
|
|
_u.mutation.SetItemID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableItemID sets the "item" edge to the Item entity by ID if the given value is not nil.
|
|
func (_u *AttachmentUpdate) SetNillableItemID(id *uuid.UUID) *AttachmentUpdate {
|
|
if id != nil {
|
|
_u = _u.SetItemID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItem sets the "item" edge to the Item entity.
|
|
func (_u *AttachmentUpdate) SetItem(v *Item) *AttachmentUpdate {
|
|
return _u.SetItemID(v.ID)
|
|
}
|
|
|
|
// SetThumbnailID sets the "thumbnail" edge to the Attachment entity by ID.
|
|
func (_u *AttachmentUpdate) SetThumbnailID(id uuid.UUID) *AttachmentUpdate {
|
|
_u.mutation.SetThumbnailID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableThumbnailID sets the "thumbnail" edge to the Attachment entity by ID if the given value is not nil.
|
|
func (_u *AttachmentUpdate) SetNillableThumbnailID(id *uuid.UUID) *AttachmentUpdate {
|
|
if id != nil {
|
|
_u = _u.SetThumbnailID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetThumbnail sets the "thumbnail" edge to the Attachment entity.
|
|
func (_u *AttachmentUpdate) SetThumbnail(v *Attachment) *AttachmentUpdate {
|
|
return _u.SetThumbnailID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the AttachmentMutation object of the builder.
|
|
func (_u *AttachmentUpdate) Mutation() *AttachmentMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearItem clears the "item" edge to the Item entity.
|
|
func (_u *AttachmentUpdate) ClearItem() *AttachmentUpdate {
|
|
_u.mutation.ClearItem()
|
|
return _u
|
|
}
|
|
|
|
// ClearThumbnail clears the "thumbnail" edge to the Attachment entity.
|
|
func (_u *AttachmentUpdate) ClearThumbnail() *AttachmentUpdate {
|
|
_u.mutation.ClearThumbnail()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *AttachmentUpdate) Save(ctx context.Context) (int, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AttachmentUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *AttachmentUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AttachmentUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *AttachmentUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := attachment.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AttachmentUpdate) check() error {
|
|
if v, ok := _u.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)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *AttachmentUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
_spec.SetField(attachment.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.Primary(); ok {
|
|
_spec.SetField(attachment.FieldPrimary, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Title(); ok {
|
|
_spec.SetField(attachment.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Path(); ok {
|
|
_spec.SetField(attachment.FieldPath, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MimeType(); ok {
|
|
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
|
|
}
|
|
if _u.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 := _u.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 _u.mutation.ThumbnailCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2O,
|
|
Inverse: false,
|
|
Table: attachment.ThumbnailTable,
|
|
Columns: []string{attachment.ThumbnailColumn},
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ThumbnailIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2O,
|
|
Inverse: false,
|
|
Table: attachment.ThumbnailTable,
|
|
Columns: []string{attachment.ThumbnailColumn},
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.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
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, 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 (_u *AttachmentUpdateOne) SetUpdatedAt(v time.Time) *AttachmentUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *AttachmentUpdateOne) SetType(v attachment.Type) *AttachmentUpdateOne {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *AttachmentUpdateOne) SetNillableType(v *attachment.Type) *AttachmentUpdateOne {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPrimary sets the "primary" field.
|
|
func (_u *AttachmentUpdateOne) SetPrimary(v bool) *AttachmentUpdateOne {
|
|
_u.mutation.SetPrimary(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePrimary sets the "primary" field if the given value is not nil.
|
|
func (_u *AttachmentUpdateOne) SetNillablePrimary(v *bool) *AttachmentUpdateOne {
|
|
if v != nil {
|
|
_u.SetPrimary(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (_u *AttachmentUpdateOne) SetTitle(v string) *AttachmentUpdateOne {
|
|
_u.mutation.SetTitle(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (_u *AttachmentUpdateOne) SetNillableTitle(v *string) *AttachmentUpdateOne {
|
|
if v != nil {
|
|
_u.SetTitle(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPath sets the "path" field.
|
|
func (_u *AttachmentUpdateOne) SetPath(v string) *AttachmentUpdateOne {
|
|
_u.mutation.SetPath(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePath sets the "path" field if the given value is not nil.
|
|
func (_u *AttachmentUpdateOne) SetNillablePath(v *string) *AttachmentUpdateOne {
|
|
if v != nil {
|
|
_u.SetPath(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMimeType sets the "mime_type" field.
|
|
func (_u *AttachmentUpdateOne) SetMimeType(v string) *AttachmentUpdateOne {
|
|
_u.mutation.SetMimeType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMimeType sets the "mime_type" field if the given value is not nil.
|
|
func (_u *AttachmentUpdateOne) SetNillableMimeType(v *string) *AttachmentUpdateOne {
|
|
if v != nil {
|
|
_u.SetMimeType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItemID sets the "item" edge to the Item entity by ID.
|
|
func (_u *AttachmentUpdateOne) SetItemID(id uuid.UUID) *AttachmentUpdateOne {
|
|
_u.mutation.SetItemID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableItemID sets the "item" edge to the Item entity by ID if the given value is not nil.
|
|
func (_u *AttachmentUpdateOne) SetNillableItemID(id *uuid.UUID) *AttachmentUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetItemID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItem sets the "item" edge to the Item entity.
|
|
func (_u *AttachmentUpdateOne) SetItem(v *Item) *AttachmentUpdateOne {
|
|
return _u.SetItemID(v.ID)
|
|
}
|
|
|
|
// SetThumbnailID sets the "thumbnail" edge to the Attachment entity by ID.
|
|
func (_u *AttachmentUpdateOne) SetThumbnailID(id uuid.UUID) *AttachmentUpdateOne {
|
|
_u.mutation.SetThumbnailID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableThumbnailID sets the "thumbnail" edge to the Attachment entity by ID if the given value is not nil.
|
|
func (_u *AttachmentUpdateOne) SetNillableThumbnailID(id *uuid.UUID) *AttachmentUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetThumbnailID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetThumbnail sets the "thumbnail" edge to the Attachment entity.
|
|
func (_u *AttachmentUpdateOne) SetThumbnail(v *Attachment) *AttachmentUpdateOne {
|
|
return _u.SetThumbnailID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the AttachmentMutation object of the builder.
|
|
func (_u *AttachmentUpdateOne) Mutation() *AttachmentMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearItem clears the "item" edge to the Item entity.
|
|
func (_u *AttachmentUpdateOne) ClearItem() *AttachmentUpdateOne {
|
|
_u.mutation.ClearItem()
|
|
return _u
|
|
}
|
|
|
|
// ClearThumbnail clears the "thumbnail" edge to the Attachment entity.
|
|
func (_u *AttachmentUpdateOne) ClearThumbnail() *AttachmentUpdateOne {
|
|
_u.mutation.ClearThumbnail()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the AttachmentUpdate builder.
|
|
func (_u *AttachmentUpdateOne) Where(ps ...predicate.Attachment) *AttachmentUpdateOne {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (_u *AttachmentUpdateOne) Select(field string, fields ...string) *AttachmentUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Attachment entity.
|
|
func (_u *AttachmentUpdateOne) Save(ctx context.Context) (*Attachment, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AttachmentUpdateOne) SaveX(ctx context.Context) *Attachment {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *AttachmentUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AttachmentUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *AttachmentUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := attachment.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AttachmentUpdateOne) check() error {
|
|
if v, ok := _u.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)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
|
|
id, ok := _u.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 := _u.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 := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
_spec.SetField(attachment.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.Primary(); ok {
|
|
_spec.SetField(attachment.FieldPrimary, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Title(); ok {
|
|
_spec.SetField(attachment.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Path(); ok {
|
|
_spec.SetField(attachment.FieldPath, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MimeType(); ok {
|
|
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
|
|
}
|
|
if _u.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 := _u.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 _u.mutation.ThumbnailCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2O,
|
|
Inverse: false,
|
|
Table: attachment.ThumbnailTable,
|
|
Columns: []string{attachment.ThumbnailColumn},
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ThumbnailIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2O,
|
|
Inverse: false,
|
|
Table: attachment.ThumbnailTable,
|
|
Columns: []string{attachment.ThumbnailColumn},
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.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: _u.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, _u.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
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|