diff --git a/backend/internal/data/ent/client.go b/backend/internal/data/ent/client.go index 67a57ef..85ac645 100644 --- a/backend/internal/data/ent/client.go +++ b/backend/internal/data/ent/client.go @@ -15,7 +15,6 @@ import ( "github.com/hay-kot/homebox/backend/internal/data/ent/authroles" "github.com/hay-kot/homebox/backend/internal/data/ent/authtokens" "github.com/hay-kot/homebox/backend/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" "github.com/hay-kot/homebox/backend/internal/data/ent/group" "github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/hay-kot/homebox/backend/internal/data/ent/item" @@ -42,8 +41,6 @@ type Client struct { AuthTokens *AuthTokensClient // Document is the client for interacting with the Document builders. Document *DocumentClient - // DocumentToken is the client for interacting with the DocumentToken builders. - DocumentToken *DocumentTokenClient // Group is the client for interacting with the Group builders. Group *GroupClient // GroupInvitationToken is the client for interacting with the GroupInvitationToken builders. @@ -75,7 +72,6 @@ func (c *Client) init() { c.AuthRoles = NewAuthRolesClient(c.config) c.AuthTokens = NewAuthTokensClient(c.config) c.Document = NewDocumentClient(c.config) - c.DocumentToken = NewDocumentTokenClient(c.config) c.Group = NewGroupClient(c.config) c.GroupInvitationToken = NewGroupInvitationTokenClient(c.config) c.Item = NewItemClient(c.config) @@ -120,7 +116,6 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { AuthRoles: NewAuthRolesClient(cfg), AuthTokens: NewAuthTokensClient(cfg), Document: NewDocumentClient(cfg), - DocumentToken: NewDocumentTokenClient(cfg), Group: NewGroupClient(cfg), GroupInvitationToken: NewGroupInvitationTokenClient(cfg), Item: NewItemClient(cfg), @@ -151,7 +146,6 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) AuthRoles: NewAuthRolesClient(cfg), AuthTokens: NewAuthTokensClient(cfg), Document: NewDocumentClient(cfg), - DocumentToken: NewDocumentTokenClient(cfg), Group: NewGroupClient(cfg), GroupInvitationToken: NewGroupInvitationTokenClient(cfg), Item: NewItemClient(cfg), @@ -191,7 +185,6 @@ func (c *Client) Use(hooks ...Hook) { c.AuthRoles.Use(hooks...) c.AuthTokens.Use(hooks...) c.Document.Use(hooks...) - c.DocumentToken.Use(hooks...) c.Group.Use(hooks...) c.GroupInvitationToken.Use(hooks...) c.Item.Use(hooks...) @@ -652,22 +645,6 @@ func (c *DocumentClient) QueryGroup(d *Document) *GroupQuery { return query } -// QueryDocumentTokens queries the document_tokens edge of a Document. -func (c *DocumentClient) QueryDocumentTokens(d *Document) *DocumentTokenQuery { - query := &DocumentTokenQuery{config: c.config} - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := d.ID - step := sqlgraph.NewStep( - sqlgraph.From(document.Table, document.FieldID, id), - sqlgraph.To(documenttoken.Table, documenttoken.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, document.DocumentTokensTable, document.DocumentTokensColumn), - ) - fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) - return fromV, nil - } - return query -} - // QueryAttachments queries the attachments edge of a Document. func (c *DocumentClient) QueryAttachments(d *Document) *AttachmentQuery { query := &AttachmentQuery{config: c.config} @@ -689,112 +666,6 @@ func (c *DocumentClient) Hooks() []Hook { return c.hooks.Document } -// DocumentTokenClient is a client for the DocumentToken schema. -type DocumentTokenClient struct { - config -} - -// NewDocumentTokenClient returns a client for the DocumentToken from the given config. -func NewDocumentTokenClient(c config) *DocumentTokenClient { - return &DocumentTokenClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `documenttoken.Hooks(f(g(h())))`. -func (c *DocumentTokenClient) Use(hooks ...Hook) { - c.hooks.DocumentToken = append(c.hooks.DocumentToken, hooks...) -} - -// Create returns a builder for creating a DocumentToken entity. -func (c *DocumentTokenClient) Create() *DocumentTokenCreate { - mutation := newDocumentTokenMutation(c.config, OpCreate) - return &DocumentTokenCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of DocumentToken entities. -func (c *DocumentTokenClient) CreateBulk(builders ...*DocumentTokenCreate) *DocumentTokenCreateBulk { - return &DocumentTokenCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for DocumentToken. -func (c *DocumentTokenClient) Update() *DocumentTokenUpdate { - mutation := newDocumentTokenMutation(c.config, OpUpdate) - return &DocumentTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *DocumentTokenClient) UpdateOne(dt *DocumentToken) *DocumentTokenUpdateOne { - mutation := newDocumentTokenMutation(c.config, OpUpdateOne, withDocumentToken(dt)) - return &DocumentTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *DocumentTokenClient) UpdateOneID(id uuid.UUID) *DocumentTokenUpdateOne { - mutation := newDocumentTokenMutation(c.config, OpUpdateOne, withDocumentTokenID(id)) - return &DocumentTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for DocumentToken. -func (c *DocumentTokenClient) Delete() *DocumentTokenDelete { - mutation := newDocumentTokenMutation(c.config, OpDelete) - return &DocumentTokenDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *DocumentTokenClient) DeleteOne(dt *DocumentToken) *DocumentTokenDeleteOne { - return c.DeleteOneID(dt.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *DocumentTokenClient) DeleteOneID(id uuid.UUID) *DocumentTokenDeleteOne { - builder := c.Delete().Where(documenttoken.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &DocumentTokenDeleteOne{builder} -} - -// Query returns a query builder for DocumentToken. -func (c *DocumentTokenClient) Query() *DocumentTokenQuery { - return &DocumentTokenQuery{ - config: c.config, - } -} - -// Get returns a DocumentToken entity by its id. -func (c *DocumentTokenClient) Get(ctx context.Context, id uuid.UUID) (*DocumentToken, error) { - return c.Query().Where(documenttoken.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *DocumentTokenClient) GetX(ctx context.Context, id uuid.UUID) *DocumentToken { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryDocument queries the document edge of a DocumentToken. -func (c *DocumentTokenClient) QueryDocument(dt *DocumentToken) *DocumentQuery { - query := &DocumentQuery{config: c.config} - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := dt.ID - step := sqlgraph.NewStep( - sqlgraph.From(documenttoken.Table, documenttoken.FieldID, id), - sqlgraph.To(document.Table, document.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, documenttoken.DocumentTable, documenttoken.DocumentColumn), - ) - fromV = sqlgraph.Neighbors(dt.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *DocumentTokenClient) Hooks() []Hook { - return c.hooks.DocumentToken -} - // GroupClient is a client for the Group schema. type GroupClient struct { config diff --git a/backend/internal/data/ent/config.go b/backend/internal/data/ent/config.go index e3ce09d..3937124 100644 --- a/backend/internal/data/ent/config.go +++ b/backend/internal/data/ent/config.go @@ -28,7 +28,6 @@ type hooks struct { AuthRoles []ent.Hook AuthTokens []ent.Hook Document []ent.Hook - DocumentToken []ent.Hook Group []ent.Hook GroupInvitationToken []ent.Hook Item []ent.Hook diff --git a/backend/internal/data/ent/document.go b/backend/internal/data/ent/document.go index 0c84d7d..50c1612 100644 --- a/backend/internal/data/ent/document.go +++ b/backend/internal/data/ent/document.go @@ -36,13 +36,11 @@ type Document struct { type DocumentEdges struct { // Group holds the value of the group edge. Group *Group `json:"group,omitempty"` - // DocumentTokens holds the value of the document_tokens edge. - DocumentTokens []*DocumentToken `json:"document_tokens,omitempty"` // Attachments holds the value of the attachments edge. Attachments []*Attachment `json:"attachments,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [3]bool + loadedTypes [2]bool } // GroupOrErr returns the Group value or an error if the edge @@ -58,19 +56,10 @@ func (e DocumentEdges) GroupOrErr() (*Group, error) { return nil, &NotLoadedError{edge: "group"} } -// DocumentTokensOrErr returns the DocumentTokens value or an error if the edge -// was not loaded in eager-loading. -func (e DocumentEdges) DocumentTokensOrErr() ([]*DocumentToken, error) { - if e.loadedTypes[1] { - return e.DocumentTokens, nil - } - return nil, &NotLoadedError{edge: "document_tokens"} -} - // AttachmentsOrErr returns the Attachments value or an error if the edge // was not loaded in eager-loading. func (e DocumentEdges) AttachmentsOrErr() ([]*Attachment, error) { - if e.loadedTypes[2] { + if e.loadedTypes[1] { return e.Attachments, nil } return nil, &NotLoadedError{edge: "attachments"} @@ -151,11 +140,6 @@ func (d *Document) QueryGroup() *GroupQuery { return (&DocumentClient{config: d.config}).QueryGroup(d) } -// QueryDocumentTokens queries the "document_tokens" edge of the Document entity. -func (d *Document) QueryDocumentTokens() *DocumentTokenQuery { - return (&DocumentClient{config: d.config}).QueryDocumentTokens(d) -} - // QueryAttachments queries the "attachments" edge of the Document entity. func (d *Document) QueryAttachments() *AttachmentQuery { return (&DocumentClient{config: d.config}).QueryAttachments(d) diff --git a/backend/internal/data/ent/document/document.go b/backend/internal/data/ent/document/document.go index bfc3881..b6a15eb 100644 --- a/backend/internal/data/ent/document/document.go +++ b/backend/internal/data/ent/document/document.go @@ -23,8 +23,6 @@ const ( FieldPath = "path" // EdgeGroup holds the string denoting the group edge name in mutations. EdgeGroup = "group" - // EdgeDocumentTokens holds the string denoting the document_tokens edge name in mutations. - EdgeDocumentTokens = "document_tokens" // EdgeAttachments holds the string denoting the attachments edge name in mutations. EdgeAttachments = "attachments" // Table holds the table name of the document in the database. @@ -36,13 +34,6 @@ const ( GroupInverseTable = "groups" // GroupColumn is the table column denoting the group relation/edge. GroupColumn = "group_documents" - // DocumentTokensTable is the table that holds the document_tokens relation/edge. - DocumentTokensTable = "document_tokens" - // DocumentTokensInverseTable is the table name for the DocumentToken entity. - // It exists in this package in order to avoid circular dependency with the "documenttoken" package. - DocumentTokensInverseTable = "document_tokens" - // DocumentTokensColumn is the table column denoting the document_tokens relation/edge. - DocumentTokensColumn = "document_document_tokens" // AttachmentsTable is the table that holds the attachments relation/edge. AttachmentsTable = "attachments" // AttachmentsInverseTable is the table name for the Attachment entity. diff --git a/backend/internal/data/ent/document/where.go b/backend/internal/data/ent/document/where.go index dc02fa4..6f1bd69 100644 --- a/backend/internal/data/ent/document/where.go +++ b/backend/internal/data/ent/document/where.go @@ -464,34 +464,6 @@ func HasGroupWith(preds ...predicate.Group) predicate.Document { }) } -// HasDocumentTokens applies the HasEdge predicate on the "document_tokens" edge. -func HasDocumentTokens() predicate.Document { - return predicate.Document(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(DocumentTokensTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, DocumentTokensTable, DocumentTokensColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasDocumentTokensWith applies the HasEdge predicate on the "document_tokens" edge with a given conditions (other predicates). -func HasDocumentTokensWith(preds ...predicate.DocumentToken) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(DocumentTokensInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, DocumentTokensTable, DocumentTokensColumn), - ) - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - // HasAttachments applies the HasEdge predicate on the "attachments" edge. func HasAttachments() predicate.Document { return predicate.Document(func(s *sql.Selector) { diff --git a/backend/internal/data/ent/document_create.go b/backend/internal/data/ent/document_create.go index b3969d6..67b5baa 100644 --- a/backend/internal/data/ent/document_create.go +++ b/backend/internal/data/ent/document_create.go @@ -13,7 +13,6 @@ import ( "github.com/google/uuid" "github.com/hay-kot/homebox/backend/internal/data/ent/attachment" "github.com/hay-kot/homebox/backend/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" "github.com/hay-kot/homebox/backend/internal/data/ent/group" ) @@ -89,21 +88,6 @@ func (dc *DocumentCreate) SetGroup(g *Group) *DocumentCreate { return dc.SetGroupID(g.ID) } -// AddDocumentTokenIDs adds the "document_tokens" edge to the DocumentToken entity by IDs. -func (dc *DocumentCreate) AddDocumentTokenIDs(ids ...uuid.UUID) *DocumentCreate { - dc.mutation.AddDocumentTokenIDs(ids...) - return dc -} - -// AddDocumentTokens adds the "document_tokens" edges to the DocumentToken entity. -func (dc *DocumentCreate) AddDocumentTokens(d ...*DocumentToken) *DocumentCreate { - ids := make([]uuid.UUID, len(d)) - for i := range d { - ids[i] = d[i].ID - } - return dc.AddDocumentTokenIDs(ids...) -} - // AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs. func (dc *DocumentCreate) AddAttachmentIDs(ids ...uuid.UUID) *DocumentCreate { dc.mutation.AddAttachmentIDs(ids...) @@ -309,25 +293,6 @@ func (dc *DocumentCreate) createSpec() (*Document, *sqlgraph.CreateSpec) { _node.group_documents = &nodes[0] _spec.Edges = append(_spec.Edges, edge) } - if nodes := dc.mutation.DocumentTokensIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: document.DocumentTokensTable, - Columns: []string{document.DocumentTokensColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } if nodes := dc.mutation.AttachmentsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/backend/internal/data/ent/document_query.go b/backend/internal/data/ent/document_query.go index 496de53..5ef4f67 100644 --- a/backend/internal/data/ent/document_query.go +++ b/backend/internal/data/ent/document_query.go @@ -14,7 +14,6 @@ import ( "github.com/google/uuid" "github.com/hay-kot/homebox/backend/internal/data/ent/attachment" "github.com/hay-kot/homebox/backend/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" "github.com/hay-kot/homebox/backend/internal/data/ent/group" "github.com/hay-kot/homebox/backend/internal/data/ent/predicate" ) @@ -22,16 +21,15 @@ import ( // DocumentQuery is the builder for querying Document entities. type DocumentQuery struct { config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.Document - withGroup *GroupQuery - withDocumentTokens *DocumentTokenQuery - withAttachments *AttachmentQuery - withFKs bool + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Document + withGroup *GroupQuery + withAttachments *AttachmentQuery + withFKs bool // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -90,28 +88,6 @@ func (dq *DocumentQuery) QueryGroup() *GroupQuery { return query } -// QueryDocumentTokens chains the current query on the "document_tokens" edge. -func (dq *DocumentQuery) QueryDocumentTokens() *DocumentTokenQuery { - query := &DocumentTokenQuery{config: dq.config} - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := dq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := dq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(document.Table, document.FieldID, selector), - sqlgraph.To(documenttoken.Table, documenttoken.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, document.DocumentTokensTable, document.DocumentTokensColumn), - ) - fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step) - return fromU, nil - } - return query -} - // QueryAttachments chains the current query on the "attachments" edge. func (dq *DocumentQuery) QueryAttachments() *AttachmentQuery { query := &AttachmentQuery{config: dq.config} @@ -310,14 +286,13 @@ func (dq *DocumentQuery) Clone() *DocumentQuery { return nil } return &DocumentQuery{ - config: dq.config, - limit: dq.limit, - offset: dq.offset, - order: append([]OrderFunc{}, dq.order...), - predicates: append([]predicate.Document{}, dq.predicates...), - withGroup: dq.withGroup.Clone(), - withDocumentTokens: dq.withDocumentTokens.Clone(), - withAttachments: dq.withAttachments.Clone(), + config: dq.config, + limit: dq.limit, + offset: dq.offset, + order: append([]OrderFunc{}, dq.order...), + predicates: append([]predicate.Document{}, dq.predicates...), + withGroup: dq.withGroup.Clone(), + withAttachments: dq.withAttachments.Clone(), // clone intermediate query. sql: dq.sql.Clone(), path: dq.path, @@ -336,17 +311,6 @@ func (dq *DocumentQuery) WithGroup(opts ...func(*GroupQuery)) *DocumentQuery { return dq } -// WithDocumentTokens tells the query-builder to eager-load the nodes that are connected to -// the "document_tokens" edge. The optional arguments are used to configure the query builder of the edge. -func (dq *DocumentQuery) WithDocumentTokens(opts ...func(*DocumentTokenQuery)) *DocumentQuery { - query := &DocumentTokenQuery{config: dq.config} - for _, opt := range opts { - opt(query) - } - dq.withDocumentTokens = query - return dq -} - // WithAttachments tells the query-builder to eager-load the nodes that are connected to // the "attachments" edge. The optional arguments are used to configure the query builder of the edge. func (dq *DocumentQuery) WithAttachments(opts ...func(*AttachmentQuery)) *DocumentQuery { @@ -432,9 +396,8 @@ func (dq *DocumentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Doc nodes = []*Document{} withFKs = dq.withFKs _spec = dq.querySpec() - loadedTypes = [3]bool{ + loadedTypes = [2]bool{ dq.withGroup != nil, - dq.withDocumentTokens != nil, dq.withAttachments != nil, } ) @@ -468,13 +431,6 @@ func (dq *DocumentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Doc return nil, err } } - if query := dq.withDocumentTokens; query != nil { - if err := dq.loadDocumentTokens(ctx, query, nodes, - func(n *Document) { n.Edges.DocumentTokens = []*DocumentToken{} }, - func(n *Document, e *DocumentToken) { n.Edges.DocumentTokens = append(n.Edges.DocumentTokens, e) }); err != nil { - return nil, err - } - } if query := dq.withAttachments; query != nil { if err := dq.loadAttachments(ctx, query, nodes, func(n *Document) { n.Edges.Attachments = []*Attachment{} }, @@ -514,37 +470,6 @@ func (dq *DocumentQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes } return nil } -func (dq *DocumentQuery) loadDocumentTokens(ctx context.Context, query *DocumentTokenQuery, nodes []*Document, init func(*Document), assign func(*Document, *DocumentToken)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[uuid.UUID]*Document) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - if init != nil { - init(nodes[i]) - } - } - query.withFKs = true - query.Where(predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.InValues(document.DocumentTokensColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.document_document_tokens - if fk == nil { - return fmt.Errorf(`foreign-key "document_document_tokens" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return fmt.Errorf(`unexpected foreign-key "document_document_tokens" returned %v for node %v`, *fk, n.ID) - } - assign(node, n) - } - return nil -} func (dq *DocumentQuery) loadAttachments(ctx context.Context, query *AttachmentQuery, nodes []*Document, init func(*Document), assign func(*Document, *Attachment)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[uuid.UUID]*Document) diff --git a/backend/internal/data/ent/document_update.go b/backend/internal/data/ent/document_update.go index 880df95..4a7ae7e 100644 --- a/backend/internal/data/ent/document_update.go +++ b/backend/internal/data/ent/document_update.go @@ -14,7 +14,6 @@ import ( "github.com/google/uuid" "github.com/hay-kot/homebox/backend/internal/data/ent/attachment" "github.com/hay-kot/homebox/backend/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" "github.com/hay-kot/homebox/backend/internal/data/ent/group" "github.com/hay-kot/homebox/backend/internal/data/ent/predicate" ) @@ -61,21 +60,6 @@ func (du *DocumentUpdate) SetGroup(g *Group) *DocumentUpdate { return du.SetGroupID(g.ID) } -// AddDocumentTokenIDs adds the "document_tokens" edge to the DocumentToken entity by IDs. -func (du *DocumentUpdate) AddDocumentTokenIDs(ids ...uuid.UUID) *DocumentUpdate { - du.mutation.AddDocumentTokenIDs(ids...) - return du -} - -// AddDocumentTokens adds the "document_tokens" edges to the DocumentToken entity. -func (du *DocumentUpdate) AddDocumentTokens(d ...*DocumentToken) *DocumentUpdate { - ids := make([]uuid.UUID, len(d)) - for i := range d { - ids[i] = d[i].ID - } - return du.AddDocumentTokenIDs(ids...) -} - // AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs. func (du *DocumentUpdate) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdate { du.mutation.AddAttachmentIDs(ids...) @@ -102,27 +86,6 @@ func (du *DocumentUpdate) ClearGroup() *DocumentUpdate { return du } -// ClearDocumentTokens clears all "document_tokens" edges to the DocumentToken entity. -func (du *DocumentUpdate) ClearDocumentTokens() *DocumentUpdate { - du.mutation.ClearDocumentTokens() - return du -} - -// RemoveDocumentTokenIDs removes the "document_tokens" edge to DocumentToken entities by IDs. -func (du *DocumentUpdate) RemoveDocumentTokenIDs(ids ...uuid.UUID) *DocumentUpdate { - du.mutation.RemoveDocumentTokenIDs(ids...) - return du -} - -// RemoveDocumentTokens removes "document_tokens" edges to DocumentToken entities. -func (du *DocumentUpdate) RemoveDocumentTokens(d ...*DocumentToken) *DocumentUpdate { - ids := make([]uuid.UUID, len(d)) - for i := range d { - ids[i] = d[i].ID - } - return du.RemoveDocumentTokenIDs(ids...) -} - // ClearAttachments clears all "attachments" edges to the Attachment entity. func (du *DocumentUpdate) ClearAttachments() *DocumentUpdate { du.mutation.ClearAttachments() @@ -293,60 +256,6 @@ func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if du.mutation.DocumentTokensCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: document.DocumentTokensTable, - Columns: []string{document.DocumentTokensColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := du.mutation.RemovedDocumentTokensIDs(); len(nodes) > 0 && !du.mutation.DocumentTokensCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: document.DocumentTokensTable, - Columns: []string{document.DocumentTokensColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := du.mutation.DocumentTokensIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: document.DocumentTokensTable, - Columns: []string{document.DocumentTokensColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } if du.mutation.AttachmentsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -449,21 +358,6 @@ func (duo *DocumentUpdateOne) SetGroup(g *Group) *DocumentUpdateOne { return duo.SetGroupID(g.ID) } -// AddDocumentTokenIDs adds the "document_tokens" edge to the DocumentToken entity by IDs. -func (duo *DocumentUpdateOne) AddDocumentTokenIDs(ids ...uuid.UUID) *DocumentUpdateOne { - duo.mutation.AddDocumentTokenIDs(ids...) - return duo -} - -// AddDocumentTokens adds the "document_tokens" edges to the DocumentToken entity. -func (duo *DocumentUpdateOne) AddDocumentTokens(d ...*DocumentToken) *DocumentUpdateOne { - ids := make([]uuid.UUID, len(d)) - for i := range d { - ids[i] = d[i].ID - } - return duo.AddDocumentTokenIDs(ids...) -} - // AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs. func (duo *DocumentUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdateOne { duo.mutation.AddAttachmentIDs(ids...) @@ -490,27 +384,6 @@ func (duo *DocumentUpdateOne) ClearGroup() *DocumentUpdateOne { return duo } -// ClearDocumentTokens clears all "document_tokens" edges to the DocumentToken entity. -func (duo *DocumentUpdateOne) ClearDocumentTokens() *DocumentUpdateOne { - duo.mutation.ClearDocumentTokens() - return duo -} - -// RemoveDocumentTokenIDs removes the "document_tokens" edge to DocumentToken entities by IDs. -func (duo *DocumentUpdateOne) RemoveDocumentTokenIDs(ids ...uuid.UUID) *DocumentUpdateOne { - duo.mutation.RemoveDocumentTokenIDs(ids...) - return duo -} - -// RemoveDocumentTokens removes "document_tokens" edges to DocumentToken entities. -func (duo *DocumentUpdateOne) RemoveDocumentTokens(d ...*DocumentToken) *DocumentUpdateOne { - ids := make([]uuid.UUID, len(d)) - for i := range d { - ids[i] = d[i].ID - } - return duo.RemoveDocumentTokenIDs(ids...) -} - // ClearAttachments clears all "attachments" edges to the Attachment entity. func (duo *DocumentUpdateOne) ClearAttachments() *DocumentUpdateOne { duo.mutation.ClearAttachments() @@ -711,60 +584,6 @@ func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if duo.mutation.DocumentTokensCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: document.DocumentTokensTable, - Columns: []string{document.DocumentTokensColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := duo.mutation.RemovedDocumentTokensIDs(); len(nodes) > 0 && !duo.mutation.DocumentTokensCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: document.DocumentTokensTable, - Columns: []string{document.DocumentTokensColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := duo.mutation.DocumentTokensIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: document.DocumentTokensTable, - Columns: []string{document.DocumentTokensColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } if duo.mutation.AttachmentsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/backend/internal/data/ent/documenttoken.go b/backend/internal/data/ent/documenttoken.go deleted file mode 100644 index c484a9e..0000000 --- a/backend/internal/data/ent/documenttoken.go +++ /dev/null @@ -1,190 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent/dialect/sql" - "github.com/google/uuid" - "github.com/hay-kot/homebox/backend/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" -) - -// DocumentToken is the model entity for the DocumentToken schema. -type DocumentToken struct { - config `json:"-"` - // ID of the ent. - ID uuid.UUID `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` - // Token holds the value of the "token" field. - Token []byte `json:"token,omitempty"` - // Uses holds the value of the "uses" field. - Uses int `json:"uses,omitempty"` - // ExpiresAt holds the value of the "expires_at" field. - ExpiresAt time.Time `json:"expires_at,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the DocumentTokenQuery when eager-loading is set. - Edges DocumentTokenEdges `json:"edges"` - document_document_tokens *uuid.UUID -} - -// DocumentTokenEdges holds the relations/edges for other nodes in the graph. -type DocumentTokenEdges struct { - // Document holds the value of the document edge. - Document *Document `json:"document,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [1]bool -} - -// DocumentOrErr returns the Document value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e DocumentTokenEdges) DocumentOrErr() (*Document, error) { - if e.loadedTypes[0] { - if e.Document == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: document.Label} - } - return e.Document, nil - } - return nil, &NotLoadedError{edge: "document"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*DocumentToken) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case documenttoken.FieldToken: - values[i] = new([]byte) - case documenttoken.FieldUses: - values[i] = new(sql.NullInt64) - case documenttoken.FieldCreatedAt, documenttoken.FieldUpdatedAt, documenttoken.FieldExpiresAt: - values[i] = new(sql.NullTime) - case documenttoken.FieldID: - values[i] = new(uuid.UUID) - case documenttoken.ForeignKeys[0]: // document_document_tokens - values[i] = &sql.NullScanner{S: new(uuid.UUID)} - default: - return nil, fmt.Errorf("unexpected column %q for type DocumentToken", columns[i]) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the DocumentToken fields. -func (dt *DocumentToken) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case documenttoken.FieldID: - if value, ok := values[i].(*uuid.UUID); !ok { - return fmt.Errorf("unexpected type %T for field id", values[i]) - } else if value != nil { - dt.ID = *value - } - case documenttoken.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - dt.CreatedAt = value.Time - } - case documenttoken.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - dt.UpdatedAt = value.Time - } - case documenttoken.FieldToken: - if value, ok := values[i].(*[]byte); !ok { - return fmt.Errorf("unexpected type %T for field token", values[i]) - } else if value != nil { - dt.Token = *value - } - case documenttoken.FieldUses: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field uses", values[i]) - } else if value.Valid { - dt.Uses = int(value.Int64) - } - case documenttoken.FieldExpiresAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field expires_at", values[i]) - } else if value.Valid { - dt.ExpiresAt = value.Time - } - case documenttoken.ForeignKeys[0]: - if value, ok := values[i].(*sql.NullScanner); !ok { - return fmt.Errorf("unexpected type %T for field document_document_tokens", values[i]) - } else if value.Valid { - dt.document_document_tokens = new(uuid.UUID) - *dt.document_document_tokens = *value.S.(*uuid.UUID) - } - } - } - return nil -} - -// QueryDocument queries the "document" edge of the DocumentToken entity. -func (dt *DocumentToken) QueryDocument() *DocumentQuery { - return (&DocumentTokenClient{config: dt.config}).QueryDocument(dt) -} - -// Update returns a builder for updating this DocumentToken. -// Note that you need to call DocumentToken.Unwrap() before calling this method if this DocumentToken -// was returned from a transaction, and the transaction was committed or rolled back. -func (dt *DocumentToken) Update() *DocumentTokenUpdateOne { - return (&DocumentTokenClient{config: dt.config}).UpdateOne(dt) -} - -// Unwrap unwraps the DocumentToken entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (dt *DocumentToken) Unwrap() *DocumentToken { - _tx, ok := dt.config.driver.(*txDriver) - if !ok { - panic("ent: DocumentToken is not a transactional entity") - } - dt.config.driver = _tx.drv - return dt -} - -// String implements the fmt.Stringer. -func (dt *DocumentToken) String() string { - var builder strings.Builder - builder.WriteString("DocumentToken(") - builder.WriteString(fmt.Sprintf("id=%v, ", dt.ID)) - builder.WriteString("created_at=") - builder.WriteString(dt.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("updated_at=") - builder.WriteString(dt.UpdatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("token=") - builder.WriteString(fmt.Sprintf("%v", dt.Token)) - builder.WriteString(", ") - builder.WriteString("uses=") - builder.WriteString(fmt.Sprintf("%v", dt.Uses)) - builder.WriteString(", ") - builder.WriteString("expires_at=") - builder.WriteString(dt.ExpiresAt.Format(time.ANSIC)) - builder.WriteByte(')') - return builder.String() -} - -// DocumentTokens is a parsable slice of DocumentToken. -type DocumentTokens []*DocumentToken - -func (dt DocumentTokens) config(cfg config) { - for _i := range dt { - dt[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/documenttoken/documenttoken.go b/backend/internal/data/ent/documenttoken/documenttoken.go deleted file mode 100644 index ce05656..0000000 --- a/backend/internal/data/ent/documenttoken/documenttoken.go +++ /dev/null @@ -1,85 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package documenttoken - -import ( - "time" - - "github.com/google/uuid" -) - -const ( - // Label holds the string label denoting the documenttoken type in the database. - Label = "document_token" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldUpdatedAt holds the string denoting the updated_at field in the database. - FieldUpdatedAt = "updated_at" - // FieldToken holds the string denoting the token field in the database. - FieldToken = "token" - // FieldUses holds the string denoting the uses field in the database. - FieldUses = "uses" - // FieldExpiresAt holds the string denoting the expires_at field in the database. - FieldExpiresAt = "expires_at" - // EdgeDocument holds the string denoting the document edge name in mutations. - EdgeDocument = "document" - // Table holds the table name of the documenttoken in the database. - Table = "document_tokens" - // DocumentTable is the table that holds the document relation/edge. - DocumentTable = "document_tokens" - // DocumentInverseTable is the table name for the Document entity. - // It exists in this package in order to avoid circular dependency with the "document" package. - DocumentInverseTable = "documents" - // DocumentColumn is the table column denoting the document relation/edge. - DocumentColumn = "document_document_tokens" -) - -// Columns holds all SQL columns for documenttoken fields. -var Columns = []string{ - FieldID, - FieldCreatedAt, - FieldUpdatedAt, - FieldToken, - FieldUses, - FieldExpiresAt, -} - -// ForeignKeys holds the SQL foreign-keys that are owned by the "document_tokens" -// table and are not defined as standalone fields in the schema. -var ForeignKeys = []string{ - "document_document_tokens", -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - for i := range ForeignKeys { - if column == ForeignKeys[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. - DefaultUpdatedAt func() time.Time - // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. - UpdateDefaultUpdatedAt func() time.Time - // TokenValidator is a validator for the "token" field. It is called by the builders before save. - TokenValidator func([]byte) error - // DefaultUses holds the default value on creation for the "uses" field. - DefaultUses int - // DefaultExpiresAt holds the default value on creation for the "expires_at" field. - DefaultExpiresAt func() time.Time - // DefaultID holds the default value on creation for the "id" field. - DefaultID func() uuid.UUID -) diff --git a/backend/internal/data/ent/documenttoken/where.go b/backend/internal/data/ent/documenttoken/where.go deleted file mode 100644 index 32dbb39..0000000 --- a/backend/internal/data/ent/documenttoken/where.go +++ /dev/null @@ -1,498 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package documenttoken - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "github.com/google/uuid" - "github.com/hay-kot/homebox/backend/internal/data/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id uuid.UUID) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id uuid.UUID) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id uuid.UUID) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...uuid.UUID) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...uuid.UUID) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id uuid.UUID) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id uuid.UUID) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id uuid.UUID) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id uuid.UUID) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// Token applies equality check predicate on the "token" field. It's identical to TokenEQ. -func Token(v []byte) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) -} - -// Uses applies equality check predicate on the "uses" field. It's identical to UsesEQ. -func Uses(v int) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUses), v)) - }) -} - -// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ. -func ExpiresAt(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiresAt), v)) - }) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) -} - -// TokenEQ applies the EQ predicate on the "token" field. -func TokenEQ(v []byte) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) -} - -// TokenNEQ applies the NEQ predicate on the "token" field. -func TokenNEQ(v []byte) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldToken), v)) - }) -} - -// TokenIn applies the In predicate on the "token" field. -func TokenIn(vs ...[]byte) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldToken), v...)) - }) -} - -// TokenNotIn applies the NotIn predicate on the "token" field. -func TokenNotIn(vs ...[]byte) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldToken), v...)) - }) -} - -// TokenGT applies the GT predicate on the "token" field. -func TokenGT(v []byte) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldToken), v)) - }) -} - -// TokenGTE applies the GTE predicate on the "token" field. -func TokenGTE(v []byte) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldToken), v)) - }) -} - -// TokenLT applies the LT predicate on the "token" field. -func TokenLT(v []byte) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldToken), v)) - }) -} - -// TokenLTE applies the LTE predicate on the "token" field. -func TokenLTE(v []byte) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldToken), v)) - }) -} - -// UsesEQ applies the EQ predicate on the "uses" field. -func UsesEQ(v int) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUses), v)) - }) -} - -// UsesNEQ applies the NEQ predicate on the "uses" field. -func UsesNEQ(v int) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUses), v)) - }) -} - -// UsesIn applies the In predicate on the "uses" field. -func UsesIn(vs ...int) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUses), v...)) - }) -} - -// UsesNotIn applies the NotIn predicate on the "uses" field. -func UsesNotIn(vs ...int) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUses), v...)) - }) -} - -// UsesGT applies the GT predicate on the "uses" field. -func UsesGT(v int) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUses), v)) - }) -} - -// UsesGTE applies the GTE predicate on the "uses" field. -func UsesGTE(v int) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUses), v)) - }) -} - -// UsesLT applies the LT predicate on the "uses" field. -func UsesLT(v int) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUses), v)) - }) -} - -// UsesLTE applies the LTE predicate on the "uses" field. -func UsesLTE(v int) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUses), v)) - }) -} - -// ExpiresAtEQ applies the EQ predicate on the "expires_at" field. -func ExpiresAtEQ(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiresAt), v)) - }) -} - -// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field. -func ExpiresAtNEQ(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldExpiresAt), v)) - }) -} - -// ExpiresAtIn applies the In predicate on the "expires_at" field. -func ExpiresAtIn(vs ...time.Time) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldExpiresAt), v...)) - }) -} - -// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field. -func ExpiresAtNotIn(vs ...time.Time) predicate.DocumentToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldExpiresAt), v...)) - }) -} - -// ExpiresAtGT applies the GT predicate on the "expires_at" field. -func ExpiresAtGT(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldExpiresAt), v)) - }) -} - -// ExpiresAtGTE applies the GTE predicate on the "expires_at" field. -func ExpiresAtGTE(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldExpiresAt), v)) - }) -} - -// ExpiresAtLT applies the LT predicate on the "expires_at" field. -func ExpiresAtLT(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldExpiresAt), v)) - }) -} - -// ExpiresAtLTE applies the LTE predicate on the "expires_at" field. -func ExpiresAtLTE(v time.Time) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldExpiresAt), v)) - }) -} - -// HasDocument applies the HasEdge predicate on the "document" edge. -func HasDocument() predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(DocumentTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, DocumentTable, DocumentColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasDocumentWith applies the HasEdge predicate on the "document" edge with a given conditions (other predicates). -func HasDocumentWith(preds ...predicate.Document) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(DocumentInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, DocumentTable, DocumentColumn), - ) - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.DocumentToken) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.DocumentToken) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.DocumentToken) predicate.DocumentToken { - return predicate.DocumentToken(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/backend/internal/data/ent/documenttoken_create.go b/backend/internal/data/ent/documenttoken_create.go deleted file mode 100644 index c937279..0000000 --- a/backend/internal/data/ent/documenttoken_create.go +++ /dev/null @@ -1,398 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/google/uuid" - "github.com/hay-kot/homebox/backend/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" -) - -// DocumentTokenCreate is the builder for creating a DocumentToken entity. -type DocumentTokenCreate struct { - config - mutation *DocumentTokenMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (dtc *DocumentTokenCreate) SetCreatedAt(t time.Time) *DocumentTokenCreate { - dtc.mutation.SetCreatedAt(t) - return dtc -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (dtc *DocumentTokenCreate) SetNillableCreatedAt(t *time.Time) *DocumentTokenCreate { - if t != nil { - dtc.SetCreatedAt(*t) - } - return dtc -} - -// SetUpdatedAt sets the "updated_at" field. -func (dtc *DocumentTokenCreate) SetUpdatedAt(t time.Time) *DocumentTokenCreate { - dtc.mutation.SetUpdatedAt(t) - return dtc -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (dtc *DocumentTokenCreate) SetNillableUpdatedAt(t *time.Time) *DocumentTokenCreate { - if t != nil { - dtc.SetUpdatedAt(*t) - } - return dtc -} - -// SetToken sets the "token" field. -func (dtc *DocumentTokenCreate) SetToken(b []byte) *DocumentTokenCreate { - dtc.mutation.SetToken(b) - return dtc -} - -// SetUses sets the "uses" field. -func (dtc *DocumentTokenCreate) SetUses(i int) *DocumentTokenCreate { - dtc.mutation.SetUses(i) - return dtc -} - -// SetNillableUses sets the "uses" field if the given value is not nil. -func (dtc *DocumentTokenCreate) SetNillableUses(i *int) *DocumentTokenCreate { - if i != nil { - dtc.SetUses(*i) - } - return dtc -} - -// SetExpiresAt sets the "expires_at" field. -func (dtc *DocumentTokenCreate) SetExpiresAt(t time.Time) *DocumentTokenCreate { - dtc.mutation.SetExpiresAt(t) - return dtc -} - -// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil. -func (dtc *DocumentTokenCreate) SetNillableExpiresAt(t *time.Time) *DocumentTokenCreate { - if t != nil { - dtc.SetExpiresAt(*t) - } - return dtc -} - -// SetID sets the "id" field. -func (dtc *DocumentTokenCreate) SetID(u uuid.UUID) *DocumentTokenCreate { - dtc.mutation.SetID(u) - return dtc -} - -// SetNillableID sets the "id" field if the given value is not nil. -func (dtc *DocumentTokenCreate) SetNillableID(u *uuid.UUID) *DocumentTokenCreate { - if u != nil { - dtc.SetID(*u) - } - return dtc -} - -// SetDocumentID sets the "document" edge to the Document entity by ID. -func (dtc *DocumentTokenCreate) SetDocumentID(id uuid.UUID) *DocumentTokenCreate { - dtc.mutation.SetDocumentID(id) - return dtc -} - -// SetNillableDocumentID sets the "document" edge to the Document entity by ID if the given value is not nil. -func (dtc *DocumentTokenCreate) SetNillableDocumentID(id *uuid.UUID) *DocumentTokenCreate { - if id != nil { - dtc = dtc.SetDocumentID(*id) - } - return dtc -} - -// SetDocument sets the "document" edge to the Document entity. -func (dtc *DocumentTokenCreate) SetDocument(d *Document) *DocumentTokenCreate { - return dtc.SetDocumentID(d.ID) -} - -// Mutation returns the DocumentTokenMutation object of the builder. -func (dtc *DocumentTokenCreate) Mutation() *DocumentTokenMutation { - return dtc.mutation -} - -// Save creates the DocumentToken in the database. -func (dtc *DocumentTokenCreate) Save(ctx context.Context) (*DocumentToken, error) { - var ( - err error - node *DocumentToken - ) - dtc.defaults() - if len(dtc.hooks) == 0 { - if err = dtc.check(); err != nil { - return nil, err - } - node, err = dtc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DocumentTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = dtc.check(); err != nil { - return nil, err - } - dtc.mutation = mutation - if node, err = dtc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(dtc.hooks) - 1; i >= 0; i-- { - if dtc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = dtc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, dtc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*DocumentToken) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from DocumentTokenMutation", v) - } - node = nv - } - return node, err -} - -// SaveX calls Save and panics if Save returns an error. -func (dtc *DocumentTokenCreate) SaveX(ctx context.Context) *DocumentToken { - v, err := dtc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (dtc *DocumentTokenCreate) Exec(ctx context.Context) error { - _, err := dtc.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dtc *DocumentTokenCreate) ExecX(ctx context.Context) { - if err := dtc.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (dtc *DocumentTokenCreate) defaults() { - if _, ok := dtc.mutation.CreatedAt(); !ok { - v := documenttoken.DefaultCreatedAt() - dtc.mutation.SetCreatedAt(v) - } - if _, ok := dtc.mutation.UpdatedAt(); !ok { - v := documenttoken.DefaultUpdatedAt() - dtc.mutation.SetUpdatedAt(v) - } - if _, ok := dtc.mutation.Uses(); !ok { - v := documenttoken.DefaultUses - dtc.mutation.SetUses(v) - } - if _, ok := dtc.mutation.ExpiresAt(); !ok { - v := documenttoken.DefaultExpiresAt() - dtc.mutation.SetExpiresAt(v) - } - if _, ok := dtc.mutation.ID(); !ok { - v := documenttoken.DefaultID() - dtc.mutation.SetID(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (dtc *DocumentTokenCreate) check() error { - if _, ok := dtc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "DocumentToken.created_at"`)} - } - if _, ok := dtc.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "DocumentToken.updated_at"`)} - } - if _, ok := dtc.mutation.Token(); !ok { - return &ValidationError{Name: "token", err: errors.New(`ent: missing required field "DocumentToken.token"`)} - } - if v, ok := dtc.mutation.Token(); ok { - if err := documenttoken.TokenValidator(v); err != nil { - return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "DocumentToken.token": %w`, err)} - } - } - if _, ok := dtc.mutation.Uses(); !ok { - return &ValidationError{Name: "uses", err: errors.New(`ent: missing required field "DocumentToken.uses"`)} - } - if _, ok := dtc.mutation.ExpiresAt(); !ok { - return &ValidationError{Name: "expires_at", err: errors.New(`ent: missing required field "DocumentToken.expires_at"`)} - } - return nil -} - -func (dtc *DocumentTokenCreate) sqlSave(ctx context.Context) (*DocumentToken, error) { - _node, _spec := dtc.createSpec() - if err := sqlgraph.CreateNode(ctx, dtc.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - if _spec.ID.Value != nil { - if id, ok := _spec.ID.Value.(*uuid.UUID); ok { - _node.ID = *id - } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { - return nil, err - } - } - return _node, nil -} - -func (dtc *DocumentTokenCreate) createSpec() (*DocumentToken, *sqlgraph.CreateSpec) { - var ( - _node = &DocumentToken{config: dtc.config} - _spec = &sqlgraph.CreateSpec{ - Table: documenttoken.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - } - ) - if id, ok := dtc.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = &id - } - if value, ok := dtc.mutation.CreatedAt(); ok { - _spec.SetField(documenttoken.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := dtc.mutation.UpdatedAt(); ok { - _spec.SetField(documenttoken.FieldUpdatedAt, field.TypeTime, value) - _node.UpdatedAt = value - } - if value, ok := dtc.mutation.Token(); ok { - _spec.SetField(documenttoken.FieldToken, field.TypeBytes, value) - _node.Token = value - } - if value, ok := dtc.mutation.Uses(); ok { - _spec.SetField(documenttoken.FieldUses, field.TypeInt, value) - _node.Uses = value - } - if value, ok := dtc.mutation.ExpiresAt(); ok { - _spec.SetField(documenttoken.FieldExpiresAt, field.TypeTime, value) - _node.ExpiresAt = value - } - if nodes := dtc.mutation.DocumentIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: documenttoken.DocumentTable, - Columns: []string{documenttoken.DocumentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _node.document_document_tokens = &nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// DocumentTokenCreateBulk is the builder for creating many DocumentToken entities in bulk. -type DocumentTokenCreateBulk struct { - config - builders []*DocumentTokenCreate -} - -// Save creates the DocumentToken entities in the database. -func (dtcb *DocumentTokenCreateBulk) Save(ctx context.Context) ([]*DocumentToken, error) { - specs := make([]*sqlgraph.CreateSpec, len(dtcb.builders)) - nodes := make([]*DocumentToken, len(dtcb.builders)) - mutators := make([]Mutator, len(dtcb.builders)) - for i := range dtcb.builders { - func(i int, root context.Context) { - builder := dtcb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DocumentTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() - var err error - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, dtcb.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, dtcb.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, dtcb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (dtcb *DocumentTokenCreateBulk) SaveX(ctx context.Context) []*DocumentToken { - v, err := dtcb.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (dtcb *DocumentTokenCreateBulk) Exec(ctx context.Context) error { - _, err := dtcb.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dtcb *DocumentTokenCreateBulk) ExecX(ctx context.Context) { - if err := dtcb.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/backend/internal/data/ent/documenttoken_delete.go b/backend/internal/data/ent/documenttoken_delete.go deleted file mode 100644 index 722ec1b..0000000 --- a/backend/internal/data/ent/documenttoken_delete.go +++ /dev/null @@ -1,115 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" - "github.com/hay-kot/homebox/backend/internal/data/ent/predicate" -) - -// DocumentTokenDelete is the builder for deleting a DocumentToken entity. -type DocumentTokenDelete struct { - config - hooks []Hook - mutation *DocumentTokenMutation -} - -// Where appends a list predicates to the DocumentTokenDelete builder. -func (dtd *DocumentTokenDelete) Where(ps ...predicate.DocumentToken) *DocumentTokenDelete { - dtd.mutation.Where(ps...) - return dtd -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (dtd *DocumentTokenDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(dtd.hooks) == 0 { - affected, err = dtd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DocumentTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - dtd.mutation = mutation - affected, err = dtd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(dtd.hooks) - 1; i >= 0; i-- { - if dtd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = dtd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, dtd.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dtd *DocumentTokenDelete) ExecX(ctx context.Context) int { - n, err := dtd.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (dtd *DocumentTokenDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: documenttoken.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - if ps := dtd.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, dtd.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return affected, err -} - -// DocumentTokenDeleteOne is the builder for deleting a single DocumentToken entity. -type DocumentTokenDeleteOne struct { - dtd *DocumentTokenDelete -} - -// Exec executes the deletion query. -func (dtdo *DocumentTokenDeleteOne) Exec(ctx context.Context) error { - n, err := dtdo.dtd.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{documenttoken.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (dtdo *DocumentTokenDeleteOne) ExecX(ctx context.Context) { - dtdo.dtd.ExecX(ctx) -} diff --git a/backend/internal/data/ent/documenttoken_query.go b/backend/internal/data/ent/documenttoken_query.go deleted file mode 100644 index 58cb61b..0000000 --- a/backend/internal/data/ent/documenttoken_query.go +++ /dev/null @@ -1,633 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "math" - - "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/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" - "github.com/hay-kot/homebox/backend/internal/data/ent/predicate" -) - -// DocumentTokenQuery is the builder for querying DocumentToken entities. -type DocumentTokenQuery struct { - config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.DocumentToken - withDocument *DocumentQuery - withFKs bool - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the DocumentTokenQuery builder. -func (dtq *DocumentTokenQuery) Where(ps ...predicate.DocumentToken) *DocumentTokenQuery { - dtq.predicates = append(dtq.predicates, ps...) - return dtq -} - -// Limit adds a limit step to the query. -func (dtq *DocumentTokenQuery) Limit(limit int) *DocumentTokenQuery { - dtq.limit = &limit - return dtq -} - -// Offset adds an offset step to the query. -func (dtq *DocumentTokenQuery) Offset(offset int) *DocumentTokenQuery { - dtq.offset = &offset - return dtq -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (dtq *DocumentTokenQuery) Unique(unique bool) *DocumentTokenQuery { - dtq.unique = &unique - return dtq -} - -// Order adds an order step to the query. -func (dtq *DocumentTokenQuery) Order(o ...OrderFunc) *DocumentTokenQuery { - dtq.order = append(dtq.order, o...) - return dtq -} - -// QueryDocument chains the current query on the "document" edge. -func (dtq *DocumentTokenQuery) QueryDocument() *DocumentQuery { - query := &DocumentQuery{config: dtq.config} - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := dtq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := dtq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(documenttoken.Table, documenttoken.FieldID, selector), - sqlgraph.To(document.Table, document.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, documenttoken.DocumentTable, documenttoken.DocumentColumn), - ) - fromU = sqlgraph.SetNeighbors(dtq.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first DocumentToken entity from the query. -// Returns a *NotFoundError when no DocumentToken was found. -func (dtq *DocumentTokenQuery) First(ctx context.Context) (*DocumentToken, error) { - nodes, err := dtq.Limit(1).All(ctx) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{documenttoken.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (dtq *DocumentTokenQuery) FirstX(ctx context.Context) *DocumentToken { - node, err := dtq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first DocumentToken ID from the query. -// Returns a *NotFoundError when no DocumentToken ID was found. -func (dtq *DocumentTokenQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { - var ids []uuid.UUID - if ids, err = dtq.Limit(1).IDs(ctx); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{documenttoken.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (dtq *DocumentTokenQuery) FirstIDX(ctx context.Context) uuid.UUID { - id, err := dtq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single DocumentToken entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one DocumentToken entity is found. -// Returns a *NotFoundError when no DocumentToken entities are found. -func (dtq *DocumentTokenQuery) Only(ctx context.Context) (*DocumentToken, error) { - nodes, err := dtq.Limit(2).All(ctx) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{documenttoken.Label} - default: - return nil, &NotSingularError{documenttoken.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (dtq *DocumentTokenQuery) OnlyX(ctx context.Context) *DocumentToken { - node, err := dtq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only DocumentToken ID in the query. -// Returns a *NotSingularError when more than one DocumentToken ID is found. -// Returns a *NotFoundError when no entities are found. -func (dtq *DocumentTokenQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { - var ids []uuid.UUID - if ids, err = dtq.Limit(2).IDs(ctx); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{documenttoken.Label} - default: - err = &NotSingularError{documenttoken.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (dtq *DocumentTokenQuery) OnlyIDX(ctx context.Context) uuid.UUID { - id, err := dtq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of DocumentTokens. -func (dtq *DocumentTokenQuery) All(ctx context.Context) ([]*DocumentToken, error) { - if err := dtq.prepareQuery(ctx); err != nil { - return nil, err - } - return dtq.sqlAll(ctx) -} - -// AllX is like All, but panics if an error occurs. -func (dtq *DocumentTokenQuery) AllX(ctx context.Context) []*DocumentToken { - nodes, err := dtq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of DocumentToken IDs. -func (dtq *DocumentTokenQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID - if err := dtq.Select(documenttoken.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (dtq *DocumentTokenQuery) IDsX(ctx context.Context) []uuid.UUID { - ids, err := dtq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (dtq *DocumentTokenQuery) Count(ctx context.Context) (int, error) { - if err := dtq.prepareQuery(ctx); err != nil { - return 0, err - } - return dtq.sqlCount(ctx) -} - -// CountX is like Count, but panics if an error occurs. -func (dtq *DocumentTokenQuery) CountX(ctx context.Context) int { - count, err := dtq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (dtq *DocumentTokenQuery) Exist(ctx context.Context) (bool, error) { - if err := dtq.prepareQuery(ctx); err != nil { - return false, err - } - return dtq.sqlExist(ctx) -} - -// ExistX is like Exist, but panics if an error occurs. -func (dtq *DocumentTokenQuery) ExistX(ctx context.Context) bool { - exist, err := dtq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the DocumentTokenQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (dtq *DocumentTokenQuery) Clone() *DocumentTokenQuery { - if dtq == nil { - return nil - } - return &DocumentTokenQuery{ - config: dtq.config, - limit: dtq.limit, - offset: dtq.offset, - order: append([]OrderFunc{}, dtq.order...), - predicates: append([]predicate.DocumentToken{}, dtq.predicates...), - withDocument: dtq.withDocument.Clone(), - // clone intermediate query. - sql: dtq.sql.Clone(), - path: dtq.path, - unique: dtq.unique, - } -} - -// WithDocument tells the query-builder to eager-load the nodes that are connected to -// the "document" edge. The optional arguments are used to configure the query builder of the edge. -func (dtq *DocumentTokenQuery) WithDocument(opts ...func(*DocumentQuery)) *DocumentTokenQuery { - query := &DocumentQuery{config: dtq.config} - for _, opt := range opts { - opt(query) - } - dtq.withDocument = query - return dtq -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.DocumentToken.Query(). -// GroupBy(documenttoken.FieldCreatedAt). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (dtq *DocumentTokenQuery) GroupBy(field string, fields ...string) *DocumentTokenGroupBy { - grbuild := &DocumentTokenGroupBy{config: dtq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := dtq.prepareQuery(ctx); err != nil { - return nil, err - } - return dtq.sqlQuery(ctx), nil - } - grbuild.label = documenttoken.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// } -// -// client.DocumentToken.Query(). -// Select(documenttoken.FieldCreatedAt). -// Scan(ctx, &v) -func (dtq *DocumentTokenQuery) Select(fields ...string) *DocumentTokenSelect { - dtq.fields = append(dtq.fields, fields...) - selbuild := &DocumentTokenSelect{DocumentTokenQuery: dtq} - selbuild.label = documenttoken.Label - selbuild.flds, selbuild.scan = &dtq.fields, selbuild.Scan - return selbuild -} - -// Aggregate returns a DocumentTokenSelect configured with the given aggregations. -func (dtq *DocumentTokenQuery) Aggregate(fns ...AggregateFunc) *DocumentTokenSelect { - return dtq.Select().Aggregate(fns...) -} - -func (dtq *DocumentTokenQuery) prepareQuery(ctx context.Context) error { - for _, f := range dtq.fields { - if !documenttoken.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if dtq.path != nil { - prev, err := dtq.path(ctx) - if err != nil { - return err - } - dtq.sql = prev - } - return nil -} - -func (dtq *DocumentTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*DocumentToken, error) { - var ( - nodes = []*DocumentToken{} - withFKs = dtq.withFKs - _spec = dtq.querySpec() - loadedTypes = [1]bool{ - dtq.withDocument != nil, - } - ) - if dtq.withDocument != nil { - withFKs = true - } - if withFKs { - _spec.Node.Columns = append(_spec.Node.Columns, documenttoken.ForeignKeys...) - } - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*DocumentToken).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &DocumentToken{config: dtq.config} - nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, dtq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - if query := dtq.withDocument; query != nil { - if err := dtq.loadDocument(ctx, query, nodes, nil, - func(n *DocumentToken, e *Document) { n.Edges.Document = e }); err != nil { - return nil, err - } - } - return nodes, nil -} - -func (dtq *DocumentTokenQuery) loadDocument(ctx context.Context, query *DocumentQuery, nodes []*DocumentToken, init func(*DocumentToken), assign func(*DocumentToken, *Document)) error { - ids := make([]uuid.UUID, 0, len(nodes)) - nodeids := make(map[uuid.UUID][]*DocumentToken) - for i := range nodes { - if nodes[i].document_document_tokens == nil { - continue - } - fk := *nodes[i].document_document_tokens - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - query.Where(document.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return fmt.Errorf(`unexpected foreign-key "document_document_tokens" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} - -func (dtq *DocumentTokenQuery) sqlCount(ctx context.Context) (int, error) { - _spec := dtq.querySpec() - _spec.Node.Columns = dtq.fields - if len(dtq.fields) > 0 { - _spec.Unique = dtq.unique != nil && *dtq.unique - } - return sqlgraph.CountNodes(ctx, dtq.driver, _spec) -} - -func (dtq *DocumentTokenQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := dtq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -func (dtq *DocumentTokenQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: documenttoken.Table, - Columns: documenttoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - From: dtq.sql, - Unique: true, - } - if unique := dtq.unique; unique != nil { - _spec.Unique = *unique - } - if fields := dtq.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, documenttoken.FieldID) - for i := range fields { - if fields[i] != documenttoken.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := dtq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := dtq.limit; limit != nil { - _spec.Limit = *limit - } - if offset := dtq.offset; offset != nil { - _spec.Offset = *offset - } - if ps := dtq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (dtq *DocumentTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(dtq.driver.Dialect()) - t1 := builder.Table(documenttoken.Table) - columns := dtq.fields - if len(columns) == 0 { - columns = documenttoken.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if dtq.sql != nil { - selector = dtq.sql - selector.Select(selector.Columns(columns...)...) - } - if dtq.unique != nil && *dtq.unique { - selector.Distinct() - } - for _, p := range dtq.predicates { - p(selector) - } - for _, p := range dtq.order { - p(selector) - } - if offset := dtq.offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := dtq.limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// DocumentTokenGroupBy is the group-by builder for DocumentToken entities. -type DocumentTokenGroupBy struct { - config - selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (dtgb *DocumentTokenGroupBy) Aggregate(fns ...AggregateFunc) *DocumentTokenGroupBy { - dtgb.fns = append(dtgb.fns, fns...) - return dtgb -} - -// Scan applies the group-by query and scans the result into the given value. -func (dtgb *DocumentTokenGroupBy) Scan(ctx context.Context, v any) error { - query, err := dtgb.path(ctx) - if err != nil { - return err - } - dtgb.sql = query - return dtgb.sqlScan(ctx, v) -} - -func (dtgb *DocumentTokenGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range dtgb.fields { - if !documenttoken.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := dtgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := dtgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (dtgb *DocumentTokenGroupBy) sqlQuery() *sql.Selector { - selector := dtgb.sql.Select() - aggregation := make([]string, 0, len(dtgb.fns)) - for _, fn := range dtgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(dtgb.fields)+len(dtgb.fns)) - for _, f := range dtgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(dtgb.fields...)...) -} - -// DocumentTokenSelect is the builder for selecting fields of DocumentToken entities. -type DocumentTokenSelect struct { - *DocumentTokenQuery - selector - // intermediate query (i.e. traversal path). - sql *sql.Selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (dts *DocumentTokenSelect) Aggregate(fns ...AggregateFunc) *DocumentTokenSelect { - dts.fns = append(dts.fns, fns...) - return dts -} - -// Scan applies the selector query and scans the result into the given value. -func (dts *DocumentTokenSelect) Scan(ctx context.Context, v any) error { - if err := dts.prepareQuery(ctx); err != nil { - return err - } - dts.sql = dts.DocumentTokenQuery.sqlQuery(ctx) - return dts.sqlScan(ctx, v) -} - -func (dts *DocumentTokenSelect) sqlScan(ctx context.Context, v any) error { - aggregation := make([]string, 0, len(dts.fns)) - for _, fn := range dts.fns { - aggregation = append(aggregation, fn(dts.sql)) - } - switch n := len(*dts.selector.flds); { - case n == 0 && len(aggregation) > 0: - dts.sql.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - dts.sql.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := dts.sql.Query() - if err := dts.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/backend/internal/data/ent/documenttoken_update.go b/backend/internal/data/ent/documenttoken_update.go deleted file mode 100644 index 416bc08..0000000 --- a/backend/internal/data/ent/documenttoken_update.go +++ /dev/null @@ -1,542 +0,0 @@ -// 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/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" - "github.com/hay-kot/homebox/backend/internal/data/ent/predicate" -) - -// DocumentTokenUpdate is the builder for updating DocumentToken entities. -type DocumentTokenUpdate struct { - config - hooks []Hook - mutation *DocumentTokenMutation -} - -// Where appends a list predicates to the DocumentTokenUpdate builder. -func (dtu *DocumentTokenUpdate) Where(ps ...predicate.DocumentToken) *DocumentTokenUpdate { - dtu.mutation.Where(ps...) - return dtu -} - -// SetUpdatedAt sets the "updated_at" field. -func (dtu *DocumentTokenUpdate) SetUpdatedAt(t time.Time) *DocumentTokenUpdate { - dtu.mutation.SetUpdatedAt(t) - return dtu -} - -// SetToken sets the "token" field. -func (dtu *DocumentTokenUpdate) SetToken(b []byte) *DocumentTokenUpdate { - dtu.mutation.SetToken(b) - return dtu -} - -// SetUses sets the "uses" field. -func (dtu *DocumentTokenUpdate) SetUses(i int) *DocumentTokenUpdate { - dtu.mutation.ResetUses() - dtu.mutation.SetUses(i) - return dtu -} - -// SetNillableUses sets the "uses" field if the given value is not nil. -func (dtu *DocumentTokenUpdate) SetNillableUses(i *int) *DocumentTokenUpdate { - if i != nil { - dtu.SetUses(*i) - } - return dtu -} - -// AddUses adds i to the "uses" field. -func (dtu *DocumentTokenUpdate) AddUses(i int) *DocumentTokenUpdate { - dtu.mutation.AddUses(i) - return dtu -} - -// SetExpiresAt sets the "expires_at" field. -func (dtu *DocumentTokenUpdate) SetExpiresAt(t time.Time) *DocumentTokenUpdate { - dtu.mutation.SetExpiresAt(t) - return dtu -} - -// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil. -func (dtu *DocumentTokenUpdate) SetNillableExpiresAt(t *time.Time) *DocumentTokenUpdate { - if t != nil { - dtu.SetExpiresAt(*t) - } - return dtu -} - -// SetDocumentID sets the "document" edge to the Document entity by ID. -func (dtu *DocumentTokenUpdate) SetDocumentID(id uuid.UUID) *DocumentTokenUpdate { - dtu.mutation.SetDocumentID(id) - return dtu -} - -// SetNillableDocumentID sets the "document" edge to the Document entity by ID if the given value is not nil. -func (dtu *DocumentTokenUpdate) SetNillableDocumentID(id *uuid.UUID) *DocumentTokenUpdate { - if id != nil { - dtu = dtu.SetDocumentID(*id) - } - return dtu -} - -// SetDocument sets the "document" edge to the Document entity. -func (dtu *DocumentTokenUpdate) SetDocument(d *Document) *DocumentTokenUpdate { - return dtu.SetDocumentID(d.ID) -} - -// Mutation returns the DocumentTokenMutation object of the builder. -func (dtu *DocumentTokenUpdate) Mutation() *DocumentTokenMutation { - return dtu.mutation -} - -// ClearDocument clears the "document" edge to the Document entity. -func (dtu *DocumentTokenUpdate) ClearDocument() *DocumentTokenUpdate { - dtu.mutation.ClearDocument() - return dtu -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (dtu *DocumentTokenUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - dtu.defaults() - if len(dtu.hooks) == 0 { - if err = dtu.check(); err != nil { - return 0, err - } - affected, err = dtu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DocumentTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = dtu.check(); err != nil { - return 0, err - } - dtu.mutation = mutation - affected, err = dtu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(dtu.hooks) - 1; i >= 0; i-- { - if dtu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = dtu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, dtu.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// SaveX is like Save, but panics if an error occurs. -func (dtu *DocumentTokenUpdate) SaveX(ctx context.Context) int { - affected, err := dtu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (dtu *DocumentTokenUpdate) Exec(ctx context.Context) error { - _, err := dtu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dtu *DocumentTokenUpdate) ExecX(ctx context.Context) { - if err := dtu.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (dtu *DocumentTokenUpdate) defaults() { - if _, ok := dtu.mutation.UpdatedAt(); !ok { - v := documenttoken.UpdateDefaultUpdatedAt() - dtu.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (dtu *DocumentTokenUpdate) check() error { - if v, ok := dtu.mutation.Token(); ok { - if err := documenttoken.TokenValidator(v); err != nil { - return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "DocumentToken.token": %w`, err)} - } - } - return nil -} - -func (dtu *DocumentTokenUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: documenttoken.Table, - Columns: documenttoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - if ps := dtu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := dtu.mutation.UpdatedAt(); ok { - _spec.SetField(documenttoken.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := dtu.mutation.Token(); ok { - _spec.SetField(documenttoken.FieldToken, field.TypeBytes, value) - } - if value, ok := dtu.mutation.Uses(); ok { - _spec.SetField(documenttoken.FieldUses, field.TypeInt, value) - } - if value, ok := dtu.mutation.AddedUses(); ok { - _spec.AddField(documenttoken.FieldUses, field.TypeInt, value) - } - if value, ok := dtu.mutation.ExpiresAt(); ok { - _spec.SetField(documenttoken.FieldExpiresAt, field.TypeTime, value) - } - if dtu.mutation.DocumentCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: documenttoken.DocumentTable, - Columns: []string{documenttoken.DocumentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := dtu.mutation.DocumentIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: documenttoken.DocumentTable, - Columns: []string{documenttoken.DocumentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.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, dtu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{documenttoken.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - return n, nil -} - -// DocumentTokenUpdateOne is the builder for updating a single DocumentToken entity. -type DocumentTokenUpdateOne struct { - config - fields []string - hooks []Hook - mutation *DocumentTokenMutation -} - -// SetUpdatedAt sets the "updated_at" field. -func (dtuo *DocumentTokenUpdateOne) SetUpdatedAt(t time.Time) *DocumentTokenUpdateOne { - dtuo.mutation.SetUpdatedAt(t) - return dtuo -} - -// SetToken sets the "token" field. -func (dtuo *DocumentTokenUpdateOne) SetToken(b []byte) *DocumentTokenUpdateOne { - dtuo.mutation.SetToken(b) - return dtuo -} - -// SetUses sets the "uses" field. -func (dtuo *DocumentTokenUpdateOne) SetUses(i int) *DocumentTokenUpdateOne { - dtuo.mutation.ResetUses() - dtuo.mutation.SetUses(i) - return dtuo -} - -// SetNillableUses sets the "uses" field if the given value is not nil. -func (dtuo *DocumentTokenUpdateOne) SetNillableUses(i *int) *DocumentTokenUpdateOne { - if i != nil { - dtuo.SetUses(*i) - } - return dtuo -} - -// AddUses adds i to the "uses" field. -func (dtuo *DocumentTokenUpdateOne) AddUses(i int) *DocumentTokenUpdateOne { - dtuo.mutation.AddUses(i) - return dtuo -} - -// SetExpiresAt sets the "expires_at" field. -func (dtuo *DocumentTokenUpdateOne) SetExpiresAt(t time.Time) *DocumentTokenUpdateOne { - dtuo.mutation.SetExpiresAt(t) - return dtuo -} - -// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil. -func (dtuo *DocumentTokenUpdateOne) SetNillableExpiresAt(t *time.Time) *DocumentTokenUpdateOne { - if t != nil { - dtuo.SetExpiresAt(*t) - } - return dtuo -} - -// SetDocumentID sets the "document" edge to the Document entity by ID. -func (dtuo *DocumentTokenUpdateOne) SetDocumentID(id uuid.UUID) *DocumentTokenUpdateOne { - dtuo.mutation.SetDocumentID(id) - return dtuo -} - -// SetNillableDocumentID sets the "document" edge to the Document entity by ID if the given value is not nil. -func (dtuo *DocumentTokenUpdateOne) SetNillableDocumentID(id *uuid.UUID) *DocumentTokenUpdateOne { - if id != nil { - dtuo = dtuo.SetDocumentID(*id) - } - return dtuo -} - -// SetDocument sets the "document" edge to the Document entity. -func (dtuo *DocumentTokenUpdateOne) SetDocument(d *Document) *DocumentTokenUpdateOne { - return dtuo.SetDocumentID(d.ID) -} - -// Mutation returns the DocumentTokenMutation object of the builder. -func (dtuo *DocumentTokenUpdateOne) Mutation() *DocumentTokenMutation { - return dtuo.mutation -} - -// ClearDocument clears the "document" edge to the Document entity. -func (dtuo *DocumentTokenUpdateOne) ClearDocument() *DocumentTokenUpdateOne { - dtuo.mutation.ClearDocument() - return dtuo -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (dtuo *DocumentTokenUpdateOne) Select(field string, fields ...string) *DocumentTokenUpdateOne { - dtuo.fields = append([]string{field}, fields...) - return dtuo -} - -// Save executes the query and returns the updated DocumentToken entity. -func (dtuo *DocumentTokenUpdateOne) Save(ctx context.Context) (*DocumentToken, error) { - var ( - err error - node *DocumentToken - ) - dtuo.defaults() - if len(dtuo.hooks) == 0 { - if err = dtuo.check(); err != nil { - return nil, err - } - node, err = dtuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DocumentTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = dtuo.check(); err != nil { - return nil, err - } - dtuo.mutation = mutation - node, err = dtuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(dtuo.hooks) - 1; i >= 0; i-- { - if dtuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = dtuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, dtuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*DocumentToken) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from DocumentTokenMutation", v) - } - node = nv - } - return node, err -} - -// SaveX is like Save, but panics if an error occurs. -func (dtuo *DocumentTokenUpdateOne) SaveX(ctx context.Context) *DocumentToken { - node, err := dtuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (dtuo *DocumentTokenUpdateOne) Exec(ctx context.Context) error { - _, err := dtuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dtuo *DocumentTokenUpdateOne) ExecX(ctx context.Context) { - if err := dtuo.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (dtuo *DocumentTokenUpdateOne) defaults() { - if _, ok := dtuo.mutation.UpdatedAt(); !ok { - v := documenttoken.UpdateDefaultUpdatedAt() - dtuo.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (dtuo *DocumentTokenUpdateOne) check() error { - if v, ok := dtuo.mutation.Token(); ok { - if err := documenttoken.TokenValidator(v); err != nil { - return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "DocumentToken.token": %w`, err)} - } - } - return nil -} - -func (dtuo *DocumentTokenUpdateOne) sqlSave(ctx context.Context) (_node *DocumentToken, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: documenttoken.Table, - Columns: documenttoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: documenttoken.FieldID, - }, - }, - } - id, ok := dtuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "DocumentToken.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := dtuo.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, documenttoken.FieldID) - for _, f := range fields { - if !documenttoken.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != documenttoken.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := dtuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := dtuo.mutation.UpdatedAt(); ok { - _spec.SetField(documenttoken.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := dtuo.mutation.Token(); ok { - _spec.SetField(documenttoken.FieldToken, field.TypeBytes, value) - } - if value, ok := dtuo.mutation.Uses(); ok { - _spec.SetField(documenttoken.FieldUses, field.TypeInt, value) - } - if value, ok := dtuo.mutation.AddedUses(); ok { - _spec.AddField(documenttoken.FieldUses, field.TypeInt, value) - } - if value, ok := dtuo.mutation.ExpiresAt(); ok { - _spec.SetField(documenttoken.FieldExpiresAt, field.TypeTime, value) - } - if dtuo.mutation.DocumentCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: documenttoken.DocumentTable, - Columns: []string{documenttoken.DocumentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := dtuo.mutation.DocumentIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: documenttoken.DocumentTable, - Columns: []string{documenttoken.DocumentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &DocumentToken{config: dtuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, dtuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{documenttoken.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - return _node, nil -} diff --git a/backend/internal/data/ent/ent.go b/backend/internal/data/ent/ent.go index 0731b14..f4fe103 100644 --- a/backend/internal/data/ent/ent.go +++ b/backend/internal/data/ent/ent.go @@ -14,7 +14,6 @@ import ( "github.com/hay-kot/homebox/backend/internal/data/ent/authroles" "github.com/hay-kot/homebox/backend/internal/data/ent/authtokens" "github.com/hay-kot/homebox/backend/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" "github.com/hay-kot/homebox/backend/internal/data/ent/group" "github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/hay-kot/homebox/backend/internal/data/ent/item" @@ -46,7 +45,6 @@ func columnChecker(table string) func(string) error { authroles.Table: authroles.ValidColumn, authtokens.Table: authtokens.ValidColumn, document.Table: document.ValidColumn, - documenttoken.Table: documenttoken.ValidColumn, group.Table: group.ValidColumn, groupinvitationtoken.Table: groupinvitationtoken.ValidColumn, item.Table: item.ValidColumn, diff --git a/backend/internal/data/ent/has_id.go b/backend/internal/data/ent/has_id.go index a6afc6a..7132131 100644 --- a/backend/internal/data/ent/has_id.go +++ b/backend/internal/data/ent/has_id.go @@ -8,6 +8,10 @@ func (a *Attachment) GetID() uuid.UUID { return a.ID } +func (ar *AuthRoles) GetID() int { + return ar.ID +} + func (at *AuthTokens) GetID() uuid.UUID { return at.ID } @@ -16,14 +20,14 @@ func (d *Document) GetID() uuid.UUID { return d.ID } -func (dt *DocumentToken) GetID() uuid.UUID { - return dt.ID -} - func (gr *Group) GetID() uuid.UUID { return gr.ID } +func (git *GroupInvitationToken) GetID() uuid.UUID { + return git.ID +} + func (i *Item) GetID() uuid.UUID { return i.ID } diff --git a/backend/internal/data/ent/hook/hook.go b/backend/internal/data/ent/hook/hook.go index 49d24c3..cc24278 100644 --- a/backend/internal/data/ent/hook/hook.go +++ b/backend/internal/data/ent/hook/hook.go @@ -61,19 +61,6 @@ func (f DocumentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er return f(ctx, mv) } -// The DocumentTokenFunc type is an adapter to allow the use of ordinary -// function as DocumentToken mutator. -type DocumentTokenFunc func(context.Context, *ent.DocumentTokenMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f DocumentTokenFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.DocumentTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DocumentTokenMutation", m) - } - return f(ctx, mv) -} - // The GroupFunc type is an adapter to allow the use of ordinary // function as Group mutator. type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error) diff --git a/backend/internal/data/ent/migrate/schema.go b/backend/internal/data/ent/migrate/schema.go index 10beaa4..fc2a146 100644 --- a/backend/internal/data/ent/migrate/schema.go +++ b/backend/internal/data/ent/migrate/schema.go @@ -110,37 +110,6 @@ var ( }, }, } - // DocumentTokensColumns holds the columns for the "document_tokens" table. - DocumentTokensColumns = []*schema.Column{ - {Name: "id", Type: field.TypeUUID}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "updated_at", Type: field.TypeTime}, - {Name: "token", Type: field.TypeBytes, Unique: true}, - {Name: "uses", Type: field.TypeInt, Default: 1}, - {Name: "expires_at", Type: field.TypeTime}, - {Name: "document_document_tokens", Type: field.TypeUUID, Nullable: true}, - } - // DocumentTokensTable holds the schema information for the "document_tokens" table. - DocumentTokensTable = &schema.Table{ - Name: "document_tokens", - Columns: DocumentTokensColumns, - PrimaryKey: []*schema.Column{DocumentTokensColumns[0]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "document_tokens_documents_document_tokens", - Columns: []*schema.Column{DocumentTokensColumns[6]}, - RefColumns: []*schema.Column{DocumentsColumns[0]}, - OnDelete: schema.Cascade, - }, - }, - Indexes: []*schema.Index{ - { - Name: "documenttoken_token", - Unique: false, - Columns: []*schema.Column{DocumentTokensColumns[3]}, - }, - }, - } // GroupsColumns holds the columns for the "groups" table. GroupsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, @@ -408,7 +377,6 @@ var ( AuthRolesTable, AuthTokensTable, DocumentsTable, - DocumentTokensTable, GroupsTable, GroupInvitationTokensTable, ItemsTable, @@ -426,7 +394,6 @@ func init() { AuthRolesTable.ForeignKeys[0].RefTable = AuthTokensTable AuthTokensTable.ForeignKeys[0].RefTable = UsersTable DocumentsTable.ForeignKeys[0].RefTable = GroupsTable - DocumentTokensTable.ForeignKeys[0].RefTable = DocumentsTable GroupInvitationTokensTable.ForeignKeys[0].RefTable = GroupsTable ItemsTable.ForeignKeys[0].RefTable = GroupsTable ItemsTable.ForeignKeys[1].RefTable = ItemsTable diff --git a/backend/internal/data/ent/mutation.go b/backend/internal/data/ent/mutation.go index ea9a441..60f49f7 100644 --- a/backend/internal/data/ent/mutation.go +++ b/backend/internal/data/ent/mutation.go @@ -14,7 +14,6 @@ import ( "github.com/hay-kot/homebox/backend/internal/data/ent/authroles" "github.com/hay-kot/homebox/backend/internal/data/ent/authtokens" "github.com/hay-kot/homebox/backend/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" "github.com/hay-kot/homebox/backend/internal/data/ent/group" "github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/hay-kot/homebox/backend/internal/data/ent/item" @@ -40,7 +39,6 @@ const ( TypeAuthRoles = "AuthRoles" TypeAuthTokens = "AuthTokens" TypeDocument = "Document" - TypeDocumentToken = "DocumentToken" TypeGroup = "Group" TypeGroupInvitationToken = "GroupInvitationToken" TypeItem = "Item" @@ -1587,25 +1585,22 @@ func (m *AuthTokensMutation) ResetEdge(name string) error { // DocumentMutation represents an operation that mutates the Document nodes in the graph. type DocumentMutation struct { config - op Op - typ string - id *uuid.UUID - created_at *time.Time - updated_at *time.Time - title *string - _path *string - clearedFields map[string]struct{} - group *uuid.UUID - clearedgroup bool - document_tokens map[uuid.UUID]struct{} - removeddocument_tokens map[uuid.UUID]struct{} - cleareddocument_tokens bool - attachments map[uuid.UUID]struct{} - removedattachments map[uuid.UUID]struct{} - clearedattachments bool - done bool - oldValue func(context.Context) (*Document, error) - predicates []predicate.Document + op Op + typ string + id *uuid.UUID + created_at *time.Time + updated_at *time.Time + title *string + _path *string + clearedFields map[string]struct{} + group *uuid.UUID + clearedgroup bool + attachments map[uuid.UUID]struct{} + removedattachments map[uuid.UUID]struct{} + clearedattachments bool + done bool + oldValue func(context.Context) (*Document, error) + predicates []predicate.Document } var _ ent.Mutation = (*DocumentMutation)(nil) @@ -1895,60 +1890,6 @@ func (m *DocumentMutation) ResetGroup() { m.clearedgroup = false } -// AddDocumentTokenIDs adds the "document_tokens" edge to the DocumentToken entity by ids. -func (m *DocumentMutation) AddDocumentTokenIDs(ids ...uuid.UUID) { - if m.document_tokens == nil { - m.document_tokens = make(map[uuid.UUID]struct{}) - } - for i := range ids { - m.document_tokens[ids[i]] = struct{}{} - } -} - -// ClearDocumentTokens clears the "document_tokens" edge to the DocumentToken entity. -func (m *DocumentMutation) ClearDocumentTokens() { - m.cleareddocument_tokens = true -} - -// DocumentTokensCleared reports if the "document_tokens" edge to the DocumentToken entity was cleared. -func (m *DocumentMutation) DocumentTokensCleared() bool { - return m.cleareddocument_tokens -} - -// RemoveDocumentTokenIDs removes the "document_tokens" edge to the DocumentToken entity by IDs. -func (m *DocumentMutation) RemoveDocumentTokenIDs(ids ...uuid.UUID) { - if m.removeddocument_tokens == nil { - m.removeddocument_tokens = make(map[uuid.UUID]struct{}) - } - for i := range ids { - delete(m.document_tokens, ids[i]) - m.removeddocument_tokens[ids[i]] = struct{}{} - } -} - -// RemovedDocumentTokens returns the removed IDs of the "document_tokens" edge to the DocumentToken entity. -func (m *DocumentMutation) RemovedDocumentTokensIDs() (ids []uuid.UUID) { - for id := range m.removeddocument_tokens { - ids = append(ids, id) - } - return -} - -// DocumentTokensIDs returns the "document_tokens" edge IDs in the mutation. -func (m *DocumentMutation) DocumentTokensIDs() (ids []uuid.UUID) { - for id := range m.document_tokens { - ids = append(ids, id) - } - return -} - -// ResetDocumentTokens resets all changes to the "document_tokens" edge. -func (m *DocumentMutation) ResetDocumentTokens() { - m.document_tokens = nil - m.cleareddocument_tokens = false - m.removeddocument_tokens = nil -} - // AddAttachmentIDs adds the "attachments" edge to the Attachment entity by ids. func (m *DocumentMutation) AddAttachmentIDs(ids ...uuid.UUID) { if m.attachments == nil { @@ -2172,13 +2113,10 @@ func (m *DocumentMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *DocumentMutation) AddedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 2) if m.group != nil { edges = append(edges, document.EdgeGroup) } - if m.document_tokens != nil { - edges = append(edges, document.EdgeDocumentTokens) - } if m.attachments != nil { edges = append(edges, document.EdgeAttachments) } @@ -2193,12 +2131,6 @@ func (m *DocumentMutation) AddedIDs(name string) []ent.Value { if id := m.group; id != nil { return []ent.Value{*id} } - case document.EdgeDocumentTokens: - ids := make([]ent.Value, 0, len(m.document_tokens)) - for id := range m.document_tokens { - ids = append(ids, id) - } - return ids case document.EdgeAttachments: ids := make([]ent.Value, 0, len(m.attachments)) for id := range m.attachments { @@ -2211,10 +2143,7 @@ func (m *DocumentMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *DocumentMutation) RemovedEdges() []string { - edges := make([]string, 0, 3) - if m.removeddocument_tokens != nil { - edges = append(edges, document.EdgeDocumentTokens) - } + edges := make([]string, 0, 2) if m.removedattachments != nil { edges = append(edges, document.EdgeAttachments) } @@ -2225,12 +2154,6 @@ func (m *DocumentMutation) RemovedEdges() []string { // the given name in this mutation. func (m *DocumentMutation) RemovedIDs(name string) []ent.Value { switch name { - case document.EdgeDocumentTokens: - ids := make([]ent.Value, 0, len(m.removeddocument_tokens)) - for id := range m.removeddocument_tokens { - ids = append(ids, id) - } - return ids case document.EdgeAttachments: ids := make([]ent.Value, 0, len(m.removedattachments)) for id := range m.removedattachments { @@ -2243,13 +2166,10 @@ func (m *DocumentMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DocumentMutation) ClearedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 2) if m.clearedgroup { edges = append(edges, document.EdgeGroup) } - if m.cleareddocument_tokens { - edges = append(edges, document.EdgeDocumentTokens) - } if m.clearedattachments { edges = append(edges, document.EdgeAttachments) } @@ -2262,8 +2182,6 @@ func (m *DocumentMutation) EdgeCleared(name string) bool { switch name { case document.EdgeGroup: return m.clearedgroup - case document.EdgeDocumentTokens: - return m.cleareddocument_tokens case document.EdgeAttachments: return m.clearedattachments } @@ -2288,9 +2206,6 @@ func (m *DocumentMutation) ResetEdge(name string) error { case document.EdgeGroup: m.ResetGroup() return nil - case document.EdgeDocumentTokens: - m.ResetDocumentTokens() - return nil case document.EdgeAttachments: m.ResetAttachments() return nil @@ -2298,642 +2213,6 @@ func (m *DocumentMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Document edge %s", name) } -// DocumentTokenMutation represents an operation that mutates the DocumentToken nodes in the graph. -type DocumentTokenMutation struct { - config - op Op - typ string - id *uuid.UUID - created_at *time.Time - updated_at *time.Time - token *[]byte - uses *int - adduses *int - expires_at *time.Time - clearedFields map[string]struct{} - document *uuid.UUID - cleareddocument bool - done bool - oldValue func(context.Context) (*DocumentToken, error) - predicates []predicate.DocumentToken -} - -var _ ent.Mutation = (*DocumentTokenMutation)(nil) - -// documenttokenOption allows management of the mutation configuration using functional options. -type documenttokenOption func(*DocumentTokenMutation) - -// newDocumentTokenMutation creates new mutation for the DocumentToken entity. -func newDocumentTokenMutation(c config, op Op, opts ...documenttokenOption) *DocumentTokenMutation { - m := &DocumentTokenMutation{ - config: c, - op: op, - typ: TypeDocumentToken, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withDocumentTokenID sets the ID field of the mutation. -func withDocumentTokenID(id uuid.UUID) documenttokenOption { - return func(m *DocumentTokenMutation) { - var ( - err error - once sync.Once - value *DocumentToken - ) - m.oldValue = func(ctx context.Context) (*DocumentToken, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().DocumentToken.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withDocumentToken sets the old DocumentToken of the mutation. -func withDocumentToken(node *DocumentToken) documenttokenOption { - return func(m *DocumentTokenMutation) { - m.oldValue = func(context.Context) (*DocumentToken, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m DocumentTokenMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m DocumentTokenMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of DocumentToken entities. -func (m *DocumentTokenMutation) SetID(id uuid.UUID) { - m.id = &id -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *DocumentTokenMutation) ID() (id uuid.UUID, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// IDs queries the database and returns the entity ids that match the mutation's predicate. -// That means, if the mutation is applied within a transaction with an isolation level such -// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated -// or updated by the mutation. -func (m *DocumentTokenMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { - switch { - case m.op.Is(OpUpdateOne | OpDeleteOne): - id, exists := m.ID() - if exists { - return []uuid.UUID{id}, nil - } - fallthrough - case m.op.Is(OpUpdate | OpDelete): - return m.Client().DocumentToken.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetCreatedAt sets the "created_at" field. -func (m *DocumentTokenMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *DocumentTokenMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the DocumentToken entity. -// If the DocumentToken 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 *DocumentTokenMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *DocumentTokenMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *DocumentTokenMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *DocumentTokenMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return - } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the DocumentToken entity. -// If the DocumentToken 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 *DocumentTokenMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUpdatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) - } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *DocumentTokenMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetToken sets the "token" field. -func (m *DocumentTokenMutation) SetToken(b []byte) { - m.token = &b -} - -// Token returns the value of the "token" field in the mutation. -func (m *DocumentTokenMutation) Token() (r []byte, exists bool) { - v := m.token - if v == nil { - return - } - return *v, true -} - -// OldToken returns the old "token" field's value of the DocumentToken entity. -// If the DocumentToken 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 *DocumentTokenMutation) OldToken(ctx context.Context) (v []byte, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldToken is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldToken requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldToken: %w", err) - } - return oldValue.Token, nil -} - -// ResetToken resets all changes to the "token" field. -func (m *DocumentTokenMutation) ResetToken() { - m.token = nil -} - -// SetUses sets the "uses" field. -func (m *DocumentTokenMutation) SetUses(i int) { - m.uses = &i - m.adduses = nil -} - -// Uses returns the value of the "uses" field in the mutation. -func (m *DocumentTokenMutation) Uses() (r int, exists bool) { - v := m.uses - if v == nil { - return - } - return *v, true -} - -// OldUses returns the old "uses" field's value of the DocumentToken entity. -// If the DocumentToken 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 *DocumentTokenMutation) OldUses(ctx context.Context) (v int, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUses is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUses requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUses: %w", err) - } - return oldValue.Uses, nil -} - -// AddUses adds i to the "uses" field. -func (m *DocumentTokenMutation) AddUses(i int) { - if m.adduses != nil { - *m.adduses += i - } else { - m.adduses = &i - } -} - -// AddedUses returns the value that was added to the "uses" field in this mutation. -func (m *DocumentTokenMutation) AddedUses() (r int, exists bool) { - v := m.adduses - if v == nil { - return - } - return *v, true -} - -// ResetUses resets all changes to the "uses" field. -func (m *DocumentTokenMutation) ResetUses() { - m.uses = nil - m.adduses = nil -} - -// SetExpiresAt sets the "expires_at" field. -func (m *DocumentTokenMutation) SetExpiresAt(t time.Time) { - m.expires_at = &t -} - -// ExpiresAt returns the value of the "expires_at" field in the mutation. -func (m *DocumentTokenMutation) ExpiresAt() (r time.Time, exists bool) { - v := m.expires_at - if v == nil { - return - } - return *v, true -} - -// OldExpiresAt returns the old "expires_at" field's value of the DocumentToken entity. -// If the DocumentToken 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 *DocumentTokenMutation) OldExpiresAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldExpiresAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err) - } - return oldValue.ExpiresAt, nil -} - -// ResetExpiresAt resets all changes to the "expires_at" field. -func (m *DocumentTokenMutation) ResetExpiresAt() { - m.expires_at = nil -} - -// SetDocumentID sets the "document" edge to the Document entity by id. -func (m *DocumentTokenMutation) SetDocumentID(id uuid.UUID) { - m.document = &id -} - -// ClearDocument clears the "document" edge to the Document entity. -func (m *DocumentTokenMutation) ClearDocument() { - m.cleareddocument = true -} - -// DocumentCleared reports if the "document" edge to the Document entity was cleared. -func (m *DocumentTokenMutation) DocumentCleared() bool { - return m.cleareddocument -} - -// DocumentID returns the "document" edge ID in the mutation. -func (m *DocumentTokenMutation) DocumentID() (id uuid.UUID, exists bool) { - if m.document != nil { - return *m.document, true - } - return -} - -// DocumentIDs returns the "document" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// DocumentID instead. It exists only for internal usage by the builders. -func (m *DocumentTokenMutation) DocumentIDs() (ids []uuid.UUID) { - if id := m.document; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetDocument resets all changes to the "document" edge. -func (m *DocumentTokenMutation) ResetDocument() { - m.document = nil - m.cleareddocument = false -} - -// Where appends a list predicates to the DocumentTokenMutation builder. -func (m *DocumentTokenMutation) Where(ps ...predicate.DocumentToken) { - m.predicates = append(m.predicates, ps...) -} - -// Op returns the operation name. -func (m *DocumentTokenMutation) Op() Op { - return m.op -} - -// Type returns the node type of this mutation (DocumentToken). -func (m *DocumentTokenMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *DocumentTokenMutation) Fields() []string { - fields := make([]string, 0, 5) - if m.created_at != nil { - fields = append(fields, documenttoken.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, documenttoken.FieldUpdatedAt) - } - if m.token != nil { - fields = append(fields, documenttoken.FieldToken) - } - if m.uses != nil { - fields = append(fields, documenttoken.FieldUses) - } - if m.expires_at != nil { - fields = append(fields, documenttoken.FieldExpiresAt) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *DocumentTokenMutation) Field(name string) (ent.Value, bool) { - switch name { - case documenttoken.FieldCreatedAt: - return m.CreatedAt() - case documenttoken.FieldUpdatedAt: - return m.UpdatedAt() - case documenttoken.FieldToken: - return m.Token() - case documenttoken.FieldUses: - return m.Uses() - case documenttoken.FieldExpiresAt: - return m.ExpiresAt() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *DocumentTokenMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case documenttoken.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case documenttoken.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case documenttoken.FieldToken: - return m.OldToken(ctx) - case documenttoken.FieldUses: - return m.OldUses(ctx) - case documenttoken.FieldExpiresAt: - return m.OldExpiresAt(ctx) - } - return nil, fmt.Errorf("unknown DocumentToken field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *DocumentTokenMutation) SetField(name string, value ent.Value) error { - switch name { - case documenttoken.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case documenttoken.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - case documenttoken.FieldToken: - v, ok := value.([]byte) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetToken(v) - return nil - case documenttoken.FieldUses: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUses(v) - return nil - case documenttoken.FieldExpiresAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetExpiresAt(v) - return nil - } - return fmt.Errorf("unknown DocumentToken field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *DocumentTokenMutation) AddedFields() []string { - var fields []string - if m.adduses != nil { - fields = append(fields, documenttoken.FieldUses) - } - return fields -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *DocumentTokenMutation) AddedField(name string) (ent.Value, bool) { - switch name { - case documenttoken.FieldUses: - return m.AddedUses() - } - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *DocumentTokenMutation) AddField(name string, value ent.Value) error { - switch name { - case documenttoken.FieldUses: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddUses(v) - return nil - } - return fmt.Errorf("unknown DocumentToken numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *DocumentTokenMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *DocumentTokenMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *DocumentTokenMutation) ClearField(name string) error { - return fmt.Errorf("unknown DocumentToken nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *DocumentTokenMutation) ResetField(name string) error { - switch name { - case documenttoken.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case documenttoken.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case documenttoken.FieldToken: - m.ResetToken() - return nil - case documenttoken.FieldUses: - m.ResetUses() - return nil - case documenttoken.FieldExpiresAt: - m.ResetExpiresAt() - return nil - } - return fmt.Errorf("unknown DocumentToken field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *DocumentTokenMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.document != nil { - edges = append(edges, documenttoken.EdgeDocument) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *DocumentTokenMutation) AddedIDs(name string) []ent.Value { - switch name { - case documenttoken.EdgeDocument: - if id := m.document; id != nil { - return []ent.Value{*id} - } - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *DocumentTokenMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *DocumentTokenMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *DocumentTokenMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.cleareddocument { - edges = append(edges, documenttoken.EdgeDocument) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *DocumentTokenMutation) EdgeCleared(name string) bool { - switch name { - case documenttoken.EdgeDocument: - return m.cleareddocument - } - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *DocumentTokenMutation) ClearEdge(name string) error { - switch name { - case documenttoken.EdgeDocument: - m.ClearDocument() - return nil - } - return fmt.Errorf("unknown DocumentToken unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *DocumentTokenMutation) ResetEdge(name string) error { - switch name { - case documenttoken.EdgeDocument: - m.ResetDocument() - return nil - } - return fmt.Errorf("unknown DocumentToken edge %s", name) -} - // GroupMutation represents an operation that mutates the Group nodes in the graph. type GroupMutation struct { config diff --git a/backend/internal/data/ent/predicate/predicate.go b/backend/internal/data/ent/predicate/predicate.go index 21a0a71..e801e9b 100644 --- a/backend/internal/data/ent/predicate/predicate.go +++ b/backend/internal/data/ent/predicate/predicate.go @@ -18,9 +18,6 @@ type AuthTokens func(*sql.Selector) // Document is the predicate function for document builders. type Document func(*sql.Selector) -// DocumentToken is the predicate function for documenttoken builders. -type DocumentToken func(*sql.Selector) - // Group is the predicate function for group builders. type Group func(*sql.Selector) diff --git a/backend/internal/data/ent/runtime.go b/backend/internal/data/ent/runtime.go index a9edda6..42eabcc 100644 --- a/backend/internal/data/ent/runtime.go +++ b/backend/internal/data/ent/runtime.go @@ -9,7 +9,6 @@ import ( "github.com/hay-kot/homebox/backend/internal/data/ent/attachment" "github.com/hay-kot/homebox/backend/internal/data/ent/authtokens" "github.com/hay-kot/homebox/backend/internal/data/ent/document" - "github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken" "github.com/hay-kot/homebox/backend/internal/data/ent/group" "github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/hay-kot/homebox/backend/internal/data/ent/item" @@ -123,37 +122,6 @@ func init() { documentDescID := documentMixinFields0[0].Descriptor() // document.DefaultID holds the default value on creation for the id field. document.DefaultID = documentDescID.Default.(func() uuid.UUID) - documenttokenMixin := schema.DocumentToken{}.Mixin() - documenttokenMixinFields0 := documenttokenMixin[0].Fields() - _ = documenttokenMixinFields0 - documenttokenFields := schema.DocumentToken{}.Fields() - _ = documenttokenFields - // documenttokenDescCreatedAt is the schema descriptor for created_at field. - documenttokenDescCreatedAt := documenttokenMixinFields0[1].Descriptor() - // documenttoken.DefaultCreatedAt holds the default value on creation for the created_at field. - documenttoken.DefaultCreatedAt = documenttokenDescCreatedAt.Default.(func() time.Time) - // documenttokenDescUpdatedAt is the schema descriptor for updated_at field. - documenttokenDescUpdatedAt := documenttokenMixinFields0[2].Descriptor() - // documenttoken.DefaultUpdatedAt holds the default value on creation for the updated_at field. - documenttoken.DefaultUpdatedAt = documenttokenDescUpdatedAt.Default.(func() time.Time) - // documenttoken.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. - documenttoken.UpdateDefaultUpdatedAt = documenttokenDescUpdatedAt.UpdateDefault.(func() time.Time) - // documenttokenDescToken is the schema descriptor for token field. - documenttokenDescToken := documenttokenFields[0].Descriptor() - // documenttoken.TokenValidator is a validator for the "token" field. It is called by the builders before save. - documenttoken.TokenValidator = documenttokenDescToken.Validators[0].(func([]byte) error) - // documenttokenDescUses is the schema descriptor for uses field. - documenttokenDescUses := documenttokenFields[1].Descriptor() - // documenttoken.DefaultUses holds the default value on creation for the uses field. - documenttoken.DefaultUses = documenttokenDescUses.Default.(int) - // documenttokenDescExpiresAt is the schema descriptor for expires_at field. - documenttokenDescExpiresAt := documenttokenFields[2].Descriptor() - // documenttoken.DefaultExpiresAt holds the default value on creation for the expires_at field. - documenttoken.DefaultExpiresAt = documenttokenDescExpiresAt.Default.(func() time.Time) - // documenttokenDescID is the schema descriptor for id field. - documenttokenDescID := documenttokenMixinFields0[0].Descriptor() - // documenttoken.DefaultID holds the default value on creation for the id field. - documenttoken.DefaultID = documenttokenDescID.Default.(func() uuid.UUID) groupMixin := schema.Group{}.Mixin() groupMixinFields0 := groupMixin[0].Fields() _ = groupMixinFields0 diff --git a/backend/internal/data/ent/tx.go b/backend/internal/data/ent/tx.go index 8af5b01..810c2cf 100644 --- a/backend/internal/data/ent/tx.go +++ b/backend/internal/data/ent/tx.go @@ -20,8 +20,6 @@ type Tx struct { AuthTokens *AuthTokensClient // Document is the client for interacting with the Document builders. Document *DocumentClient - // DocumentToken is the client for interacting with the DocumentToken builders. - DocumentToken *DocumentTokenClient // Group is the client for interacting with the Group builders. Group *GroupClient // GroupInvitationToken is the client for interacting with the GroupInvitationToken builders. @@ -171,7 +169,6 @@ func (tx *Tx) init() { tx.AuthRoles = NewAuthRolesClient(tx.config) tx.AuthTokens = NewAuthTokensClient(tx.config) tx.Document = NewDocumentClient(tx.config) - tx.DocumentToken = NewDocumentTokenClient(tx.config) tx.Group = NewGroupClient(tx.config) tx.GroupInvitationToken = NewGroupInvitationTokenClient(tx.config) tx.Item = NewItemClient(tx.config)