943 lines
28 KiB
Go
943 lines
28 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
|
"juwan-backend/app/shop/rpc/internal/models/schema"
|
|
"juwan-backend/app/shop/rpc/internal/models/shops"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
// ShopsUpdate is the builder for updating Shops entities.
|
|
type ShopsUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *ShopsMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the ShopsUpdate builder.
|
|
func (_u *ShopsUpdate) Where(ps ...predicate.Shops) *ShopsUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetOwnerID sets the "owner_id" field.
|
|
func (_u *ShopsUpdate) SetOwnerID(v int64) *ShopsUpdate {
|
|
_u.mutation.ResetOwnerID()
|
|
_u.mutation.SetOwnerID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableOwnerID(v *int64) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetOwnerID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddOwnerID adds value to the "owner_id" field.
|
|
func (_u *ShopsUpdate) AddOwnerID(v int64) *ShopsUpdate {
|
|
_u.mutation.AddOwnerID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *ShopsUpdate) SetName(v string) *ShopsUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableName(v *string) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBanner sets the "banner" field.
|
|
func (_u *ShopsUpdate) SetBanner(v string) *ShopsUpdate {
|
|
_u.mutation.SetBanner(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBanner sets the "banner" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableBanner(v *string) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetBanner(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearBanner clears the value of the "banner" field.
|
|
func (_u *ShopsUpdate) ClearBanner() *ShopsUpdate {
|
|
_u.mutation.ClearBanner()
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *ShopsUpdate) SetDescription(v string) *ShopsUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableDescription(v *string) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *ShopsUpdate) ClearDescription() *ShopsUpdate {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetRating sets the "rating" field.
|
|
func (_u *ShopsUpdate) SetRating(v decimal.Decimal) *ShopsUpdate {
|
|
_u.mutation.SetRating(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRating sets the "rating" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableRating(v *decimal.Decimal) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetRating(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearRating clears the value of the "rating" field.
|
|
func (_u *ShopsUpdate) ClearRating() *ShopsUpdate {
|
|
_u.mutation.ClearRating()
|
|
return _u
|
|
}
|
|
|
|
// SetTotalOrders sets the "total_orders" field.
|
|
func (_u *ShopsUpdate) SetTotalOrders(v int) *ShopsUpdate {
|
|
_u.mutation.ResetTotalOrders()
|
|
_u.mutation.SetTotalOrders(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableTotalOrders(v *int) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetTotalOrders(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddTotalOrders adds value to the "total_orders" field.
|
|
func (_u *ShopsUpdate) AddTotalOrders(v int) *ShopsUpdate {
|
|
_u.mutation.AddTotalOrders(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearTotalOrders clears the value of the "total_orders" field.
|
|
func (_u *ShopsUpdate) ClearTotalOrders() *ShopsUpdate {
|
|
_u.mutation.ClearTotalOrders()
|
|
return _u
|
|
}
|
|
|
|
// SetPlayerCount sets the "player_count" field.
|
|
func (_u *ShopsUpdate) SetPlayerCount(v int) *ShopsUpdate {
|
|
_u.mutation.ResetPlayerCount()
|
|
_u.mutation.SetPlayerCount(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePlayerCount sets the "player_count" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillablePlayerCount(v *int) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetPlayerCount(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddPlayerCount adds value to the "player_count" field.
|
|
func (_u *ShopsUpdate) AddPlayerCount(v int) *ShopsUpdate {
|
|
_u.mutation.AddPlayerCount(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearPlayerCount clears the value of the "player_count" field.
|
|
func (_u *ShopsUpdate) ClearPlayerCount() *ShopsUpdate {
|
|
_u.mutation.ClearPlayerCount()
|
|
return _u
|
|
}
|
|
|
|
// SetCommissionType sets the "commission_type" field.
|
|
func (_u *ShopsUpdate) SetCommissionType(v string) *ShopsUpdate {
|
|
_u.mutation.SetCommissionType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCommissionType sets the "commission_type" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableCommissionType(v *string) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetCommissionType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCommissionValue sets the "commission_value" field.
|
|
func (_u *ShopsUpdate) SetCommissionValue(v decimal.Decimal) *ShopsUpdate {
|
|
_u.mutation.SetCommissionValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCommissionValue sets the "commission_value" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableCommissionValue(v *decimal.Decimal) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetCommissionValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAllowMultiShop sets the "allow_multi_shop" field.
|
|
func (_u *ShopsUpdate) SetAllowMultiShop(v bool) *ShopsUpdate {
|
|
_u.mutation.SetAllowMultiShop(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAllowMultiShop sets the "allow_multi_shop" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableAllowMultiShop(v *bool) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetAllowMultiShop(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearAllowMultiShop clears the value of the "allow_multi_shop" field.
|
|
func (_u *ShopsUpdate) ClearAllowMultiShop() *ShopsUpdate {
|
|
_u.mutation.ClearAllowMultiShop()
|
|
return _u
|
|
}
|
|
|
|
// SetAllowIndependentOrders sets the "allow_independent_orders" field.
|
|
func (_u *ShopsUpdate) SetAllowIndependentOrders(v bool) *ShopsUpdate {
|
|
_u.mutation.SetAllowIndependentOrders(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAllowIndependentOrders sets the "allow_independent_orders" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableAllowIndependentOrders(v *bool) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetAllowIndependentOrders(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearAllowIndependentOrders clears the value of the "allow_independent_orders" field.
|
|
func (_u *ShopsUpdate) ClearAllowIndependentOrders() *ShopsUpdate {
|
|
_u.mutation.ClearAllowIndependentOrders()
|
|
return _u
|
|
}
|
|
|
|
// SetDispatchMode sets the "dispatch_mode" field.
|
|
func (_u *ShopsUpdate) SetDispatchMode(v string) *ShopsUpdate {
|
|
_u.mutation.SetDispatchMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDispatchMode sets the "dispatch_mode" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableDispatchMode(v *string) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetDispatchMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAnnouncements sets the "announcements" field.
|
|
func (_u *ShopsUpdate) SetAnnouncements(v schema.TextArray) *ShopsUpdate {
|
|
_u.mutation.SetAnnouncements(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
|
|
func (_u *ShopsUpdate) SetNillableAnnouncements(v *schema.TextArray) *ShopsUpdate {
|
|
if v != nil {
|
|
_u.SetAnnouncements(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearAnnouncements clears the value of the "announcements" field.
|
|
func (_u *ShopsUpdate) ClearAnnouncements() *ShopsUpdate {
|
|
_u.mutation.ClearAnnouncements()
|
|
return _u
|
|
}
|
|
|
|
// SetTemplateConfig sets the "template_config" field.
|
|
func (_u *ShopsUpdate) SetTemplateConfig(v map[string]interface{}) *ShopsUpdate {
|
|
_u.mutation.SetTemplateConfig(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearTemplateConfig clears the value of the "template_config" field.
|
|
func (_u *ShopsUpdate) ClearTemplateConfig() *ShopsUpdate {
|
|
_u.mutation.ClearTemplateConfig()
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *ShopsUpdate) SetUpdatedAt(v time.Time) *ShopsUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the ShopsMutation object of the builder.
|
|
func (_u *ShopsUpdate) Mutation() *ShopsMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *ShopsUpdate) Save(ctx context.Context) (int, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *ShopsUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *ShopsUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *ShopsUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *ShopsUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := shops.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *ShopsUpdate) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := shops.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Shops.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.CommissionType(); ok {
|
|
if err := shops.CommissionTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "commission_type", err: fmt.Errorf(`models: validator failed for field "Shops.commission_type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.DispatchMode(); ok {
|
|
if err := shops.DispatchModeValidator(v); err != nil {
|
|
return &ValidationError{Name: "dispatch_mode", err: fmt.Errorf(`models: validator failed for field "Shops.dispatch_mode": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *ShopsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(shops.Table, shops.Columns, sqlgraph.NewFieldSpec(shops.FieldID, field.TypeInt64))
|
|
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.OwnerID(); ok {
|
|
_spec.SetField(shops.FieldOwnerID, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedOwnerID(); ok {
|
|
_spec.AddField(shops.FieldOwnerID, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(shops.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Banner(); ok {
|
|
_spec.SetField(shops.FieldBanner, field.TypeString, value)
|
|
}
|
|
if _u.mutation.BannerCleared() {
|
|
_spec.ClearField(shops.FieldBanner, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(shops.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(shops.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Rating(); ok {
|
|
_spec.SetField(shops.FieldRating, field.TypeOther, value)
|
|
}
|
|
if _u.mutation.RatingCleared() {
|
|
_spec.ClearField(shops.FieldRating, field.TypeOther)
|
|
}
|
|
if value, ok := _u.mutation.TotalOrders(); ok {
|
|
_spec.SetField(shops.FieldTotalOrders, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedTotalOrders(); ok {
|
|
_spec.AddField(shops.FieldTotalOrders, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.TotalOrdersCleared() {
|
|
_spec.ClearField(shops.FieldTotalOrders, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.PlayerCount(); ok {
|
|
_spec.SetField(shops.FieldPlayerCount, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedPlayerCount(); ok {
|
|
_spec.AddField(shops.FieldPlayerCount, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.PlayerCountCleared() {
|
|
_spec.ClearField(shops.FieldPlayerCount, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.CommissionType(); ok {
|
|
_spec.SetField(shops.FieldCommissionType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CommissionValue(); ok {
|
|
_spec.SetField(shops.FieldCommissionValue, field.TypeOther, value)
|
|
}
|
|
if value, ok := _u.mutation.AllowMultiShop(); ok {
|
|
_spec.SetField(shops.FieldAllowMultiShop, field.TypeBool, value)
|
|
}
|
|
if _u.mutation.AllowMultiShopCleared() {
|
|
_spec.ClearField(shops.FieldAllowMultiShop, field.TypeBool)
|
|
}
|
|
if value, ok := _u.mutation.AllowIndependentOrders(); ok {
|
|
_spec.SetField(shops.FieldAllowIndependentOrders, field.TypeBool, value)
|
|
}
|
|
if _u.mutation.AllowIndependentOrdersCleared() {
|
|
_spec.ClearField(shops.FieldAllowIndependentOrders, field.TypeBool)
|
|
}
|
|
if value, ok := _u.mutation.DispatchMode(); ok {
|
|
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Announcements(); ok {
|
|
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
|
|
}
|
|
if _u.mutation.AnnouncementsCleared() {
|
|
_spec.ClearField(shops.FieldAnnouncements, field.TypeOther)
|
|
}
|
|
if value, ok := _u.mutation.TemplateConfig(); ok {
|
|
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.TemplateConfigCleared() {
|
|
_spec.ClearField(shops.FieldTemplateConfig, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(shops.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{shops.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// ShopsUpdateOne is the builder for updating a single Shops entity.
|
|
type ShopsUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *ShopsMutation
|
|
}
|
|
|
|
// SetOwnerID sets the "owner_id" field.
|
|
func (_u *ShopsUpdateOne) SetOwnerID(v int64) *ShopsUpdateOne {
|
|
_u.mutation.ResetOwnerID()
|
|
_u.mutation.SetOwnerID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableOwnerID(v *int64) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetOwnerID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddOwnerID adds value to the "owner_id" field.
|
|
func (_u *ShopsUpdateOne) AddOwnerID(v int64) *ShopsUpdateOne {
|
|
_u.mutation.AddOwnerID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *ShopsUpdateOne) SetName(v string) *ShopsUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableName(v *string) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBanner sets the "banner" field.
|
|
func (_u *ShopsUpdateOne) SetBanner(v string) *ShopsUpdateOne {
|
|
_u.mutation.SetBanner(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBanner sets the "banner" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableBanner(v *string) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetBanner(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearBanner clears the value of the "banner" field.
|
|
func (_u *ShopsUpdateOne) ClearBanner() *ShopsUpdateOne {
|
|
_u.mutation.ClearBanner()
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *ShopsUpdateOne) SetDescription(v string) *ShopsUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableDescription(v *string) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *ShopsUpdateOne) ClearDescription() *ShopsUpdateOne {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetRating sets the "rating" field.
|
|
func (_u *ShopsUpdateOne) SetRating(v decimal.Decimal) *ShopsUpdateOne {
|
|
_u.mutation.SetRating(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRating sets the "rating" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableRating(v *decimal.Decimal) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetRating(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearRating clears the value of the "rating" field.
|
|
func (_u *ShopsUpdateOne) ClearRating() *ShopsUpdateOne {
|
|
_u.mutation.ClearRating()
|
|
return _u
|
|
}
|
|
|
|
// SetTotalOrders sets the "total_orders" field.
|
|
func (_u *ShopsUpdateOne) SetTotalOrders(v int) *ShopsUpdateOne {
|
|
_u.mutation.ResetTotalOrders()
|
|
_u.mutation.SetTotalOrders(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableTotalOrders(v *int) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetTotalOrders(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddTotalOrders adds value to the "total_orders" field.
|
|
func (_u *ShopsUpdateOne) AddTotalOrders(v int) *ShopsUpdateOne {
|
|
_u.mutation.AddTotalOrders(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearTotalOrders clears the value of the "total_orders" field.
|
|
func (_u *ShopsUpdateOne) ClearTotalOrders() *ShopsUpdateOne {
|
|
_u.mutation.ClearTotalOrders()
|
|
return _u
|
|
}
|
|
|
|
// SetPlayerCount sets the "player_count" field.
|
|
func (_u *ShopsUpdateOne) SetPlayerCount(v int) *ShopsUpdateOne {
|
|
_u.mutation.ResetPlayerCount()
|
|
_u.mutation.SetPlayerCount(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePlayerCount sets the "player_count" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillablePlayerCount(v *int) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetPlayerCount(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddPlayerCount adds value to the "player_count" field.
|
|
func (_u *ShopsUpdateOne) AddPlayerCount(v int) *ShopsUpdateOne {
|
|
_u.mutation.AddPlayerCount(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearPlayerCount clears the value of the "player_count" field.
|
|
func (_u *ShopsUpdateOne) ClearPlayerCount() *ShopsUpdateOne {
|
|
_u.mutation.ClearPlayerCount()
|
|
return _u
|
|
}
|
|
|
|
// SetCommissionType sets the "commission_type" field.
|
|
func (_u *ShopsUpdateOne) SetCommissionType(v string) *ShopsUpdateOne {
|
|
_u.mutation.SetCommissionType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCommissionType sets the "commission_type" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableCommissionType(v *string) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetCommissionType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCommissionValue sets the "commission_value" field.
|
|
func (_u *ShopsUpdateOne) SetCommissionValue(v decimal.Decimal) *ShopsUpdateOne {
|
|
_u.mutation.SetCommissionValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCommissionValue sets the "commission_value" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableCommissionValue(v *decimal.Decimal) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetCommissionValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAllowMultiShop sets the "allow_multi_shop" field.
|
|
func (_u *ShopsUpdateOne) SetAllowMultiShop(v bool) *ShopsUpdateOne {
|
|
_u.mutation.SetAllowMultiShop(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAllowMultiShop sets the "allow_multi_shop" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableAllowMultiShop(v *bool) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetAllowMultiShop(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearAllowMultiShop clears the value of the "allow_multi_shop" field.
|
|
func (_u *ShopsUpdateOne) ClearAllowMultiShop() *ShopsUpdateOne {
|
|
_u.mutation.ClearAllowMultiShop()
|
|
return _u
|
|
}
|
|
|
|
// SetAllowIndependentOrders sets the "allow_independent_orders" field.
|
|
func (_u *ShopsUpdateOne) SetAllowIndependentOrders(v bool) *ShopsUpdateOne {
|
|
_u.mutation.SetAllowIndependentOrders(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAllowIndependentOrders sets the "allow_independent_orders" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableAllowIndependentOrders(v *bool) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetAllowIndependentOrders(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearAllowIndependentOrders clears the value of the "allow_independent_orders" field.
|
|
func (_u *ShopsUpdateOne) ClearAllowIndependentOrders() *ShopsUpdateOne {
|
|
_u.mutation.ClearAllowIndependentOrders()
|
|
return _u
|
|
}
|
|
|
|
// SetDispatchMode sets the "dispatch_mode" field.
|
|
func (_u *ShopsUpdateOne) SetDispatchMode(v string) *ShopsUpdateOne {
|
|
_u.mutation.SetDispatchMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDispatchMode sets the "dispatch_mode" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableDispatchMode(v *string) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetDispatchMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAnnouncements sets the "announcements" field.
|
|
func (_u *ShopsUpdateOne) SetAnnouncements(v schema.TextArray) *ShopsUpdateOne {
|
|
_u.mutation.SetAnnouncements(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
|
|
func (_u *ShopsUpdateOne) SetNillableAnnouncements(v *schema.TextArray) *ShopsUpdateOne {
|
|
if v != nil {
|
|
_u.SetAnnouncements(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearAnnouncements clears the value of the "announcements" field.
|
|
func (_u *ShopsUpdateOne) ClearAnnouncements() *ShopsUpdateOne {
|
|
_u.mutation.ClearAnnouncements()
|
|
return _u
|
|
}
|
|
|
|
// SetTemplateConfig sets the "template_config" field.
|
|
func (_u *ShopsUpdateOne) SetTemplateConfig(v map[string]interface{}) *ShopsUpdateOne {
|
|
_u.mutation.SetTemplateConfig(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearTemplateConfig clears the value of the "template_config" field.
|
|
func (_u *ShopsUpdateOne) ClearTemplateConfig() *ShopsUpdateOne {
|
|
_u.mutation.ClearTemplateConfig()
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *ShopsUpdateOne) SetUpdatedAt(v time.Time) *ShopsUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the ShopsMutation object of the builder.
|
|
func (_u *ShopsUpdateOne) Mutation() *ShopsMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the ShopsUpdate builder.
|
|
func (_u *ShopsUpdateOne) Where(ps ...predicate.Shops) *ShopsUpdateOne {
|
|
_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 *ShopsUpdateOne) Select(field string, fields ...string) *ShopsUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Shops entity.
|
|
func (_u *ShopsUpdateOne) Save(ctx context.Context) (*Shops, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *ShopsUpdateOne) SaveX(ctx context.Context) *Shops {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *ShopsUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *ShopsUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *ShopsUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := shops.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *ShopsUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := shops.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Shops.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.CommissionType(); ok {
|
|
if err := shops.CommissionTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "commission_type", err: fmt.Errorf(`models: validator failed for field "Shops.commission_type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.DispatchMode(); ok {
|
|
if err := shops.DispatchModeValidator(v); err != nil {
|
|
return &ValidationError{Name: "dispatch_mode", err: fmt.Errorf(`models: validator failed for field "Shops.dispatch_mode": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *ShopsUpdateOne) sqlSave(ctx context.Context) (_node *Shops, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(shops.Table, shops.Columns, sqlgraph.NewFieldSpec(shops.FieldID, field.TypeInt64))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Shops.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, shops.FieldID)
|
|
for _, f := range fields {
|
|
if !shops.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
|
}
|
|
if f != shops.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.OwnerID(); ok {
|
|
_spec.SetField(shops.FieldOwnerID, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedOwnerID(); ok {
|
|
_spec.AddField(shops.FieldOwnerID, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(shops.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Banner(); ok {
|
|
_spec.SetField(shops.FieldBanner, field.TypeString, value)
|
|
}
|
|
if _u.mutation.BannerCleared() {
|
|
_spec.ClearField(shops.FieldBanner, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(shops.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(shops.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Rating(); ok {
|
|
_spec.SetField(shops.FieldRating, field.TypeOther, value)
|
|
}
|
|
if _u.mutation.RatingCleared() {
|
|
_spec.ClearField(shops.FieldRating, field.TypeOther)
|
|
}
|
|
if value, ok := _u.mutation.TotalOrders(); ok {
|
|
_spec.SetField(shops.FieldTotalOrders, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedTotalOrders(); ok {
|
|
_spec.AddField(shops.FieldTotalOrders, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.TotalOrdersCleared() {
|
|
_spec.ClearField(shops.FieldTotalOrders, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.PlayerCount(); ok {
|
|
_spec.SetField(shops.FieldPlayerCount, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedPlayerCount(); ok {
|
|
_spec.AddField(shops.FieldPlayerCount, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.PlayerCountCleared() {
|
|
_spec.ClearField(shops.FieldPlayerCount, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.CommissionType(); ok {
|
|
_spec.SetField(shops.FieldCommissionType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CommissionValue(); ok {
|
|
_spec.SetField(shops.FieldCommissionValue, field.TypeOther, value)
|
|
}
|
|
if value, ok := _u.mutation.AllowMultiShop(); ok {
|
|
_spec.SetField(shops.FieldAllowMultiShop, field.TypeBool, value)
|
|
}
|
|
if _u.mutation.AllowMultiShopCleared() {
|
|
_spec.ClearField(shops.FieldAllowMultiShop, field.TypeBool)
|
|
}
|
|
if value, ok := _u.mutation.AllowIndependentOrders(); ok {
|
|
_spec.SetField(shops.FieldAllowIndependentOrders, field.TypeBool, value)
|
|
}
|
|
if _u.mutation.AllowIndependentOrdersCleared() {
|
|
_spec.ClearField(shops.FieldAllowIndependentOrders, field.TypeBool)
|
|
}
|
|
if value, ok := _u.mutation.DispatchMode(); ok {
|
|
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Announcements(); ok {
|
|
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
|
|
}
|
|
if _u.mutation.AnnouncementsCleared() {
|
|
_spec.ClearField(shops.FieldAnnouncements, field.TypeOther)
|
|
}
|
|
if value, ok := _u.mutation.TemplateConfig(); ok {
|
|
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.TemplateConfigCleared() {
|
|
_spec.ClearField(shops.FieldTemplateConfig, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(shops.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
_node = &Shops{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{shops.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|