add group_id to notifier

This commit is contained in:
Hayden 2023-03-04 22:20:02 -09:00
parent 43b34e2899
commit 37857682e6
No known key found for this signature in database
GPG key ID: 17CF79474E257545
18 changed files with 919 additions and 18 deletions

View file

@ -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