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

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