forked from mirrors/homebox
add group_id to notifier
This commit is contained in:
parent
43b34e2899
commit
37857682e6
18 changed files with 919 additions and 18 deletions
|
@ -1033,6 +1033,22 @@ func (c *GroupClient) QueryInvitationTokens(gr *Group) *GroupInvitationTokenQuer
|
|||
return query
|
||||
}
|
||||
|
||||
// QueryNotifiers queries the notifiers edge of a Group.
|
||||
func (c *GroupClient) QueryNotifiers(gr *Group) *NotifierQuery {
|
||||
query := (&NotifierClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := gr.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
sqlgraph.To(notifier.Table, notifier.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, group.NotifiersTable, group.NotifiersColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(gr.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *GroupClient) Hooks() []Hook {
|
||||
return c.hooks.Group
|
||||
|
@ -2147,6 +2163,22 @@ func (c *NotifierClient) QueryUser(n *Notifier) *UserQuery {
|
|||
return query
|
||||
}
|
||||
|
||||
// QueryGroup queries the group edge of a Notifier.
|
||||
func (c *NotifierClient) QueryGroup(n *Notifier) *GroupQuery {
|
||||
query := (&GroupClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := n.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(notifier.Table, notifier.FieldID, id),
|
||||
sqlgraph.To(group.Table, group.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, notifier.GroupTable, notifier.GroupColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(n.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *NotifierClient) Hooks() []Hook {
|
||||
return c.hooks.Notifier
|
||||
|
|
|
@ -44,9 +44,11 @@ type GroupEdges struct {
|
|||
Documents []*Document `json:"documents,omitempty"`
|
||||
// InvitationTokens holds the value of the invitation_tokens edge.
|
||||
InvitationTokens []*GroupInvitationToken `json:"invitation_tokens,omitempty"`
|
||||
// Notifiers holds the value of the notifiers edge.
|
||||
Notifiers []*Notifier `json:"notifiers,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [6]bool
|
||||
loadedTypes [7]bool
|
||||
}
|
||||
|
||||
// UsersOrErr returns the Users value or an error if the edge
|
||||
|
@ -103,6 +105,15 @@ func (e GroupEdges) InvitationTokensOrErr() ([]*GroupInvitationToken, error) {
|
|||
return nil, &NotLoadedError{edge: "invitation_tokens"}
|
||||
}
|
||||
|
||||
// NotifiersOrErr returns the Notifiers value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e GroupEdges) NotifiersOrErr() ([]*Notifier, error) {
|
||||
if e.loadedTypes[6] {
|
||||
return e.Notifiers, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "notifiers"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Group) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
|
@ -194,6 +205,11 @@ func (gr *Group) QueryInvitationTokens() *GroupInvitationTokenQuery {
|
|||
return NewGroupClient(gr.config).QueryInvitationTokens(gr)
|
||||
}
|
||||
|
||||
// QueryNotifiers queries the "notifiers" edge of the Group entity.
|
||||
func (gr *Group) QueryNotifiers() *NotifierQuery {
|
||||
return NewGroupClient(gr.config).QueryNotifiers(gr)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Group.
|
||||
// Note that you need to call Group.Unwrap() before calling this method if this Group
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
|
|
|
@ -34,6 +34,8 @@ const (
|
|||
EdgeDocuments = "documents"
|
||||
// EdgeInvitationTokens holds the string denoting the invitation_tokens edge name in mutations.
|
||||
EdgeInvitationTokens = "invitation_tokens"
|
||||
// EdgeNotifiers holds the string denoting the notifiers edge name in mutations.
|
||||
EdgeNotifiers = "notifiers"
|
||||
// Table holds the table name of the group in the database.
|
||||
Table = "groups"
|
||||
// UsersTable is the table that holds the users relation/edge.
|
||||
|
@ -78,6 +80,13 @@ const (
|
|||
InvitationTokensInverseTable = "group_invitation_tokens"
|
||||
// InvitationTokensColumn is the table column denoting the invitation_tokens relation/edge.
|
||||
InvitationTokensColumn = "group_invitation_tokens"
|
||||
// NotifiersTable is the table that holds the notifiers relation/edge.
|
||||
NotifiersTable = "notifiers"
|
||||
// NotifiersInverseTable is the table name for the Notifier entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "notifier" package.
|
||||
NotifiersInverseTable = "notifiers"
|
||||
// NotifiersColumn is the table column denoting the notifiers relation/edge.
|
||||
NotifiersColumn = "group_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for group fields.
|
||||
|
|
|
@ -398,6 +398,33 @@ func HasInvitationTokensWith(preds ...predicate.GroupInvitationToken) predicate.
|
|||
})
|
||||
}
|
||||
|
||||
// HasNotifiers applies the HasEdge predicate on the "notifiers" edge.
|
||||
func HasNotifiers() predicate.Group {
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, NotifiersTable, NotifiersColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasNotifiersWith applies the HasEdge predicate on the "notifiers" edge with a given conditions (other predicates).
|
||||
func HasNotifiersWith(preds ...predicate.Notifier) predicate.Group {
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(NotifiersInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, NotifiersTable, NotifiersColumn),
|
||||
)
|
||||
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.Group) predicate.Group {
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/notifier"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||
)
|
||||
|
||||
|
@ -179,6 +180,21 @@ func (gc *GroupCreate) AddInvitationTokens(g ...*GroupInvitationToken) *GroupCre
|
|||
return gc.AddInvitationTokenIDs(ids...)
|
||||
}
|
||||
|
||||
// AddNotifierIDs adds the "notifiers" edge to the Notifier entity by IDs.
|
||||
func (gc *GroupCreate) AddNotifierIDs(ids ...uuid.UUID) *GroupCreate {
|
||||
gc.mutation.AddNotifierIDs(ids...)
|
||||
return gc
|
||||
}
|
||||
|
||||
// AddNotifiers adds the "notifiers" edges to the Notifier entity.
|
||||
func (gc *GroupCreate) AddNotifiers(n ...*Notifier) *GroupCreate {
|
||||
ids := make([]uuid.UUID, len(n))
|
||||
for i := range n {
|
||||
ids[i] = n[i].ID
|
||||
}
|
||||
return gc.AddNotifierIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the GroupMutation object of the builder.
|
||||
func (gc *GroupCreate) Mutation() *GroupMutation {
|
||||
return gc.mutation
|
||||
|
@ -421,6 +437,25 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
|
|||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := gc.mutation.NotifiersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: group.NotifiersTable,
|
||||
Columns: []string{group.NotifiersColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: notifier.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/notifier"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||
)
|
||||
|
@ -35,6 +36,7 @@ type GroupQuery struct {
|
|||
withLabels *LabelQuery
|
||||
withDocuments *DocumentQuery
|
||||
withInvitationTokens *GroupInvitationTokenQuery
|
||||
withNotifiers *NotifierQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
@ -203,6 +205,28 @@ func (gq *GroupQuery) QueryInvitationTokens() *GroupInvitationTokenQuery {
|
|||
return query
|
||||
}
|
||||
|
||||
// QueryNotifiers chains the current query on the "notifiers" edge.
|
||||
func (gq *GroupQuery) QueryNotifiers() *NotifierQuery {
|
||||
query := (&NotifierClient{config: gq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := gq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, selector),
|
||||
sqlgraph.To(notifier.Table, notifier.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, group.NotifiersTable, group.NotifiersColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(gq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Group entity from the query.
|
||||
// Returns a *NotFoundError when no Group was found.
|
||||
func (gq *GroupQuery) First(ctx context.Context) (*Group, error) {
|
||||
|
@ -401,6 +425,7 @@ func (gq *GroupQuery) Clone() *GroupQuery {
|
|||
withLabels: gq.withLabels.Clone(),
|
||||
withDocuments: gq.withDocuments.Clone(),
|
||||
withInvitationTokens: gq.withInvitationTokens.Clone(),
|
||||
withNotifiers: gq.withNotifiers.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: gq.sql.Clone(),
|
||||
path: gq.path,
|
||||
|
@ -473,6 +498,17 @@ func (gq *GroupQuery) WithInvitationTokens(opts ...func(*GroupInvitationTokenQue
|
|||
return gq
|
||||
}
|
||||
|
||||
// WithNotifiers tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "notifiers" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (gq *GroupQuery) WithNotifiers(opts ...func(*NotifierQuery)) *GroupQuery {
|
||||
query := (&NotifierClient{config: gq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
gq.withNotifiers = query
|
||||
return gq
|
||||
}
|
||||
|
||||
// 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.
|
||||
//
|
||||
|
@ -551,13 +587,14 @@ func (gq *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group,
|
|||
var (
|
||||
nodes = []*Group{}
|
||||
_spec = gq.querySpec()
|
||||
loadedTypes = [6]bool{
|
||||
loadedTypes = [7]bool{
|
||||
gq.withUsers != nil,
|
||||
gq.withLocations != nil,
|
||||
gq.withItems != nil,
|
||||
gq.withLabels != nil,
|
||||
gq.withDocuments != nil,
|
||||
gq.withInvitationTokens != nil,
|
||||
gq.withNotifiers != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
|
@ -622,6 +659,13 @@ func (gq *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group,
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := gq.withNotifiers; query != nil {
|
||||
if err := gq.loadNotifiers(ctx, query, nodes,
|
||||
func(n *Group) { n.Edges.Notifiers = []*Notifier{} },
|
||||
func(n *Group, e *Notifier) { n.Edges.Notifiers = append(n.Edges.Notifiers, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
@ -811,6 +855,33 @@ func (gq *GroupQuery) loadInvitationTokens(ctx context.Context, query *GroupInvi
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func (gq *GroupQuery) loadNotifiers(ctx context.Context, query *NotifierQuery, nodes []*Group, init func(*Group), assign func(*Group, *Notifier)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*Group)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.Where(predicate.Notifier(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(group.NotifiersColumn, fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.GroupID
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "group_id" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gq *GroupQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := gq.querySpec()
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/notifier"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||
)
|
||||
|
@ -151,6 +152,21 @@ func (gu *GroupUpdate) AddInvitationTokens(g ...*GroupInvitationToken) *GroupUpd
|
|||
return gu.AddInvitationTokenIDs(ids...)
|
||||
}
|
||||
|
||||
// AddNotifierIDs adds the "notifiers" edge to the Notifier entity by IDs.
|
||||
func (gu *GroupUpdate) AddNotifierIDs(ids ...uuid.UUID) *GroupUpdate {
|
||||
gu.mutation.AddNotifierIDs(ids...)
|
||||
return gu
|
||||
}
|
||||
|
||||
// AddNotifiers adds the "notifiers" edges to the Notifier entity.
|
||||
func (gu *GroupUpdate) AddNotifiers(n ...*Notifier) *GroupUpdate {
|
||||
ids := make([]uuid.UUID, len(n))
|
||||
for i := range n {
|
||||
ids[i] = n[i].ID
|
||||
}
|
||||
return gu.AddNotifierIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the GroupMutation object of the builder.
|
||||
func (gu *GroupUpdate) Mutation() *GroupMutation {
|
||||
return gu.mutation
|
||||
|
@ -282,6 +298,27 @@ func (gu *GroupUpdate) RemoveInvitationTokens(g ...*GroupInvitationToken) *Group
|
|||
return gu.RemoveInvitationTokenIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearNotifiers clears all "notifiers" edges to the Notifier entity.
|
||||
func (gu *GroupUpdate) ClearNotifiers() *GroupUpdate {
|
||||
gu.mutation.ClearNotifiers()
|
||||
return gu
|
||||
}
|
||||
|
||||
// RemoveNotifierIDs removes the "notifiers" edge to Notifier entities by IDs.
|
||||
func (gu *GroupUpdate) RemoveNotifierIDs(ids ...uuid.UUID) *GroupUpdate {
|
||||
gu.mutation.RemoveNotifierIDs(ids...)
|
||||
return gu
|
||||
}
|
||||
|
||||
// RemoveNotifiers removes "notifiers" edges to Notifier entities.
|
||||
func (gu *GroupUpdate) RemoveNotifiers(n ...*Notifier) *GroupUpdate {
|
||||
ids := make([]uuid.UUID, len(n))
|
||||
for i := range n {
|
||||
ids[i] = n[i].ID
|
||||
}
|
||||
return gu.RemoveNotifierIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (gu *GroupUpdate) Save(ctx context.Context) (int, error) {
|
||||
gu.defaults()
|
||||
|
@ -678,6 +715,60 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if gu.mutation.NotifiersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: group.NotifiersTable,
|
||||
Columns: []string{group.NotifiersColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: notifier.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := gu.mutation.RemovedNotifiersIDs(); len(nodes) > 0 && !gu.mutation.NotifiersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: group.NotifiersTable,
|
||||
Columns: []string{group.NotifiersColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: notifier.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := gu.mutation.NotifiersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: group.NotifiersTable,
|
||||
Columns: []string{group.NotifiersColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: notifier.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, gu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{group.Label}
|
||||
|
@ -814,6 +905,21 @@ func (guo *GroupUpdateOne) AddInvitationTokens(g ...*GroupInvitationToken) *Grou
|
|||
return guo.AddInvitationTokenIDs(ids...)
|
||||
}
|
||||
|
||||
// AddNotifierIDs adds the "notifiers" edge to the Notifier entity by IDs.
|
||||
func (guo *GroupUpdateOne) AddNotifierIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||||
guo.mutation.AddNotifierIDs(ids...)
|
||||
return guo
|
||||
}
|
||||
|
||||
// AddNotifiers adds the "notifiers" edges to the Notifier entity.
|
||||
func (guo *GroupUpdateOne) AddNotifiers(n ...*Notifier) *GroupUpdateOne {
|
||||
ids := make([]uuid.UUID, len(n))
|
||||
for i := range n {
|
||||
ids[i] = n[i].ID
|
||||
}
|
||||
return guo.AddNotifierIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the GroupMutation object of the builder.
|
||||
func (guo *GroupUpdateOne) Mutation() *GroupMutation {
|
||||
return guo.mutation
|
||||
|
@ -945,6 +1051,27 @@ func (guo *GroupUpdateOne) RemoveInvitationTokens(g ...*GroupInvitationToken) *G
|
|||
return guo.RemoveInvitationTokenIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearNotifiers clears all "notifiers" edges to the Notifier entity.
|
||||
func (guo *GroupUpdateOne) ClearNotifiers() *GroupUpdateOne {
|
||||
guo.mutation.ClearNotifiers()
|
||||
return guo
|
||||
}
|
||||
|
||||
// RemoveNotifierIDs removes the "notifiers" edge to Notifier entities by IDs.
|
||||
func (guo *GroupUpdateOne) RemoveNotifierIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||||
guo.mutation.RemoveNotifierIDs(ids...)
|
||||
return guo
|
||||
}
|
||||
|
||||
// RemoveNotifiers removes "notifiers" edges to Notifier entities.
|
||||
func (guo *GroupUpdateOne) RemoveNotifiers(n ...*Notifier) *GroupUpdateOne {
|
||||
ids := make([]uuid.UUID, len(n))
|
||||
for i := range n {
|
||||
ids[i] = n[i].ID
|
||||
}
|
||||
return guo.RemoveNotifierIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupUpdate builder.
|
||||
func (guo *GroupUpdateOne) Where(ps ...predicate.Group) *GroupUpdateOne {
|
||||
guo.mutation.Where(ps...)
|
||||
|
@ -1371,6 +1498,60 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error
|
|||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if guo.mutation.NotifiersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: group.NotifiersTable,
|
||||
Columns: []string{group.NotifiersColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: notifier.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := guo.mutation.RemovedNotifiersIDs(); len(nodes) > 0 && !guo.mutation.NotifiersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: group.NotifiersTable,
|
||||
Columns: []string{group.NotifiersColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: notifier.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := guo.mutation.NotifiersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: group.NotifiersTable,
|
||||
Columns: []string{group.NotifiersColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: notifier.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Group{config: guo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
|
|
@ -352,6 +352,7 @@ var (
|
|||
{Name: "name", Type: field.TypeString, Size: 255},
|
||||
{Name: "url", Type: field.TypeString, Size: 2083},
|
||||
{Name: "is_active", Type: field.TypeBool, Default: true},
|
||||
{Name: "group_id", Type: field.TypeUUID},
|
||||
{Name: "user_id", Type: field.TypeUUID},
|
||||
}
|
||||
// NotifiersTable holds the schema information for the "notifiers" table.
|
||||
|
@ -361,8 +362,14 @@ var (
|
|||
PrimaryKey: []*schema.Column{NotifiersColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "notifiers_users_notifiers",
|
||||
Symbol: "notifiers_groups_notifiers",
|
||||
Columns: []*schema.Column{NotifiersColumns[6]},
|
||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "notifiers_users_notifiers",
|
||||
Columns: []*schema.Column{NotifiersColumns[7]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
|
@ -371,11 +378,21 @@ var (
|
|||
{
|
||||
Name: "notifier_user_id",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{NotifiersColumns[6]},
|
||||
Columns: []*schema.Column{NotifiersColumns[7]},
|
||||
},
|
||||
{
|
||||
Name: "notifier_user_id_is_active",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{NotifiersColumns[7], NotifiersColumns[5]},
|
||||
},
|
||||
{
|
||||
Name: "notifier_group_id",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{NotifiersColumns[6]},
|
||||
},
|
||||
{
|
||||
Name: "notifier_group_id_is_active",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{NotifiersColumns[6], NotifiersColumns[5]},
|
||||
},
|
||||
},
|
||||
|
@ -467,7 +484,8 @@ func init() {
|
|||
LocationsTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
LocationsTable.ForeignKeys[1].RefTable = LocationsTable
|
||||
MaintenanceEntriesTable.ForeignKeys[0].RefTable = ItemsTable
|
||||
NotifiersTable.ForeignKeys[0].RefTable = UsersTable
|
||||
NotifiersTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
NotifiersTable.ForeignKeys[1].RefTable = UsersTable
|
||||
UsersTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
LabelItemsTable.ForeignKeys[0].RefTable = LabelsTable
|
||||
LabelItemsTable.ForeignKeys[1].RefTable = ItemsTable
|
||||
|
|
|
@ -2307,6 +2307,9 @@ type GroupMutation struct {
|
|||
invitation_tokens map[uuid.UUID]struct{}
|
||||
removedinvitation_tokens map[uuid.UUID]struct{}
|
||||
clearedinvitation_tokens bool
|
||||
notifiers map[uuid.UUID]struct{}
|
||||
removednotifiers map[uuid.UUID]struct{}
|
||||
clearednotifiers bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*Group, error)
|
||||
predicates []predicate.Group
|
||||
|
@ -2884,6 +2887,60 @@ func (m *GroupMutation) ResetInvitationTokens() {
|
|||
m.removedinvitation_tokens = nil
|
||||
}
|
||||
|
||||
// AddNotifierIDs adds the "notifiers" edge to the Notifier entity by ids.
|
||||
func (m *GroupMutation) AddNotifierIDs(ids ...uuid.UUID) {
|
||||
if m.notifiers == nil {
|
||||
m.notifiers = make(map[uuid.UUID]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.notifiers[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearNotifiers clears the "notifiers" edge to the Notifier entity.
|
||||
func (m *GroupMutation) ClearNotifiers() {
|
||||
m.clearednotifiers = true
|
||||
}
|
||||
|
||||
// NotifiersCleared reports if the "notifiers" edge to the Notifier entity was cleared.
|
||||
func (m *GroupMutation) NotifiersCleared() bool {
|
||||
return m.clearednotifiers
|
||||
}
|
||||
|
||||
// RemoveNotifierIDs removes the "notifiers" edge to the Notifier entity by IDs.
|
||||
func (m *GroupMutation) RemoveNotifierIDs(ids ...uuid.UUID) {
|
||||
if m.removednotifiers == nil {
|
||||
m.removednotifiers = make(map[uuid.UUID]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.notifiers, ids[i])
|
||||
m.removednotifiers[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedNotifiers returns the removed IDs of the "notifiers" edge to the Notifier entity.
|
||||
func (m *GroupMutation) RemovedNotifiersIDs() (ids []uuid.UUID) {
|
||||
for id := range m.removednotifiers {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// NotifiersIDs returns the "notifiers" edge IDs in the mutation.
|
||||
func (m *GroupMutation) NotifiersIDs() (ids []uuid.UUID) {
|
||||
for id := range m.notifiers {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetNotifiers resets all changes to the "notifiers" edge.
|
||||
func (m *GroupMutation) ResetNotifiers() {
|
||||
m.notifiers = nil
|
||||
m.clearednotifiers = false
|
||||
m.removednotifiers = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupMutation builder.
|
||||
func (m *GroupMutation) Where(ps ...predicate.Group) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
|
@ -3068,7 +3125,7 @@ func (m *GroupMutation) ResetField(name string) error {
|
|||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *GroupMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 6)
|
||||
edges := make([]string, 0, 7)
|
||||
if m.users != nil {
|
||||
edges = append(edges, group.EdgeUsers)
|
||||
}
|
||||
|
@ -3087,6 +3144,9 @@ func (m *GroupMutation) AddedEdges() []string {
|
|||
if m.invitation_tokens != nil {
|
||||
edges = append(edges, group.EdgeInvitationTokens)
|
||||
}
|
||||
if m.notifiers != nil {
|
||||
edges = append(edges, group.EdgeNotifiers)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
|
@ -3130,13 +3190,19 @@ func (m *GroupMutation) AddedIDs(name string) []ent.Value {
|
|||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case group.EdgeNotifiers:
|
||||
ids := make([]ent.Value, 0, len(m.notifiers))
|
||||
for id := range m.notifiers {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *GroupMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 6)
|
||||
edges := make([]string, 0, 7)
|
||||
if m.removedusers != nil {
|
||||
edges = append(edges, group.EdgeUsers)
|
||||
}
|
||||
|
@ -3155,6 +3221,9 @@ func (m *GroupMutation) RemovedEdges() []string {
|
|||
if m.removedinvitation_tokens != nil {
|
||||
edges = append(edges, group.EdgeInvitationTokens)
|
||||
}
|
||||
if m.removednotifiers != nil {
|
||||
edges = append(edges, group.EdgeNotifiers)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
|
@ -3198,13 +3267,19 @@ func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
|
|||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case group.EdgeNotifiers:
|
||||
ids := make([]ent.Value, 0, len(m.removednotifiers))
|
||||
for id := range m.removednotifiers {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *GroupMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 6)
|
||||
edges := make([]string, 0, 7)
|
||||
if m.clearedusers {
|
||||
edges = append(edges, group.EdgeUsers)
|
||||
}
|
||||
|
@ -3223,6 +3298,9 @@ func (m *GroupMutation) ClearedEdges() []string {
|
|||
if m.clearedinvitation_tokens {
|
||||
edges = append(edges, group.EdgeInvitationTokens)
|
||||
}
|
||||
if m.clearednotifiers {
|
||||
edges = append(edges, group.EdgeNotifiers)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
|
@ -3242,6 +3320,8 @@ func (m *GroupMutation) EdgeCleared(name string) bool {
|
|||
return m.cleareddocuments
|
||||
case group.EdgeInvitationTokens:
|
||||
return m.clearedinvitation_tokens
|
||||
case group.EdgeNotifiers:
|
||||
return m.clearednotifiers
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -3276,6 +3356,9 @@ func (m *GroupMutation) ResetEdge(name string) error {
|
|||
case group.EdgeInvitationTokens:
|
||||
m.ResetInvitationTokens()
|
||||
return nil
|
||||
case group.EdgeNotifiers:
|
||||
m.ResetNotifiers()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Group edge %s", name)
|
||||
}
|
||||
|
@ -9790,6 +9873,8 @@ type NotifierMutation struct {
|
|||
clearedFields map[string]struct{}
|
||||
user *uuid.UUID
|
||||
cleareduser bool
|
||||
group *uuid.UUID
|
||||
clearedgroup bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*Notifier, error)
|
||||
predicates []predicate.Notifier
|
||||
|
@ -10007,6 +10092,42 @@ func (m *NotifierMutation) ResetUserID() {
|
|||
m.user = nil
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (m *NotifierMutation) SetGroupID(u uuid.UUID) {
|
||||
m.group = &u
|
||||
}
|
||||
|
||||
// GroupID returns the value of the "group_id" field in the mutation.
|
||||
func (m *NotifierMutation) GroupID() (r uuid.UUID, exists bool) {
|
||||
v := m.group
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldGroupID returns the old "group_id" field's value of the Notifier entity.
|
||||
// If the Notifier 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 *NotifierMutation) OldGroupID(ctx context.Context) (v uuid.UUID, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldGroupID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
|
||||
}
|
||||
return oldValue.GroupID, nil
|
||||
}
|
||||
|
||||
// ResetGroupID resets all changes to the "group_id" field.
|
||||
func (m *NotifierMutation) ResetGroupID() {
|
||||
m.group = nil
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (m *NotifierMutation) SetName(s string) {
|
||||
m.name = &s
|
||||
|
@ -10141,6 +10262,32 @@ func (m *NotifierMutation) ResetUser() {
|
|||
m.cleareduser = false
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (m *NotifierMutation) ClearGroup() {
|
||||
m.clearedgroup = true
|
||||
}
|
||||
|
||||
// GroupCleared reports if the "group" edge to the Group entity was cleared.
|
||||
func (m *NotifierMutation) GroupCleared() bool {
|
||||
return m.clearedgroup
|
||||
}
|
||||
|
||||
// GroupIDs returns the "group" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// GroupID instead. It exists only for internal usage by the builders.
|
||||
func (m *NotifierMutation) GroupIDs() (ids []uuid.UUID) {
|
||||
if id := m.group; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetGroup resets all changes to the "group" edge.
|
||||
func (m *NotifierMutation) ResetGroup() {
|
||||
m.group = nil
|
||||
m.clearedgroup = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NotifierMutation builder.
|
||||
func (m *NotifierMutation) Where(ps ...predicate.Notifier) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
|
@ -10175,7 +10322,7 @@ func (m *NotifierMutation) Type() string {
|
|||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *NotifierMutation) Fields() []string {
|
||||
fields := make([]string, 0, 6)
|
||||
fields := make([]string, 0, 7)
|
||||
if m.created_at != nil {
|
||||
fields = append(fields, notifier.FieldCreatedAt)
|
||||
}
|
||||
|
@ -10185,6 +10332,9 @@ func (m *NotifierMutation) Fields() []string {
|
|||
if m.user != nil {
|
||||
fields = append(fields, notifier.FieldUserID)
|
||||
}
|
||||
if m.group != nil {
|
||||
fields = append(fields, notifier.FieldGroupID)
|
||||
}
|
||||
if m.name != nil {
|
||||
fields = append(fields, notifier.FieldName)
|
||||
}
|
||||
|
@ -10208,6 +10358,8 @@ func (m *NotifierMutation) Field(name string) (ent.Value, bool) {
|
|||
return m.UpdatedAt()
|
||||
case notifier.FieldUserID:
|
||||
return m.UserID()
|
||||
case notifier.FieldGroupID:
|
||||
return m.GroupID()
|
||||
case notifier.FieldName:
|
||||
return m.Name()
|
||||
case notifier.FieldURL:
|
||||
|
@ -10229,6 +10381,8 @@ func (m *NotifierMutation) OldField(ctx context.Context, name string) (ent.Value
|
|||
return m.OldUpdatedAt(ctx)
|
||||
case notifier.FieldUserID:
|
||||
return m.OldUserID(ctx)
|
||||
case notifier.FieldGroupID:
|
||||
return m.OldGroupID(ctx)
|
||||
case notifier.FieldName:
|
||||
return m.OldName(ctx)
|
||||
case notifier.FieldURL:
|
||||
|
@ -10265,6 +10419,13 @@ func (m *NotifierMutation) SetField(name string, value ent.Value) error {
|
|||
}
|
||||
m.SetUserID(v)
|
||||
return nil
|
||||
case notifier.FieldGroupID:
|
||||
v, ok := value.(uuid.UUID)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetGroupID(v)
|
||||
return nil
|
||||
case notifier.FieldName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
|
@ -10344,6 +10505,9 @@ func (m *NotifierMutation) ResetField(name string) error {
|
|||
case notifier.FieldUserID:
|
||||
m.ResetUserID()
|
||||
return nil
|
||||
case notifier.FieldGroupID:
|
||||
m.ResetGroupID()
|
||||
return nil
|
||||
case notifier.FieldName:
|
||||
m.ResetName()
|
||||
return nil
|
||||
|
@ -10359,10 +10523,13 @@ func (m *NotifierMutation) ResetField(name string) error {
|
|||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *NotifierMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
edges := make([]string, 0, 2)
|
||||
if m.user != nil {
|
||||
edges = append(edges, notifier.EdgeUser)
|
||||
}
|
||||
if m.group != nil {
|
||||
edges = append(edges, notifier.EdgeGroup)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
|
@ -10374,13 +10541,17 @@ func (m *NotifierMutation) AddedIDs(name string) []ent.Value {
|
|||
if id := m.user; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case notifier.EdgeGroup:
|
||||
if id := m.group; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *NotifierMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
edges := make([]string, 0, 2)
|
||||
return edges
|
||||
}
|
||||
|
||||
|
@ -10392,10 +10563,13 @@ func (m *NotifierMutation) RemovedIDs(name string) []ent.Value {
|
|||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *NotifierMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
edges := make([]string, 0, 2)
|
||||
if m.cleareduser {
|
||||
edges = append(edges, notifier.EdgeUser)
|
||||
}
|
||||
if m.clearedgroup {
|
||||
edges = append(edges, notifier.EdgeGroup)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
|
@ -10405,6 +10579,8 @@ func (m *NotifierMutation) EdgeCleared(name string) bool {
|
|||
switch name {
|
||||
case notifier.EdgeUser:
|
||||
return m.cleareduser
|
||||
case notifier.EdgeGroup:
|
||||
return m.clearedgroup
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -10416,6 +10592,9 @@ func (m *NotifierMutation) ClearEdge(name string) error {
|
|||
case notifier.EdgeUser:
|
||||
m.ClearUser()
|
||||
return nil
|
||||
case notifier.EdgeGroup:
|
||||
m.ClearGroup()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Notifier unique edge %s", name)
|
||||
}
|
||||
|
@ -10427,6 +10606,9 @@ func (m *NotifierMutation) ResetEdge(name string) error {
|
|||
case notifier.EdgeUser:
|
||||
m.ResetUser()
|
||||
return nil
|
||||
case notifier.EdgeGroup:
|
||||
m.ResetGroup()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Notifier edge %s", name)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/notifier"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||
)
|
||||
|
@ -24,6 +25,8 @@ type Notifier struct {
|
|||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID uuid.UUID `json:"user_id,omitempty"`
|
||||
// GroupID holds the value of the "group_id" field.
|
||||
GroupID uuid.UUID `json:"group_id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// URL holds the value of the "url" field.
|
||||
|
@ -39,9 +42,11 @@ type Notifier struct {
|
|||
type NotifierEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// Group holds the value of the group edge.
|
||||
Group *Group `json:"group,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
|
@ -57,6 +62,19 @@ func (e NotifierEdges) UserOrErr() (*User, error) {
|
|||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// GroupOrErr returns the Group value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e NotifierEdges) GroupOrErr() (*Group, error) {
|
||||
if e.loadedTypes[1] {
|
||||
if e.Group == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: group.Label}
|
||||
}
|
||||
return e.Group, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "group"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Notifier) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
|
@ -68,7 +86,7 @@ func (*Notifier) scanValues(columns []string) ([]any, error) {
|
|||
values[i] = new(sql.NullString)
|
||||
case notifier.FieldCreatedAt, notifier.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case notifier.FieldID, notifier.FieldUserID:
|
||||
case notifier.FieldID, notifier.FieldUserID, notifier.FieldGroupID:
|
||||
values[i] = new(uuid.UUID)
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected column %q for type Notifier", columns[i])
|
||||
|
@ -109,6 +127,12 @@ func (n *Notifier) assignValues(columns []string, values []any) error {
|
|||
} else if value != nil {
|
||||
n.UserID = *value
|
||||
}
|
||||
case notifier.FieldGroupID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field group_id", values[i])
|
||||
} else if value != nil {
|
||||
n.GroupID = *value
|
||||
}
|
||||
case notifier.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
|
@ -137,6 +161,11 @@ func (n *Notifier) QueryUser() *UserQuery {
|
|||
return NewNotifierClient(n.config).QueryUser(n)
|
||||
}
|
||||
|
||||
// QueryGroup queries the "group" edge of the Notifier entity.
|
||||
func (n *Notifier) QueryGroup() *GroupQuery {
|
||||
return NewNotifierClient(n.config).QueryGroup(n)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Notifier.
|
||||
// Note that you need to call Notifier.Unwrap() before calling this method if this Notifier
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
|
@ -169,6 +198,9 @@ func (n *Notifier) String() string {
|
|||
builder.WriteString("user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", n.UserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("group_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", n.GroupID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(n.Name)
|
||||
builder.WriteString(", ")
|
||||
|
|
|
@ -19,6 +19,8 @@ const (
|
|||
FieldUpdatedAt = "updated_at"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldGroupID holds the string denoting the group_id field in the database.
|
||||
FieldGroupID = "group_id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldURL holds the string denoting the url field in the database.
|
||||
|
@ -27,6 +29,8 @@ const (
|
|||
FieldIsActive = "is_active"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// EdgeGroup holds the string denoting the group edge name in mutations.
|
||||
EdgeGroup = "group"
|
||||
// Table holds the table name of the notifier in the database.
|
||||
Table = "notifiers"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
|
@ -36,6 +40,13 @@ const (
|
|||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "user_id"
|
||||
// GroupTable is the table that holds the group relation/edge.
|
||||
GroupTable = "notifiers"
|
||||
// GroupInverseTable is the table name for the Group entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "group" package.
|
||||
GroupInverseTable = "groups"
|
||||
// GroupColumn is the table column denoting the group relation/edge.
|
||||
GroupColumn = "group_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for notifier fields.
|
||||
|
@ -44,6 +55,7 @@ var Columns = []string{
|
|||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldUserID,
|
||||
FieldGroupID,
|
||||
FieldName,
|
||||
FieldURL,
|
||||
FieldIsActive,
|
||||
|
|
|
@ -71,6 +71,11 @@ func UserID(v uuid.UUID) predicate.Notifier {
|
|||
return predicate.Notifier(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
|
||||
func GroupID(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldGroupID, v))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldName, v))
|
||||
|
@ -186,6 +191,26 @@ func UserIDNotIn(vs ...uuid.UUID) predicate.Notifier {
|
|||
return predicate.Notifier(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// GroupIDEQ applies the EQ predicate on the "group_id" field.
|
||||
func GroupIDEQ(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldGroupID, v))
|
||||
}
|
||||
|
||||
// GroupIDNEQ applies the NEQ predicate on the "group_id" field.
|
||||
func GroupIDNEQ(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldNEQ(FieldGroupID, v))
|
||||
}
|
||||
|
||||
// GroupIDIn applies the In predicate on the "group_id" field.
|
||||
func GroupIDIn(vs ...uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldIn(FieldGroupID, vs...))
|
||||
}
|
||||
|
||||
// GroupIDNotIn applies the NotIn predicate on the "group_id" field.
|
||||
func GroupIDNotIn(vs ...uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldNotIn(FieldGroupID, vs...))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldName, v))
|
||||
|
@ -353,6 +378,33 @@ func HasUserWith(preds ...predicate.User) predicate.Notifier {
|
|||
})
|
||||
}
|
||||
|
||||
// HasGroup applies the HasEdge predicate on the "group" edge.
|
||||
func HasGroup() predicate.Notifier {
|
||||
return predicate.Notifier(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates).
|
||||
func HasGroupWith(preds ...predicate.Group) predicate.Notifier {
|
||||
return predicate.Notifier(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(GroupInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn),
|
||||
)
|
||||
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.Notifier) predicate.Notifier {
|
||||
return predicate.Notifier(func(s *sql.Selector) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/notifier"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||
)
|
||||
|
@ -56,6 +57,12 @@ func (nc *NotifierCreate) SetUserID(u uuid.UUID) *NotifierCreate {
|
|||
return nc
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (nc *NotifierCreate) SetGroupID(u uuid.UUID) *NotifierCreate {
|
||||
nc.mutation.SetGroupID(u)
|
||||
return nc
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (nc *NotifierCreate) SetName(s string) *NotifierCreate {
|
||||
nc.mutation.SetName(s)
|
||||
|
@ -101,6 +108,11 @@ func (nc *NotifierCreate) SetUser(u *User) *NotifierCreate {
|
|||
return nc.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (nc *NotifierCreate) SetGroup(g *Group) *NotifierCreate {
|
||||
return nc.SetGroupID(g.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the NotifierMutation object of the builder.
|
||||
func (nc *NotifierCreate) Mutation() *NotifierMutation {
|
||||
return nc.mutation
|
||||
|
@ -165,6 +177,9 @@ func (nc *NotifierCreate) check() error {
|
|||
if _, ok := nc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "Notifier.user_id"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.GroupID(); !ok {
|
||||
return &ValidationError{Name: "group_id", err: errors.New(`ent: missing required field "Notifier.group_id"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Notifier.name"`)}
|
||||
}
|
||||
|
@ -187,6 +202,9 @@ func (nc *NotifierCreate) check() error {
|
|||
if _, ok := nc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "Notifier.user"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.GroupID(); !ok {
|
||||
return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Notifier.group"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -262,6 +280,26 @@ func (nc *NotifierCreate) createSpec() (*Notifier, *sqlgraph.CreateSpec) {
|
|||
_node.UserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := nc.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.GroupTable,
|
||||
Columns: []string{notifier.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: group.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.GroupID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/notifier"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||
|
@ -24,6 +25,7 @@ type NotifierQuery struct {
|
|||
inters []Interceptor
|
||||
predicates []predicate.Notifier
|
||||
withUser *UserQuery
|
||||
withGroup *GroupQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
@ -82,6 +84,28 @@ func (nq *NotifierQuery) QueryUser() *UserQuery {
|
|||
return query
|
||||
}
|
||||
|
||||
// QueryGroup chains the current query on the "group" edge.
|
||||
func (nq *NotifierQuery) QueryGroup() *GroupQuery {
|
||||
query := (&GroupClient{config: nq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := nq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := nq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(notifier.Table, notifier.FieldID, selector),
|
||||
sqlgraph.To(group.Table, group.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, notifier.GroupTable, notifier.GroupColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(nq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Notifier entity from the query.
|
||||
// Returns a *NotFoundError when no Notifier was found.
|
||||
func (nq *NotifierQuery) First(ctx context.Context) (*Notifier, error) {
|
||||
|
@ -275,6 +299,7 @@ func (nq *NotifierQuery) Clone() *NotifierQuery {
|
|||
inters: append([]Interceptor{}, nq.inters...),
|
||||
predicates: append([]predicate.Notifier{}, nq.predicates...),
|
||||
withUser: nq.withUser.Clone(),
|
||||
withGroup: nq.withGroup.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: nq.sql.Clone(),
|
||||
path: nq.path,
|
||||
|
@ -292,6 +317,17 @@ func (nq *NotifierQuery) WithUser(opts ...func(*UserQuery)) *NotifierQuery {
|
|||
return nq
|
||||
}
|
||||
|
||||
// WithGroup tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (nq *NotifierQuery) WithGroup(opts ...func(*GroupQuery)) *NotifierQuery {
|
||||
query := (&GroupClient{config: nq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
nq.withGroup = query
|
||||
return nq
|
||||
}
|
||||
|
||||
// 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.
|
||||
//
|
||||
|
@ -370,8 +406,9 @@ func (nq *NotifierQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Not
|
|||
var (
|
||||
nodes = []*Notifier{}
|
||||
_spec = nq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
loadedTypes = [2]bool{
|
||||
nq.withUser != nil,
|
||||
nq.withGroup != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
|
@ -398,6 +435,12 @@ func (nq *NotifierQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Not
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := nq.withGroup; query != nil {
|
||||
if err := nq.loadGroup(ctx, query, nodes, nil,
|
||||
func(n *Notifier, e *Group) { n.Edges.Group = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
@ -430,6 +473,35 @@ func (nq *NotifierQuery) loadUser(ctx context.Context, query *UserQuery, nodes [
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func (nq *NotifierQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*Notifier, init func(*Notifier), assign func(*Notifier, *Group)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*Notifier)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].GroupID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(group.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 "group_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nq *NotifierQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := nq.querySpec()
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/notifier"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||
|
@ -42,6 +43,12 @@ func (nu *NotifierUpdate) SetUserID(u uuid.UUID) *NotifierUpdate {
|
|||
return nu
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (nu *NotifierUpdate) SetGroupID(u uuid.UUID) *NotifierUpdate {
|
||||
nu.mutation.SetGroupID(u)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (nu *NotifierUpdate) SetName(s string) *NotifierUpdate {
|
||||
nu.mutation.SetName(s)
|
||||
|
@ -73,6 +80,11 @@ func (nu *NotifierUpdate) SetUser(u *User) *NotifierUpdate {
|
|||
return nu.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (nu *NotifierUpdate) SetGroup(g *Group) *NotifierUpdate {
|
||||
return nu.SetGroupID(g.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the NotifierMutation object of the builder.
|
||||
func (nu *NotifierUpdate) Mutation() *NotifierMutation {
|
||||
return nu.mutation
|
||||
|
@ -84,6 +96,12 @@ func (nu *NotifierUpdate) ClearUser() *NotifierUpdate {
|
|||
return nu
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (nu *NotifierUpdate) ClearGroup() *NotifierUpdate {
|
||||
nu.mutation.ClearGroup()
|
||||
return nu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (nu *NotifierUpdate) Save(ctx context.Context) (int, error) {
|
||||
nu.defaults()
|
||||
|
@ -135,6 +153,9 @@ func (nu *NotifierUpdate) check() error {
|
|||
if _, ok := nu.mutation.UserID(); nu.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.user"`)
|
||||
}
|
||||
if _, ok := nu.mutation.GroupID(); nu.mutation.GroupCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.group"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -197,6 +218,41 @@ func (nu *NotifierUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nu.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.GroupTable,
|
||||
Columns: []string{notifier.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: group.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nu.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.GroupTable,
|
||||
Columns: []string{notifier.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: group.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, nu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{notifier.Label}
|
||||
|
@ -229,6 +285,12 @@ func (nuo *NotifierUpdateOne) SetUserID(u uuid.UUID) *NotifierUpdateOne {
|
|||
return nuo
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (nuo *NotifierUpdateOne) SetGroupID(u uuid.UUID) *NotifierUpdateOne {
|
||||
nuo.mutation.SetGroupID(u)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (nuo *NotifierUpdateOne) SetName(s string) *NotifierUpdateOne {
|
||||
nuo.mutation.SetName(s)
|
||||
|
@ -260,6 +322,11 @@ func (nuo *NotifierUpdateOne) SetUser(u *User) *NotifierUpdateOne {
|
|||
return nuo.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (nuo *NotifierUpdateOne) SetGroup(g *Group) *NotifierUpdateOne {
|
||||
return nuo.SetGroupID(g.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the NotifierMutation object of the builder.
|
||||
func (nuo *NotifierUpdateOne) Mutation() *NotifierMutation {
|
||||
return nuo.mutation
|
||||
|
@ -271,6 +338,12 @@ func (nuo *NotifierUpdateOne) ClearUser() *NotifierUpdateOne {
|
|||
return nuo
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (nuo *NotifierUpdateOne) ClearGroup() *NotifierUpdateOne {
|
||||
nuo.mutation.ClearGroup()
|
||||
return nuo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NotifierUpdate builder.
|
||||
func (nuo *NotifierUpdateOne) Where(ps ...predicate.Notifier) *NotifierUpdateOne {
|
||||
nuo.mutation.Where(ps...)
|
||||
|
@ -335,6 +408,9 @@ func (nuo *NotifierUpdateOne) check() error {
|
|||
if _, ok := nuo.mutation.UserID(); nuo.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.user"`)
|
||||
}
|
||||
if _, ok := nuo.mutation.GroupID(); nuo.mutation.GroupCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.group"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -414,6 +490,41 @@ func (nuo *NotifierUpdateOne) sqlSave(ctx context.Context) (_node *Notifier, err
|
|||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nuo.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.GroupTable,
|
||||
Columns: []string{notifier.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: group.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nuo.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.GroupTable,
|
||||
Columns: []string{notifier.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: group.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Notifier{config: nuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
|
|
@ -493,7 +493,7 @@ func init() {
|
|||
// notifier.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
notifier.UpdateDefaultUpdatedAt = notifierDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// notifierDescName is the schema descriptor for name field.
|
||||
notifierDescName := notifierFields[1].Descriptor()
|
||||
notifierDescName := notifierFields[2].Descriptor()
|
||||
// notifier.NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
notifier.NameValidator = func() func(string) error {
|
||||
validators := notifierDescName.Validators
|
||||
|
@ -511,7 +511,7 @@ func init() {
|
|||
}
|
||||
}()
|
||||
// notifierDescURL is the schema descriptor for url field.
|
||||
notifierDescURL := notifierFields[2].Descriptor()
|
||||
notifierDescURL := notifierFields[3].Descriptor()
|
||||
// notifier.URLValidator is a validator for the "url" field. It is called by the builders before save.
|
||||
notifier.URLValidator = func() func(string) error {
|
||||
validators := notifierDescURL.Validators
|
||||
|
@ -529,7 +529,7 @@ func init() {
|
|||
}
|
||||
}()
|
||||
// notifierDescIsActive is the schema descriptor for is_active field.
|
||||
notifierDescIsActive := notifierFields[3].Descriptor()
|
||||
notifierDescIsActive := notifierFields[4].Descriptor()
|
||||
// notifier.DefaultIsActive holds the default value on creation for the is_active field.
|
||||
notifier.DefaultIsActive = notifierDescIsActive.Default.(bool)
|
||||
// notifierDescID is the schema descriptor for id field.
|
||||
|
|
|
@ -58,5 +58,9 @@ func (Group) Edges() []ent.Edge {
|
|||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("notifiers", Notifier.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ func (Notifier) Mixin() []ent.Mixin {
|
|||
func (Notifier) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("user_id", uuid.UUID{}),
|
||||
field.UUID("group_id", uuid.UUID{}),
|
||||
field.String("name").
|
||||
MaxLen(255).
|
||||
NotEmpty(),
|
||||
|
@ -44,6 +45,11 @@ func (Notifier) Edges() []ent.Edge {
|
|||
Ref("notifiers").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.From("group", Group.Type).
|
||||
Field("group_id").
|
||||
Ref("notifiers").
|
||||
Required().
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,5 +57,8 @@ func (Notifier) Indexes() []ent.Index {
|
|||
return []ent.Index{
|
||||
index.Fields("user_id"),
|
||||
index.Fields("user_id", "is_active"),
|
||||
|
||||
index.Fields("group_id"),
|
||||
index.Fields("group_id", "is_active"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue