mirror of
https://github.com/holos-run/holos.git
synced 2026-03-20 01:04:59 +00:00
This patch refactors the API to be resource-oriented around one service per resource type. PlatformService, OrganizationService, UserService, etc... Validation is improved to use CEL rules provided by [protovalidate][1]. Place holders for FieldMask and other best practices are added, but are unimplemented as per [API Best Practices][2]. The intent is to set us up well for copying and pasting solid existing examples as we add features. With this patch the server and web app client are both updated to use the refactored API, however the following are not working: 1. Update the model. 2. Field Masks. [1]: https://buf.build/bufbuild/protovalidate [2]: https://protobuf.dev/programming-guides/api/
729 lines
21 KiB
Go
729 lines
21 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/gofrs/uuid"
|
|
"github.com/holos-run/holos/internal/ent/organization"
|
|
"github.com/holos-run/holos/internal/ent/platform"
|
|
"github.com/holos-run/holos/internal/ent/predicate"
|
|
"github.com/holos-run/holos/internal/ent/user"
|
|
storage "github.com/holos-run/holos/service/gen/holos/storage/v1alpha1"
|
|
)
|
|
|
|
// PlatformUpdate is the builder for updating Platform entities.
|
|
type PlatformUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *PlatformMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the PlatformUpdate builder.
|
|
func (pu *PlatformUpdate) Where(ps ...predicate.Platform) *PlatformUpdate {
|
|
pu.mutation.Where(ps...)
|
|
return pu
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (pu *PlatformUpdate) SetUpdatedAt(t time.Time) *PlatformUpdate {
|
|
pu.mutation.SetUpdatedAt(t)
|
|
return pu
|
|
}
|
|
|
|
// SetUpdatedByID sets the "updated_by_id" field.
|
|
func (pu *PlatformUpdate) SetUpdatedByID(u uuid.UUID) *PlatformUpdate {
|
|
pu.mutation.SetUpdatedByID(u)
|
|
return pu
|
|
}
|
|
|
|
// SetNillableUpdatedByID sets the "updated_by_id" field if the given value is not nil.
|
|
func (pu *PlatformUpdate) SetNillableUpdatedByID(u *uuid.UUID) *PlatformUpdate {
|
|
if u != nil {
|
|
pu.SetUpdatedByID(*u)
|
|
}
|
|
return pu
|
|
}
|
|
|
|
// SetOrgID sets the "org_id" field.
|
|
func (pu *PlatformUpdate) SetOrgID(u uuid.UUID) *PlatformUpdate {
|
|
pu.mutation.SetOrgID(u)
|
|
return pu
|
|
}
|
|
|
|
// SetNillableOrgID sets the "org_id" field if the given value is not nil.
|
|
func (pu *PlatformUpdate) SetNillableOrgID(u *uuid.UUID) *PlatformUpdate {
|
|
if u != nil {
|
|
pu.SetOrgID(*u)
|
|
}
|
|
return pu
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (pu *PlatformUpdate) SetName(s string) *PlatformUpdate {
|
|
pu.mutation.SetName(s)
|
|
return pu
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (pu *PlatformUpdate) SetNillableName(s *string) *PlatformUpdate {
|
|
if s != nil {
|
|
pu.SetName(*s)
|
|
}
|
|
return pu
|
|
}
|
|
|
|
// SetDisplayName sets the "display_name" field.
|
|
func (pu *PlatformUpdate) SetDisplayName(s string) *PlatformUpdate {
|
|
pu.mutation.SetDisplayName(s)
|
|
return pu
|
|
}
|
|
|
|
// SetNillableDisplayName sets the "display_name" field if the given value is not nil.
|
|
func (pu *PlatformUpdate) SetNillableDisplayName(s *string) *PlatformUpdate {
|
|
if s != nil {
|
|
pu.SetDisplayName(*s)
|
|
}
|
|
return pu
|
|
}
|
|
|
|
// SetForm sets the "form" field.
|
|
func (pu *PlatformUpdate) SetForm(s *storage.Form) *PlatformUpdate {
|
|
pu.mutation.SetForm(s)
|
|
return pu
|
|
}
|
|
|
|
// ClearForm clears the value of the "form" field.
|
|
func (pu *PlatformUpdate) ClearForm() *PlatformUpdate {
|
|
pu.mutation.ClearForm()
|
|
return pu
|
|
}
|
|
|
|
// SetModel sets the "model" field.
|
|
func (pu *PlatformUpdate) SetModel(s *storage.Model) *PlatformUpdate {
|
|
pu.mutation.SetModel(s)
|
|
return pu
|
|
}
|
|
|
|
// ClearModel clears the value of the "model" field.
|
|
func (pu *PlatformUpdate) ClearModel() *PlatformUpdate {
|
|
pu.mutation.ClearModel()
|
|
return pu
|
|
}
|
|
|
|
// SetCue sets the "cue" field.
|
|
func (pu *PlatformUpdate) SetCue(b []byte) *PlatformUpdate {
|
|
pu.mutation.SetCue(b)
|
|
return pu
|
|
}
|
|
|
|
// ClearCue clears the value of the "cue" field.
|
|
func (pu *PlatformUpdate) ClearCue() *PlatformUpdate {
|
|
pu.mutation.ClearCue()
|
|
return pu
|
|
}
|
|
|
|
// SetCueDefinition sets the "cue_definition" field.
|
|
func (pu *PlatformUpdate) SetCueDefinition(s string) *PlatformUpdate {
|
|
pu.mutation.SetCueDefinition(s)
|
|
return pu
|
|
}
|
|
|
|
// SetNillableCueDefinition sets the "cue_definition" field if the given value is not nil.
|
|
func (pu *PlatformUpdate) SetNillableCueDefinition(s *string) *PlatformUpdate {
|
|
if s != nil {
|
|
pu.SetCueDefinition(*s)
|
|
}
|
|
return pu
|
|
}
|
|
|
|
// ClearCueDefinition clears the value of the "cue_definition" field.
|
|
func (pu *PlatformUpdate) ClearCueDefinition() *PlatformUpdate {
|
|
pu.mutation.ClearCueDefinition()
|
|
return pu
|
|
}
|
|
|
|
// SetEditorID sets the "editor" edge to the User entity by ID.
|
|
func (pu *PlatformUpdate) SetEditorID(id uuid.UUID) *PlatformUpdate {
|
|
pu.mutation.SetEditorID(id)
|
|
return pu
|
|
}
|
|
|
|
// SetEditor sets the "editor" edge to the User entity.
|
|
func (pu *PlatformUpdate) SetEditor(u *User) *PlatformUpdate {
|
|
return pu.SetEditorID(u.ID)
|
|
}
|
|
|
|
// SetOrganizationID sets the "organization" edge to the Organization entity by ID.
|
|
func (pu *PlatformUpdate) SetOrganizationID(id uuid.UUID) *PlatformUpdate {
|
|
pu.mutation.SetOrganizationID(id)
|
|
return pu
|
|
}
|
|
|
|
// SetOrganization sets the "organization" edge to the Organization entity.
|
|
func (pu *PlatformUpdate) SetOrganization(o *Organization) *PlatformUpdate {
|
|
return pu.SetOrganizationID(o.ID)
|
|
}
|
|
|
|
// Mutation returns the PlatformMutation object of the builder.
|
|
func (pu *PlatformUpdate) Mutation() *PlatformMutation {
|
|
return pu.mutation
|
|
}
|
|
|
|
// ClearEditor clears the "editor" edge to the User entity.
|
|
func (pu *PlatformUpdate) ClearEditor() *PlatformUpdate {
|
|
pu.mutation.ClearEditor()
|
|
return pu
|
|
}
|
|
|
|
// ClearOrganization clears the "organization" edge to the Organization entity.
|
|
func (pu *PlatformUpdate) ClearOrganization() *PlatformUpdate {
|
|
pu.mutation.ClearOrganization()
|
|
return pu
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (pu *PlatformUpdate) Save(ctx context.Context) (int, error) {
|
|
pu.defaults()
|
|
return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (pu *PlatformUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := pu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (pu *PlatformUpdate) Exec(ctx context.Context) error {
|
|
_, err := pu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (pu *PlatformUpdate) ExecX(ctx context.Context) {
|
|
if err := pu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (pu *PlatformUpdate) defaults() {
|
|
if _, ok := pu.mutation.UpdatedAt(); !ok {
|
|
v := platform.UpdateDefaultUpdatedAt()
|
|
pu.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (pu *PlatformUpdate) check() error {
|
|
if v, ok := pu.mutation.Name(); ok {
|
|
if err := platform.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Platform.name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := pu.mutation.CreatorID(); pu.mutation.CreatorCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "Platform.creator"`)
|
|
}
|
|
if _, ok := pu.mutation.EditorID(); pu.mutation.EditorCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "Platform.editor"`)
|
|
}
|
|
if _, ok := pu.mutation.OrganizationID(); pu.mutation.OrganizationCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "Platform.organization"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (pu *PlatformUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
if err := pu.check(); err != nil {
|
|
return n, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(platform.Table, platform.Columns, sqlgraph.NewFieldSpec(platform.FieldID, field.TypeUUID))
|
|
if ps := pu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := pu.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(platform.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := pu.mutation.Name(); ok {
|
|
_spec.SetField(platform.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := pu.mutation.DisplayName(); ok {
|
|
_spec.SetField(platform.FieldDisplayName, field.TypeString, value)
|
|
}
|
|
if value, ok := pu.mutation.Form(); ok {
|
|
_spec.SetField(platform.FieldForm, field.TypeJSON, value)
|
|
}
|
|
if pu.mutation.FormCleared() {
|
|
_spec.ClearField(platform.FieldForm, field.TypeJSON)
|
|
}
|
|
if value, ok := pu.mutation.Model(); ok {
|
|
_spec.SetField(platform.FieldModel, field.TypeJSON, value)
|
|
}
|
|
if pu.mutation.ModelCleared() {
|
|
_spec.ClearField(platform.FieldModel, field.TypeJSON)
|
|
}
|
|
if value, ok := pu.mutation.Cue(); ok {
|
|
_spec.SetField(platform.FieldCue, field.TypeBytes, value)
|
|
}
|
|
if pu.mutation.CueCleared() {
|
|
_spec.ClearField(platform.FieldCue, field.TypeBytes)
|
|
}
|
|
if value, ok := pu.mutation.CueDefinition(); ok {
|
|
_spec.SetField(platform.FieldCueDefinition, field.TypeString, value)
|
|
}
|
|
if pu.mutation.CueDefinitionCleared() {
|
|
_spec.ClearField(platform.FieldCueDefinition, field.TypeString)
|
|
}
|
|
if pu.mutation.EditorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: platform.EditorTable,
|
|
Columns: []string{platform.EditorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := pu.mutation.EditorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: platform.EditorTable,
|
|
Columns: []string{platform.EditorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if pu.mutation.OrganizationCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: platform.OrganizationTable,
|
|
Columns: []string{platform.OrganizationColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := pu.mutation.OrganizationIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: platform.OrganizationTable,
|
|
Columns: []string{platform.OrganizationColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
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, pu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{platform.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
pu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// PlatformUpdateOne is the builder for updating a single Platform entity.
|
|
type PlatformUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *PlatformMutation
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (puo *PlatformUpdateOne) SetUpdatedAt(t time.Time) *PlatformUpdateOne {
|
|
puo.mutation.SetUpdatedAt(t)
|
|
return puo
|
|
}
|
|
|
|
// SetUpdatedByID sets the "updated_by_id" field.
|
|
func (puo *PlatformUpdateOne) SetUpdatedByID(u uuid.UUID) *PlatformUpdateOne {
|
|
puo.mutation.SetUpdatedByID(u)
|
|
return puo
|
|
}
|
|
|
|
// SetNillableUpdatedByID sets the "updated_by_id" field if the given value is not nil.
|
|
func (puo *PlatformUpdateOne) SetNillableUpdatedByID(u *uuid.UUID) *PlatformUpdateOne {
|
|
if u != nil {
|
|
puo.SetUpdatedByID(*u)
|
|
}
|
|
return puo
|
|
}
|
|
|
|
// SetOrgID sets the "org_id" field.
|
|
func (puo *PlatformUpdateOne) SetOrgID(u uuid.UUID) *PlatformUpdateOne {
|
|
puo.mutation.SetOrgID(u)
|
|
return puo
|
|
}
|
|
|
|
// SetNillableOrgID sets the "org_id" field if the given value is not nil.
|
|
func (puo *PlatformUpdateOne) SetNillableOrgID(u *uuid.UUID) *PlatformUpdateOne {
|
|
if u != nil {
|
|
puo.SetOrgID(*u)
|
|
}
|
|
return puo
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (puo *PlatformUpdateOne) SetName(s string) *PlatformUpdateOne {
|
|
puo.mutation.SetName(s)
|
|
return puo
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (puo *PlatformUpdateOne) SetNillableName(s *string) *PlatformUpdateOne {
|
|
if s != nil {
|
|
puo.SetName(*s)
|
|
}
|
|
return puo
|
|
}
|
|
|
|
// SetDisplayName sets the "display_name" field.
|
|
func (puo *PlatformUpdateOne) SetDisplayName(s string) *PlatformUpdateOne {
|
|
puo.mutation.SetDisplayName(s)
|
|
return puo
|
|
}
|
|
|
|
// SetNillableDisplayName sets the "display_name" field if the given value is not nil.
|
|
func (puo *PlatformUpdateOne) SetNillableDisplayName(s *string) *PlatformUpdateOne {
|
|
if s != nil {
|
|
puo.SetDisplayName(*s)
|
|
}
|
|
return puo
|
|
}
|
|
|
|
// SetForm sets the "form" field.
|
|
func (puo *PlatformUpdateOne) SetForm(s *storage.Form) *PlatformUpdateOne {
|
|
puo.mutation.SetForm(s)
|
|
return puo
|
|
}
|
|
|
|
// ClearForm clears the value of the "form" field.
|
|
func (puo *PlatformUpdateOne) ClearForm() *PlatformUpdateOne {
|
|
puo.mutation.ClearForm()
|
|
return puo
|
|
}
|
|
|
|
// SetModel sets the "model" field.
|
|
func (puo *PlatformUpdateOne) SetModel(s *storage.Model) *PlatformUpdateOne {
|
|
puo.mutation.SetModel(s)
|
|
return puo
|
|
}
|
|
|
|
// ClearModel clears the value of the "model" field.
|
|
func (puo *PlatformUpdateOne) ClearModel() *PlatformUpdateOne {
|
|
puo.mutation.ClearModel()
|
|
return puo
|
|
}
|
|
|
|
// SetCue sets the "cue" field.
|
|
func (puo *PlatformUpdateOne) SetCue(b []byte) *PlatformUpdateOne {
|
|
puo.mutation.SetCue(b)
|
|
return puo
|
|
}
|
|
|
|
// ClearCue clears the value of the "cue" field.
|
|
func (puo *PlatformUpdateOne) ClearCue() *PlatformUpdateOne {
|
|
puo.mutation.ClearCue()
|
|
return puo
|
|
}
|
|
|
|
// SetCueDefinition sets the "cue_definition" field.
|
|
func (puo *PlatformUpdateOne) SetCueDefinition(s string) *PlatformUpdateOne {
|
|
puo.mutation.SetCueDefinition(s)
|
|
return puo
|
|
}
|
|
|
|
// SetNillableCueDefinition sets the "cue_definition" field if the given value is not nil.
|
|
func (puo *PlatformUpdateOne) SetNillableCueDefinition(s *string) *PlatformUpdateOne {
|
|
if s != nil {
|
|
puo.SetCueDefinition(*s)
|
|
}
|
|
return puo
|
|
}
|
|
|
|
// ClearCueDefinition clears the value of the "cue_definition" field.
|
|
func (puo *PlatformUpdateOne) ClearCueDefinition() *PlatformUpdateOne {
|
|
puo.mutation.ClearCueDefinition()
|
|
return puo
|
|
}
|
|
|
|
// SetEditorID sets the "editor" edge to the User entity by ID.
|
|
func (puo *PlatformUpdateOne) SetEditorID(id uuid.UUID) *PlatformUpdateOne {
|
|
puo.mutation.SetEditorID(id)
|
|
return puo
|
|
}
|
|
|
|
// SetEditor sets the "editor" edge to the User entity.
|
|
func (puo *PlatformUpdateOne) SetEditor(u *User) *PlatformUpdateOne {
|
|
return puo.SetEditorID(u.ID)
|
|
}
|
|
|
|
// SetOrganizationID sets the "organization" edge to the Organization entity by ID.
|
|
func (puo *PlatformUpdateOne) SetOrganizationID(id uuid.UUID) *PlatformUpdateOne {
|
|
puo.mutation.SetOrganizationID(id)
|
|
return puo
|
|
}
|
|
|
|
// SetOrganization sets the "organization" edge to the Organization entity.
|
|
func (puo *PlatformUpdateOne) SetOrganization(o *Organization) *PlatformUpdateOne {
|
|
return puo.SetOrganizationID(o.ID)
|
|
}
|
|
|
|
// Mutation returns the PlatformMutation object of the builder.
|
|
func (puo *PlatformUpdateOne) Mutation() *PlatformMutation {
|
|
return puo.mutation
|
|
}
|
|
|
|
// ClearEditor clears the "editor" edge to the User entity.
|
|
func (puo *PlatformUpdateOne) ClearEditor() *PlatformUpdateOne {
|
|
puo.mutation.ClearEditor()
|
|
return puo
|
|
}
|
|
|
|
// ClearOrganization clears the "organization" edge to the Organization entity.
|
|
func (puo *PlatformUpdateOne) ClearOrganization() *PlatformUpdateOne {
|
|
puo.mutation.ClearOrganization()
|
|
return puo
|
|
}
|
|
|
|
// Where appends a list predicates to the PlatformUpdate builder.
|
|
func (puo *PlatformUpdateOne) Where(ps ...predicate.Platform) *PlatformUpdateOne {
|
|
puo.mutation.Where(ps...)
|
|
return puo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (puo *PlatformUpdateOne) Select(field string, fields ...string) *PlatformUpdateOne {
|
|
puo.fields = append([]string{field}, fields...)
|
|
return puo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Platform entity.
|
|
func (puo *PlatformUpdateOne) Save(ctx context.Context) (*Platform, error) {
|
|
puo.defaults()
|
|
return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (puo *PlatformUpdateOne) SaveX(ctx context.Context) *Platform {
|
|
node, err := puo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (puo *PlatformUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := puo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (puo *PlatformUpdateOne) ExecX(ctx context.Context) {
|
|
if err := puo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (puo *PlatformUpdateOne) defaults() {
|
|
if _, ok := puo.mutation.UpdatedAt(); !ok {
|
|
v := platform.UpdateDefaultUpdatedAt()
|
|
puo.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (puo *PlatformUpdateOne) check() error {
|
|
if v, ok := puo.mutation.Name(); ok {
|
|
if err := platform.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Platform.name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := puo.mutation.CreatorID(); puo.mutation.CreatorCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "Platform.creator"`)
|
|
}
|
|
if _, ok := puo.mutation.EditorID(); puo.mutation.EditorCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "Platform.editor"`)
|
|
}
|
|
if _, ok := puo.mutation.OrganizationID(); puo.mutation.OrganizationCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "Platform.organization"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (puo *PlatformUpdateOne) sqlSave(ctx context.Context) (_node *Platform, err error) {
|
|
if err := puo.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(platform.Table, platform.Columns, sqlgraph.NewFieldSpec(platform.FieldID, field.TypeUUID))
|
|
id, ok := puo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Platform.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := puo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, platform.FieldID)
|
|
for _, f := range fields {
|
|
if !platform.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != platform.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := puo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := puo.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(platform.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := puo.mutation.Name(); ok {
|
|
_spec.SetField(platform.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := puo.mutation.DisplayName(); ok {
|
|
_spec.SetField(platform.FieldDisplayName, field.TypeString, value)
|
|
}
|
|
if value, ok := puo.mutation.Form(); ok {
|
|
_spec.SetField(platform.FieldForm, field.TypeJSON, value)
|
|
}
|
|
if puo.mutation.FormCleared() {
|
|
_spec.ClearField(platform.FieldForm, field.TypeJSON)
|
|
}
|
|
if value, ok := puo.mutation.Model(); ok {
|
|
_spec.SetField(platform.FieldModel, field.TypeJSON, value)
|
|
}
|
|
if puo.mutation.ModelCleared() {
|
|
_spec.ClearField(platform.FieldModel, field.TypeJSON)
|
|
}
|
|
if value, ok := puo.mutation.Cue(); ok {
|
|
_spec.SetField(platform.FieldCue, field.TypeBytes, value)
|
|
}
|
|
if puo.mutation.CueCleared() {
|
|
_spec.ClearField(platform.FieldCue, field.TypeBytes)
|
|
}
|
|
if value, ok := puo.mutation.CueDefinition(); ok {
|
|
_spec.SetField(platform.FieldCueDefinition, field.TypeString, value)
|
|
}
|
|
if puo.mutation.CueDefinitionCleared() {
|
|
_spec.ClearField(platform.FieldCueDefinition, field.TypeString)
|
|
}
|
|
if puo.mutation.EditorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: platform.EditorTable,
|
|
Columns: []string{platform.EditorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := puo.mutation.EditorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: platform.EditorTable,
|
|
Columns: []string{platform.EditorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if puo.mutation.OrganizationCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: platform.OrganizationTable,
|
|
Columns: []string{platform.OrganizationColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := puo.mutation.OrganizationIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: platform.OrganizationTable,
|
|
Columns: []string{platform.OrganizationColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &Platform{config: puo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{platform.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
puo.mutation.done = true
|
|
return _node, nil
|
|
}
|