mirror of
https://github.com/hay-kot/homebox.git
synced 2025-06-01 01:52:30 +00:00
feat: Notifiers CRUD (#337)
* introduce scaffold for new models * wip: shoutrrr wrapper (may remove) * update schema files * gen: ent code * gen: migrations * go mod tidy * add group_id to notifier * db migration * new mapper helpers * notifier repo * introduce experimental adapter pattern for hdlrs * refactor adapters to fit more common use cases * new routes for notifiers * update errors to fix validation panic * go tidy * reverse checkbox label display * wip: notifiers UI * use badges instead of text * improve documentation * add scaffold schema reference * remove notifier service * refactor schema folder * support group edges via scaffold * delete test file * include link to API docs * audit and update documentation + improve format * refactor schema edges * refactor * add custom validator * set validate + order fields by name * fix failing tests
This commit is contained in:
parent
2665b666f1
commit
23b5892aef
100 changed files with 11437 additions and 2075 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
||||
"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"
|
||||
)
|
||||
|
||||
|
@ -83,20 +84,6 @@ func (uc *UserCreate) SetNillableIsSuperuser(b *bool) *UserCreate {
|
|||
return uc
|
||||
}
|
||||
|
||||
// SetRole sets the "role" field.
|
||||
func (uc *UserCreate) SetRole(u user.Role) *UserCreate {
|
||||
uc.mutation.SetRole(u)
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetNillableRole sets the "role" field if the given value is not nil.
|
||||
func (uc *UserCreate) SetNillableRole(u *user.Role) *UserCreate {
|
||||
if u != nil {
|
||||
uc.SetRole(*u)
|
||||
}
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetSuperuser sets the "superuser" field.
|
||||
func (uc *UserCreate) SetSuperuser(b bool) *UserCreate {
|
||||
uc.mutation.SetSuperuser(b)
|
||||
|
@ -111,6 +98,20 @@ func (uc *UserCreate) SetNillableSuperuser(b *bool) *UserCreate {
|
|||
return uc
|
||||
}
|
||||
|
||||
// SetRole sets the "role" field.
|
||||
func (uc *UserCreate) SetRole(u user.Role) *UserCreate {
|
||||
uc.mutation.SetRole(u)
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetNillableRole sets the "role" field if the given value is not nil.
|
||||
func (uc *UserCreate) SetNillableRole(u *user.Role) *UserCreate {
|
||||
if u != nil {
|
||||
uc.SetRole(*u)
|
||||
}
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetActivatedOn sets the "activated_on" field.
|
||||
func (uc *UserCreate) SetActivatedOn(t time.Time) *UserCreate {
|
||||
uc.mutation.SetActivatedOn(t)
|
||||
|
@ -165,6 +166,21 @@ func (uc *UserCreate) AddAuthTokens(a ...*AuthTokens) *UserCreate {
|
|||
return uc.AddAuthTokenIDs(ids...)
|
||||
}
|
||||
|
||||
// AddNotifierIDs adds the "notifiers" edge to the Notifier entity by IDs.
|
||||
func (uc *UserCreate) AddNotifierIDs(ids ...uuid.UUID) *UserCreate {
|
||||
uc.mutation.AddNotifierIDs(ids...)
|
||||
return uc
|
||||
}
|
||||
|
||||
// AddNotifiers adds the "notifiers" edges to the Notifier entity.
|
||||
func (uc *UserCreate) AddNotifiers(n ...*Notifier) *UserCreate {
|
||||
ids := make([]uuid.UUID, len(n))
|
||||
for i := range n {
|
||||
ids[i] = n[i].ID
|
||||
}
|
||||
return uc.AddNotifierIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uc *UserCreate) Mutation() *UserMutation {
|
||||
return uc.mutation
|
||||
|
@ -212,14 +228,14 @@ func (uc *UserCreate) defaults() {
|
|||
v := user.DefaultIsSuperuser
|
||||
uc.mutation.SetIsSuperuser(v)
|
||||
}
|
||||
if _, ok := uc.mutation.Role(); !ok {
|
||||
v := user.DefaultRole
|
||||
uc.mutation.SetRole(v)
|
||||
}
|
||||
if _, ok := uc.mutation.Superuser(); !ok {
|
||||
v := user.DefaultSuperuser
|
||||
uc.mutation.SetSuperuser(v)
|
||||
}
|
||||
if _, ok := uc.mutation.Role(); !ok {
|
||||
v := user.DefaultRole
|
||||
uc.mutation.SetRole(v)
|
||||
}
|
||||
if _, ok := uc.mutation.ID(); !ok {
|
||||
v := user.DefaultID()
|
||||
uc.mutation.SetID(v)
|
||||
|
@ -261,6 +277,9 @@ func (uc *UserCreate) check() error {
|
|||
if _, ok := uc.mutation.IsSuperuser(); !ok {
|
||||
return &ValidationError{Name: "is_superuser", err: errors.New(`ent: missing required field "User.is_superuser"`)}
|
||||
}
|
||||
if _, ok := uc.mutation.Superuser(); !ok {
|
||||
return &ValidationError{Name: "superuser", err: errors.New(`ent: missing required field "User.superuser"`)}
|
||||
}
|
||||
if _, ok := uc.mutation.Role(); !ok {
|
||||
return &ValidationError{Name: "role", err: errors.New(`ent: missing required field "User.role"`)}
|
||||
}
|
||||
|
@ -269,9 +288,6 @@ func (uc *UserCreate) check() error {
|
|||
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := uc.mutation.Superuser(); !ok {
|
||||
return &ValidationError{Name: "superuser", err: errors.New(`ent: missing required field "User.superuser"`)}
|
||||
}
|
||||
if _, ok := uc.mutation.GroupID(); !ok {
|
||||
return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "User.group"`)}
|
||||
}
|
||||
|
@ -334,14 +350,14 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||
_spec.SetField(user.FieldIsSuperuser, field.TypeBool, value)
|
||||
_node.IsSuperuser = value
|
||||
}
|
||||
if value, ok := uc.mutation.Role(); ok {
|
||||
_spec.SetField(user.FieldRole, field.TypeEnum, value)
|
||||
_node.Role = value
|
||||
}
|
||||
if value, ok := uc.mutation.Superuser(); ok {
|
||||
_spec.SetField(user.FieldSuperuser, field.TypeBool, value)
|
||||
_node.Superuser = value
|
||||
}
|
||||
if value, ok := uc.mutation.Role(); ok {
|
||||
_spec.SetField(user.FieldRole, field.TypeEnum, value)
|
||||
_node.Role = value
|
||||
}
|
||||
if value, ok := uc.mutation.ActivatedOn(); ok {
|
||||
_spec.SetField(user.FieldActivatedOn, field.TypeTime, value)
|
||||
_node.ActivatedOn = value
|
||||
|
@ -385,6 +401,25 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := uc.mutation.NotifiersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.NotifiersTable,
|
||||
Columns: []string{user.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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue