Implemented Epic 1 core kernel and infrastructure stories: Story 1.1: Enhanced DI Container - Added providers for database, health, metrics, and error bus - Extended CoreModule to include all core services Story 1.2: Database Layer with Ent ORM - Created Ent schema for User, Role, Permission, AuditLog entities - Implemented many-to-many relationships (User-Role, Role-Permission) - Created database client wrapper with connection pooling - Added database provider to DI container with migration support Story 1.3: Health Monitoring and Metrics System - Implemented health check registry and interface - Added database health checker - Created Prometheus metrics system with HTTP instrumentation - Added health and metrics providers to DI container Story 1.4: Error Handling and Error Bus - Implemented channel-based error bus - Created ErrorPublisher interface - Added error bus provider with lifecycle management Story 1.5: HTTP Server Foundation - Created HTTP server with Gin framework - Implemented comprehensive middleware stack: - Request ID generation - Structured logging - Panic recovery with error bus integration - Prometheus metrics collection - CORS support - Registered core routes: /healthz, /ready, /metrics - Integrated with FX lifecycle for graceful shutdown All components are integrated via DI container and ready for use.
368 lines
11 KiB
Go
368 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"git.dcentral.systems/toolz/goplt/internal/ent/auditlog"
|
|
"git.dcentral.systems/toolz/goplt/internal/ent/predicate"
|
|
)
|
|
|
|
// AuditLogUpdate is the builder for updating AuditLog entities.
|
|
type AuditLogUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AuditLogMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AuditLogUpdate builder.
|
|
func (_u *AuditLogUpdate) Where(ps ...predicate.AuditLog) *AuditLogUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetActorID sets the "actor_id" field.
|
|
func (_u *AuditLogUpdate) SetActorID(v string) *AuditLogUpdate {
|
|
_u.mutation.SetActorID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActorID sets the "actor_id" field if the given value is not nil.
|
|
func (_u *AuditLogUpdate) SetNillableActorID(v *string) *AuditLogUpdate {
|
|
if v != nil {
|
|
_u.SetActorID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAction sets the "action" field.
|
|
func (_u *AuditLogUpdate) SetAction(v string) *AuditLogUpdate {
|
|
_u.mutation.SetAction(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAction sets the "action" field if the given value is not nil.
|
|
func (_u *AuditLogUpdate) SetNillableAction(v *string) *AuditLogUpdate {
|
|
if v != nil {
|
|
_u.SetAction(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTargetID sets the "target_id" field.
|
|
func (_u *AuditLogUpdate) SetTargetID(v string) *AuditLogUpdate {
|
|
_u.mutation.SetTargetID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTargetID sets the "target_id" field if the given value is not nil.
|
|
func (_u *AuditLogUpdate) SetNillableTargetID(v *string) *AuditLogUpdate {
|
|
if v != nil {
|
|
_u.SetTargetID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTargetID clears the value of the "target_id" field.
|
|
func (_u *AuditLogUpdate) ClearTargetID() *AuditLogUpdate {
|
|
_u.mutation.ClearTargetID()
|
|
return _u
|
|
}
|
|
|
|
// SetMetadata sets the "metadata" field.
|
|
func (_u *AuditLogUpdate) SetMetadata(v map[string]interface{}) *AuditLogUpdate {
|
|
_u.mutation.SetMetadata(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearMetadata clears the value of the "metadata" field.
|
|
func (_u *AuditLogUpdate) ClearMetadata() *AuditLogUpdate {
|
|
_u.mutation.ClearMetadata()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the AuditLogMutation object of the builder.
|
|
func (_u *AuditLogUpdate) Mutation() *AuditLogMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *AuditLogUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AuditLogUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *AuditLogUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AuditLogUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AuditLogUpdate) check() error {
|
|
if v, ok := _u.mutation.ActorID(); ok {
|
|
if err := auditlog.ActorIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "actor_id", err: fmt.Errorf(`ent: validator failed for field "AuditLog.actor_id": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Action(); ok {
|
|
if err := auditlog.ActionValidator(v); err != nil {
|
|
return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "AuditLog.action": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *AuditLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(auditlog.Table, auditlog.Columns, sqlgraph.NewFieldSpec(auditlog.FieldID, field.TypeString))
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.ActorID(); ok {
|
|
_spec.SetField(auditlog.FieldActorID, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Action(); ok {
|
|
_spec.SetField(auditlog.FieldAction, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.TargetID(); ok {
|
|
_spec.SetField(auditlog.FieldTargetID, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TargetIDCleared() {
|
|
_spec.ClearField(auditlog.FieldTargetID, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Metadata(); ok {
|
|
_spec.SetField(auditlog.FieldMetadata, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.MetadataCleared() {
|
|
_spec.ClearField(auditlog.FieldMetadata, field.TypeJSON)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{auditlog.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// AuditLogUpdateOne is the builder for updating a single AuditLog entity.
|
|
type AuditLogUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AuditLogMutation
|
|
}
|
|
|
|
// SetActorID sets the "actor_id" field.
|
|
func (_u *AuditLogUpdateOne) SetActorID(v string) *AuditLogUpdateOne {
|
|
_u.mutation.SetActorID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActorID sets the "actor_id" field if the given value is not nil.
|
|
func (_u *AuditLogUpdateOne) SetNillableActorID(v *string) *AuditLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetActorID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAction sets the "action" field.
|
|
func (_u *AuditLogUpdateOne) SetAction(v string) *AuditLogUpdateOne {
|
|
_u.mutation.SetAction(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAction sets the "action" field if the given value is not nil.
|
|
func (_u *AuditLogUpdateOne) SetNillableAction(v *string) *AuditLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetAction(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTargetID sets the "target_id" field.
|
|
func (_u *AuditLogUpdateOne) SetTargetID(v string) *AuditLogUpdateOne {
|
|
_u.mutation.SetTargetID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTargetID sets the "target_id" field if the given value is not nil.
|
|
func (_u *AuditLogUpdateOne) SetNillableTargetID(v *string) *AuditLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetTargetID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTargetID clears the value of the "target_id" field.
|
|
func (_u *AuditLogUpdateOne) ClearTargetID() *AuditLogUpdateOne {
|
|
_u.mutation.ClearTargetID()
|
|
return _u
|
|
}
|
|
|
|
// SetMetadata sets the "metadata" field.
|
|
func (_u *AuditLogUpdateOne) SetMetadata(v map[string]interface{}) *AuditLogUpdateOne {
|
|
_u.mutation.SetMetadata(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearMetadata clears the value of the "metadata" field.
|
|
func (_u *AuditLogUpdateOne) ClearMetadata() *AuditLogUpdateOne {
|
|
_u.mutation.ClearMetadata()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the AuditLogMutation object of the builder.
|
|
func (_u *AuditLogUpdateOne) Mutation() *AuditLogMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AuditLogUpdate builder.
|
|
func (_u *AuditLogUpdateOne) Where(ps ...predicate.AuditLog) *AuditLogUpdateOne {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (_u *AuditLogUpdateOne) Select(field string, fields ...string) *AuditLogUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated AuditLog entity.
|
|
func (_u *AuditLogUpdateOne) Save(ctx context.Context) (*AuditLog, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AuditLogUpdateOne) SaveX(ctx context.Context) *AuditLog {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *AuditLogUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AuditLogUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AuditLogUpdateOne) check() error {
|
|
if v, ok := _u.mutation.ActorID(); ok {
|
|
if err := auditlog.ActorIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "actor_id", err: fmt.Errorf(`ent: validator failed for field "AuditLog.actor_id": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Action(); ok {
|
|
if err := auditlog.ActionValidator(v); err != nil {
|
|
return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "AuditLog.action": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *AuditLogUpdateOne) sqlSave(ctx context.Context) (_node *AuditLog, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(auditlog.Table, auditlog.Columns, sqlgraph.NewFieldSpec(auditlog.FieldID, field.TypeString))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuditLog.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := _u.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, auditlog.FieldID)
|
|
for _, f := range fields {
|
|
if !auditlog.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != auditlog.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.ActorID(); ok {
|
|
_spec.SetField(auditlog.FieldActorID, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Action(); ok {
|
|
_spec.SetField(auditlog.FieldAction, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.TargetID(); ok {
|
|
_spec.SetField(auditlog.FieldTargetID, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TargetIDCleared() {
|
|
_spec.ClearField(auditlog.FieldTargetID, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Metadata(); ok {
|
|
_spec.SetField(auditlog.FieldMetadata, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.MetadataCleared() {
|
|
_spec.ClearField(auditlog.FieldMetadata, field.TypeJSON)
|
|
}
|
|
_node = &AuditLog{config: _u.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{auditlog.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|