tss-rocks/backend/ent/postcontributor_update.go
CDN 05ddc1f783
Some checks failed
Build Backend / Build Docker Image (push) Successful in 3m33s
Test Backend / test (push) Failing after 31s
[feature] migrate to monorepo
2025-02-21 00:49:20 +08:00

615 lines
19 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"tss-rocks-be/ent/contributor"
"tss-rocks-be/ent/contributorrole"
"tss-rocks-be/ent/post"
"tss-rocks-be/ent/postcontributor"
"tss-rocks-be/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// PostContributorUpdate is the builder for updating PostContributor entities.
type PostContributorUpdate struct {
config
hooks []Hook
mutation *PostContributorMutation
}
// Where appends a list predicates to the PostContributorUpdate builder.
func (pcu *PostContributorUpdate) Where(ps ...predicate.PostContributor) *PostContributorUpdate {
pcu.mutation.Where(ps...)
return pcu
}
// SetLanguageCode sets the "language_code" field.
func (pcu *PostContributorUpdate) SetLanguageCode(pc postcontributor.LanguageCode) *PostContributorUpdate {
pcu.mutation.SetLanguageCode(pc)
return pcu
}
// SetNillableLanguageCode sets the "language_code" field if the given value is not nil.
func (pcu *PostContributorUpdate) SetNillableLanguageCode(pc *postcontributor.LanguageCode) *PostContributorUpdate {
if pc != nil {
pcu.SetLanguageCode(*pc)
}
return pcu
}
// ClearLanguageCode clears the value of the "language_code" field.
func (pcu *PostContributorUpdate) ClearLanguageCode() *PostContributorUpdate {
pcu.mutation.ClearLanguageCode()
return pcu
}
// SetCreatedAt sets the "created_at" field.
func (pcu *PostContributorUpdate) SetCreatedAt(t time.Time) *PostContributorUpdate {
pcu.mutation.SetCreatedAt(t)
return pcu
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (pcu *PostContributorUpdate) SetNillableCreatedAt(t *time.Time) *PostContributorUpdate {
if t != nil {
pcu.SetCreatedAt(*t)
}
return pcu
}
// SetPostID sets the "post" edge to the Post entity by ID.
func (pcu *PostContributorUpdate) SetPostID(id int) *PostContributorUpdate {
pcu.mutation.SetPostID(id)
return pcu
}
// SetNillablePostID sets the "post" edge to the Post entity by ID if the given value is not nil.
func (pcu *PostContributorUpdate) SetNillablePostID(id *int) *PostContributorUpdate {
if id != nil {
pcu = pcu.SetPostID(*id)
}
return pcu
}
// SetPost sets the "post" edge to the Post entity.
func (pcu *PostContributorUpdate) SetPost(p *Post) *PostContributorUpdate {
return pcu.SetPostID(p.ID)
}
// SetContributorID sets the "contributor" edge to the Contributor entity by ID.
func (pcu *PostContributorUpdate) SetContributorID(id int) *PostContributorUpdate {
pcu.mutation.SetContributorID(id)
return pcu
}
// SetNillableContributorID sets the "contributor" edge to the Contributor entity by ID if the given value is not nil.
func (pcu *PostContributorUpdate) SetNillableContributorID(id *int) *PostContributorUpdate {
if id != nil {
pcu = pcu.SetContributorID(*id)
}
return pcu
}
// SetContributor sets the "contributor" edge to the Contributor entity.
func (pcu *PostContributorUpdate) SetContributor(c *Contributor) *PostContributorUpdate {
return pcu.SetContributorID(c.ID)
}
// SetRoleID sets the "role" edge to the ContributorRole entity by ID.
func (pcu *PostContributorUpdate) SetRoleID(id int) *PostContributorUpdate {
pcu.mutation.SetRoleID(id)
return pcu
}
// SetNillableRoleID sets the "role" edge to the ContributorRole entity by ID if the given value is not nil.
func (pcu *PostContributorUpdate) SetNillableRoleID(id *int) *PostContributorUpdate {
if id != nil {
pcu = pcu.SetRoleID(*id)
}
return pcu
}
// SetRole sets the "role" edge to the ContributorRole entity.
func (pcu *PostContributorUpdate) SetRole(c *ContributorRole) *PostContributorUpdate {
return pcu.SetRoleID(c.ID)
}
// Mutation returns the PostContributorMutation object of the builder.
func (pcu *PostContributorUpdate) Mutation() *PostContributorMutation {
return pcu.mutation
}
// ClearPost clears the "post" edge to the Post entity.
func (pcu *PostContributorUpdate) ClearPost() *PostContributorUpdate {
pcu.mutation.ClearPost()
return pcu
}
// ClearContributor clears the "contributor" edge to the Contributor entity.
func (pcu *PostContributorUpdate) ClearContributor() *PostContributorUpdate {
pcu.mutation.ClearContributor()
return pcu
}
// ClearRole clears the "role" edge to the ContributorRole entity.
func (pcu *PostContributorUpdate) ClearRole() *PostContributorUpdate {
pcu.mutation.ClearRole()
return pcu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (pcu *PostContributorUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, pcu.sqlSave, pcu.mutation, pcu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (pcu *PostContributorUpdate) SaveX(ctx context.Context) int {
affected, err := pcu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (pcu *PostContributorUpdate) Exec(ctx context.Context) error {
_, err := pcu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (pcu *PostContributorUpdate) ExecX(ctx context.Context) {
if err := pcu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (pcu *PostContributorUpdate) check() error {
if v, ok := pcu.mutation.LanguageCode(); ok {
if err := postcontributor.LanguageCodeValidator(v); err != nil {
return &ValidationError{Name: "language_code", err: fmt.Errorf(`ent: validator failed for field "PostContributor.language_code": %w`, err)}
}
}
return nil
}
func (pcu *PostContributorUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := pcu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(postcontributor.Table, postcontributor.Columns, sqlgraph.NewFieldSpec(postcontributor.FieldID, field.TypeInt))
if ps := pcu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := pcu.mutation.LanguageCode(); ok {
_spec.SetField(postcontributor.FieldLanguageCode, field.TypeEnum, value)
}
if pcu.mutation.LanguageCodeCleared() {
_spec.ClearField(postcontributor.FieldLanguageCode, field.TypeEnum)
}
if value, ok := pcu.mutation.CreatedAt(); ok {
_spec.SetField(postcontributor.FieldCreatedAt, field.TypeTime, value)
}
if pcu.mutation.PostCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.PostTable,
Columns: []string{postcontributor.PostColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pcu.mutation.PostIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.PostTable,
Columns: []string{postcontributor.PostColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if pcu.mutation.ContributorCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.ContributorTable,
Columns: []string{postcontributor.ContributorColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pcu.mutation.ContributorIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.ContributorTable,
Columns: []string{postcontributor.ContributorColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if pcu.mutation.RoleCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.RoleTable,
Columns: []string{postcontributor.RoleColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(contributorrole.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pcu.mutation.RoleIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.RoleTable,
Columns: []string{postcontributor.RoleColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(contributorrole.FieldID, field.TypeInt),
},
}
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, pcu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{postcontributor.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
pcu.mutation.done = true
return n, nil
}
// PostContributorUpdateOne is the builder for updating a single PostContributor entity.
type PostContributorUpdateOne struct {
config
fields []string
hooks []Hook
mutation *PostContributorMutation
}
// SetLanguageCode sets the "language_code" field.
func (pcuo *PostContributorUpdateOne) SetLanguageCode(pc postcontributor.LanguageCode) *PostContributorUpdateOne {
pcuo.mutation.SetLanguageCode(pc)
return pcuo
}
// SetNillableLanguageCode sets the "language_code" field if the given value is not nil.
func (pcuo *PostContributorUpdateOne) SetNillableLanguageCode(pc *postcontributor.LanguageCode) *PostContributorUpdateOne {
if pc != nil {
pcuo.SetLanguageCode(*pc)
}
return pcuo
}
// ClearLanguageCode clears the value of the "language_code" field.
func (pcuo *PostContributorUpdateOne) ClearLanguageCode() *PostContributorUpdateOne {
pcuo.mutation.ClearLanguageCode()
return pcuo
}
// SetCreatedAt sets the "created_at" field.
func (pcuo *PostContributorUpdateOne) SetCreatedAt(t time.Time) *PostContributorUpdateOne {
pcuo.mutation.SetCreatedAt(t)
return pcuo
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (pcuo *PostContributorUpdateOne) SetNillableCreatedAt(t *time.Time) *PostContributorUpdateOne {
if t != nil {
pcuo.SetCreatedAt(*t)
}
return pcuo
}
// SetPostID sets the "post" edge to the Post entity by ID.
func (pcuo *PostContributorUpdateOne) SetPostID(id int) *PostContributorUpdateOne {
pcuo.mutation.SetPostID(id)
return pcuo
}
// SetNillablePostID sets the "post" edge to the Post entity by ID if the given value is not nil.
func (pcuo *PostContributorUpdateOne) SetNillablePostID(id *int) *PostContributorUpdateOne {
if id != nil {
pcuo = pcuo.SetPostID(*id)
}
return pcuo
}
// SetPost sets the "post" edge to the Post entity.
func (pcuo *PostContributorUpdateOne) SetPost(p *Post) *PostContributorUpdateOne {
return pcuo.SetPostID(p.ID)
}
// SetContributorID sets the "contributor" edge to the Contributor entity by ID.
func (pcuo *PostContributorUpdateOne) SetContributorID(id int) *PostContributorUpdateOne {
pcuo.mutation.SetContributorID(id)
return pcuo
}
// SetNillableContributorID sets the "contributor" edge to the Contributor entity by ID if the given value is not nil.
func (pcuo *PostContributorUpdateOne) SetNillableContributorID(id *int) *PostContributorUpdateOne {
if id != nil {
pcuo = pcuo.SetContributorID(*id)
}
return pcuo
}
// SetContributor sets the "contributor" edge to the Contributor entity.
func (pcuo *PostContributorUpdateOne) SetContributor(c *Contributor) *PostContributorUpdateOne {
return pcuo.SetContributorID(c.ID)
}
// SetRoleID sets the "role" edge to the ContributorRole entity by ID.
func (pcuo *PostContributorUpdateOne) SetRoleID(id int) *PostContributorUpdateOne {
pcuo.mutation.SetRoleID(id)
return pcuo
}
// SetNillableRoleID sets the "role" edge to the ContributorRole entity by ID if the given value is not nil.
func (pcuo *PostContributorUpdateOne) SetNillableRoleID(id *int) *PostContributorUpdateOne {
if id != nil {
pcuo = pcuo.SetRoleID(*id)
}
return pcuo
}
// SetRole sets the "role" edge to the ContributorRole entity.
func (pcuo *PostContributorUpdateOne) SetRole(c *ContributorRole) *PostContributorUpdateOne {
return pcuo.SetRoleID(c.ID)
}
// Mutation returns the PostContributorMutation object of the builder.
func (pcuo *PostContributorUpdateOne) Mutation() *PostContributorMutation {
return pcuo.mutation
}
// ClearPost clears the "post" edge to the Post entity.
func (pcuo *PostContributorUpdateOne) ClearPost() *PostContributorUpdateOne {
pcuo.mutation.ClearPost()
return pcuo
}
// ClearContributor clears the "contributor" edge to the Contributor entity.
func (pcuo *PostContributorUpdateOne) ClearContributor() *PostContributorUpdateOne {
pcuo.mutation.ClearContributor()
return pcuo
}
// ClearRole clears the "role" edge to the ContributorRole entity.
func (pcuo *PostContributorUpdateOne) ClearRole() *PostContributorUpdateOne {
pcuo.mutation.ClearRole()
return pcuo
}
// Where appends a list predicates to the PostContributorUpdate builder.
func (pcuo *PostContributorUpdateOne) Where(ps ...predicate.PostContributor) *PostContributorUpdateOne {
pcuo.mutation.Where(ps...)
return pcuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (pcuo *PostContributorUpdateOne) Select(field string, fields ...string) *PostContributorUpdateOne {
pcuo.fields = append([]string{field}, fields...)
return pcuo
}
// Save executes the query and returns the updated PostContributor entity.
func (pcuo *PostContributorUpdateOne) Save(ctx context.Context) (*PostContributor, error) {
return withHooks(ctx, pcuo.sqlSave, pcuo.mutation, pcuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (pcuo *PostContributorUpdateOne) SaveX(ctx context.Context) *PostContributor {
node, err := pcuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (pcuo *PostContributorUpdateOne) Exec(ctx context.Context) error {
_, err := pcuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (pcuo *PostContributorUpdateOne) ExecX(ctx context.Context) {
if err := pcuo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (pcuo *PostContributorUpdateOne) check() error {
if v, ok := pcuo.mutation.LanguageCode(); ok {
if err := postcontributor.LanguageCodeValidator(v); err != nil {
return &ValidationError{Name: "language_code", err: fmt.Errorf(`ent: validator failed for field "PostContributor.language_code": %w`, err)}
}
}
return nil
}
func (pcuo *PostContributorUpdateOne) sqlSave(ctx context.Context) (_node *PostContributor, err error) {
if err := pcuo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(postcontributor.Table, postcontributor.Columns, sqlgraph.NewFieldSpec(postcontributor.FieldID, field.TypeInt))
id, ok := pcuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PostContributor.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := pcuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, postcontributor.FieldID)
for _, f := range fields {
if !postcontributor.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != postcontributor.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := pcuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := pcuo.mutation.LanguageCode(); ok {
_spec.SetField(postcontributor.FieldLanguageCode, field.TypeEnum, value)
}
if pcuo.mutation.LanguageCodeCleared() {
_spec.ClearField(postcontributor.FieldLanguageCode, field.TypeEnum)
}
if value, ok := pcuo.mutation.CreatedAt(); ok {
_spec.SetField(postcontributor.FieldCreatedAt, field.TypeTime, value)
}
if pcuo.mutation.PostCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.PostTable,
Columns: []string{postcontributor.PostColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pcuo.mutation.PostIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.PostTable,
Columns: []string{postcontributor.PostColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if pcuo.mutation.ContributorCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.ContributorTable,
Columns: []string{postcontributor.ContributorColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pcuo.mutation.ContributorIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.ContributorTable,
Columns: []string{postcontributor.ContributorColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if pcuo.mutation.RoleCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.RoleTable,
Columns: []string{postcontributor.RoleColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(contributorrole.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pcuo.mutation.RoleIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: postcontributor.RoleTable,
Columns: []string{postcontributor.RoleColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(contributorrole.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &PostContributor{config: pcuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, pcuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{postcontributor.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
pcuo.mutation.done = true
return _node, nil
}