From 7dc088eadfa9bdb38e0f643f2ed99c38d2ba5111 Mon Sep 17 00:00:00 2001 From: zetaloop Date: Sat, 4 Apr 2026 06:25:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20shop=5Fplayers=20=E5=85=B3=E7=B3=BB?= =?UTF-8?q?=E8=A1=A8=E4=B8=BB=E9=94=AE=E4=B8=8E=E6=A8=A1=E5=9E=8B=E5=AF=B9?= =?UTF-8?q?=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rpc/internal/logic/addShopPlayersLogic.go | 10 +-- .../rpc/internal/logic/delShopPlayersLogic.go | 11 ++- .../internal/logic/getShopPlayersByIdLogic.go | 5 +- app/shop/rpc/internal/models/client.go | 31 +------ .../rpc/internal/models/migrate/schema.go | 12 +-- app/shop/rpc/internal/models/mutation.go | 76 ++++------------- app/shop/rpc/internal/models/runtime.go | 4 +- .../rpc/internal/models/schema/shopplayers.go | 14 ++-- app/shop/rpc/internal/models/shopplayers.go | 11 +-- .../models/shopplayers/shopplayers.go | 8 -- .../rpc/internal/models/shopplayers/where.go | 45 ---------- .../rpc/internal/models/shopplayers_create.go | 22 +---- .../rpc/internal/models/shopplayers_delete.go | 3 +- .../rpc/internal/models/shopplayers_query.go | 82 +------------------ .../rpc/internal/models/shopplayers_update.go | 15 +--- app/shop/rpc/pb/shop.pb.go | 44 +++++++--- app/shop/rpc/pb/shop_grpc.pb.go | 2 +- desc/rpc/shop.proto | 6 +- 18 files changed, 91 insertions(+), 310 deletions(-) diff --git a/app/shop/rpc/internal/logic/addShopPlayersLogic.go b/app/shop/rpc/internal/logic/addShopPlayersLogic.go index 94fe641..7da9d67 100644 --- a/app/shop/rpc/internal/logic/addShopPlayersLogic.go +++ b/app/shop/rpc/internal/logic/addShopPlayersLogic.go @@ -3,7 +3,6 @@ package logic import ( "context" "errors" - "juwan-backend/app/snowflake/rpc/snowflake" "juwan-backend/app/shop/rpc/internal/svc" "juwan-backend/app/shop/rpc/pb" @@ -27,14 +26,7 @@ func NewAddShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ad // -----------------------shopPlayers----------------------- func (l *AddShopPlayersLogic) AddShopPlayers(in *pb.AddShopPlayersReq) (*pb.AddShopPlayersResp, error) { - idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{}) - if err != nil { - logx.Errorf("addPlayerServices err:%v", err) - return nil, errors.New("create player service id failed") - } - - _, err = l.svcCtx.ShopModelRW.ShopPlayers.Create(). - SetID(idResp.Id). + _, err := l.svcCtx.ShopModelRW.ShopPlayers.Create(). SetShopID(in.ShopId). SetPlayerID(in.PlayerId). SetIsPrimary(in.IsPrimary). diff --git a/app/shop/rpc/internal/logic/delShopPlayersLogic.go b/app/shop/rpc/internal/logic/delShopPlayersLogic.go index a3020f3..68bd9b6 100644 --- a/app/shop/rpc/internal/logic/delShopPlayersLogic.go +++ b/app/shop/rpc/internal/logic/delShopPlayersLogic.go @@ -3,6 +3,7 @@ package logic import ( "context" "errors" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" "juwan-backend/app/shop/rpc/internal/svc" "juwan-backend/app/shop/rpc/pb" @@ -25,11 +26,19 @@ func NewDelShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *De } func (l *DelShopPlayersLogic) DelShopPlayers(in *pb.DelShopPlayersReq) (*pb.DelShopPlayersResp, error) { - err := l.svcCtx.ShopModelRO.ShopPlayers.DeleteOneID(in.Id).Exec(l.ctx) + affected, err := l.svcCtx.ShopModelRW.ShopPlayers.Delete(). + Where( + shopplayers.ShopIDEQ(in.ShopId), + shopplayers.PlayerIDEQ(in.PlayerId), + ). + Exec(l.ctx) if err != nil { logx.Errorf("delete shop players failed, %s", err.Error()) return nil, errors.New("delete failed") } + if affected == 0 { + return nil, errors.New("delete failed") + } return &pb.DelShopPlayersResp{}, nil } diff --git a/app/shop/rpc/internal/logic/getShopPlayersByIdLogic.go b/app/shop/rpc/internal/logic/getShopPlayersByIdLogic.go index b2e2ec6..50bfc2b 100644 --- a/app/shop/rpc/internal/logic/getShopPlayersByIdLogic.go +++ b/app/shop/rpc/internal/logic/getShopPlayersByIdLogic.go @@ -26,7 +26,10 @@ func NewGetShopPlayersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) } func (l *GetShopPlayersByIdLogic) GetShopPlayersById(in *pb.GetShopPlayersByIdReq) (*pb.GetShopPlayersByIdResp, error) { - shopPlayer, err := l.svcCtx.ShopModelRO.ShopPlayers.Query().Where(shopplayers.IDEQ(in.Id)).First(l.ctx) + shopPlayer, err := l.svcCtx.ShopModelRO.ShopPlayers.Query().Where( + shopplayers.ShopIDEQ(in.ShopId), + shopplayers.PlayerIDEQ(in.PlayerId), + ).First(l.ctx) if err != nil { logx.WithContext(l.ctx).Errorf("GetShopPlayersByIdLogic err: %v", err) return nil, errors.New("get shop players by id failed") diff --git a/app/shop/rpc/internal/models/client.go b/app/shop/rpc/internal/models/client.go index 2c365ab..240c848 100644 --- a/app/shop/rpc/internal/models/client.go +++ b/app/shop/rpc/internal/models/client.go @@ -410,12 +410,6 @@ func (c *ShopPlayersClient) UpdateOne(_m *ShopPlayers) *ShopPlayersUpdateOne { return &ShopPlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } -// UpdateOneID returns an update builder for the given id. -func (c *ShopPlayersClient) UpdateOneID(id int64) *ShopPlayersUpdateOne { - mutation := newShopPlayersMutation(c.config, OpUpdateOne, withShopPlayersID(id)) - return &ShopPlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - // Delete returns a delete builder for ShopPlayers. func (c *ShopPlayersClient) Delete() *ShopPlayersDelete { mutation := newShopPlayersMutation(c.config, OpDelete) @@ -424,13 +418,10 @@ func (c *ShopPlayersClient) Delete() *ShopPlayersDelete { // DeleteOne returns a builder for deleting the given entity. func (c *ShopPlayersClient) DeleteOne(_m *ShopPlayers) *ShopPlayersDeleteOne { - return c.DeleteOneID(_m.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *ShopPlayersClient) DeleteOneID(id int64) *ShopPlayersDeleteOne { - builder := c.Delete().Where(shopplayers.ID(id)) - builder.mutation.id = &id + builder := c.Delete().Where( + shopplayers.ShopIDEQ(_m.ShopID), + shopplayers.PlayerIDEQ(_m.PlayerID), + ) builder.mutation.op = OpDeleteOne return &ShopPlayersDeleteOne{builder} } @@ -444,20 +435,6 @@ func (c *ShopPlayersClient) Query() *ShopPlayersQuery { } } -// Get returns a ShopPlayers entity by its id. -func (c *ShopPlayersClient) Get(ctx context.Context, id int64) (*ShopPlayers, error) { - return c.Query().Where(shopplayers.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *ShopPlayersClient) GetX(ctx context.Context, id int64) *ShopPlayers { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - // Hooks returns the client hooks. func (c *ShopPlayersClient) Hooks() []Hook { return c.hooks.ShopPlayers diff --git a/app/shop/rpc/internal/models/migrate/schema.go b/app/shop/rpc/internal/models/migrate/schema.go index 891e368..180c503 100644 --- a/app/shop/rpc/internal/models/migrate/schema.go +++ b/app/shop/rpc/internal/models/migrate/schema.go @@ -49,7 +49,6 @@ var ( } // ShopPlayersColumns holds the columns for the "shop_players" table. ShopPlayersColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "shop_id", Type: field.TypeInt64}, {Name: "player_id", Type: field.TypeInt64}, {Name: "is_primary", Type: field.TypeBool, Nullable: true, Default: false}, @@ -60,22 +59,17 @@ var ( ShopPlayersTable = &schema.Table{ Name: "shop_players", Columns: ShopPlayersColumns, - PrimaryKey: []*schema.Column{ShopPlayersColumns[0]}, + PrimaryKey: []*schema.Column{ShopPlayersColumns[0], ShopPlayersColumns[1]}, Indexes: []*schema.Index{ - { - Name: "shopplayers_shop_id_player_id", - Unique: true, - Columns: []*schema.Column{ShopPlayersColumns[1], ShopPlayersColumns[2]}, - }, { Name: "shopplayers_player_id", Unique: false, - Columns: []*schema.Column{ShopPlayersColumns[2]}, + Columns: []*schema.Column{ShopPlayersColumns[1]}, }, { Name: "shopplayers_shop_id_joined_at", Unique: false, - Columns: []*schema.Column{ShopPlayersColumns[1], ShopPlayersColumns[4]}, + Columns: []*schema.Column{ShopPlayersColumns[0], ShopPlayersColumns[3]}, }, }, } diff --git a/app/shop/rpc/internal/models/mutation.go b/app/shop/rpc/internal/models/mutation.go index 3683ef2..b3107cb 100644 --- a/app/shop/rpc/internal/models/mutation.go +++ b/app/shop/rpc/internal/models/mutation.go @@ -764,7 +764,6 @@ type ShopPlayersMutation struct { config op Op typ string - id *int64 shop_id *int64 addshop_id *int64 player_id *int64 @@ -797,35 +796,16 @@ func newShopPlayersMutation(c config, op Op, opts ...shopplayersOption) *ShopPla return m } -// withShopPlayersID sets the ID field of the mutation. -func withShopPlayersID(id int64) shopplayersOption { - return func(m *ShopPlayersMutation) { - var ( - err error - once sync.Once - value *ShopPlayers - ) - m.oldValue = func(ctx context.Context) (*ShopPlayers, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().ShopPlayers.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - // withShopPlayers sets the old ShopPlayers of the mutation. func withShopPlayers(node *ShopPlayers) shopplayersOption { return func(m *ShopPlayersMutation) { m.oldValue = func(context.Context) (*ShopPlayers, error) { return node, nil } - m.id = &node.ID + m.predicates = append(m.predicates, + shopplayers.ShopIDEQ(node.ShopID), + shopplayers.PlayerIDEQ(node.PlayerID), + ) } } @@ -848,38 +828,12 @@ func (m ShopPlayersMutation) Tx() (*Tx, error) { return tx, nil } -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ShopPlayers entities. -func (m *ShopPlayersMutation) SetID(id int64) { - m.id = &id -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *ShopPlayersMutation) ID() (id int64, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *ShopPlayersMutation) IDs(ctx context.Context) ([]int64, error) { - switch { - case m.op.Is(OpUpdateOne | OpDeleteOne): - id, exists := m.ID() - if exists { - return []int64{id}, nil - } - fallthrough - case m.op.Is(OpUpdate | OpDelete): - return m.Client().ShopPlayers.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } + return nil, fmt.Errorf("IDs is not supported on %s operations for ShopPlayers", m.op) } // SetShopID sets the "shop_id" field. @@ -904,8 +858,8 @@ func (m *ShopPlayersMutation) OldShopID(ctx context.Context) (v int64, err error if !m.op.Is(OpUpdateOne) { return v, errors.New("OldShopID is only allowed on UpdateOne operations") } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldShopID requires an ID field in the mutation") + if m.oldValue == nil { + return v, errors.New("OldShopID requires the old ShopPlayers value in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -960,8 +914,8 @@ func (m *ShopPlayersMutation) OldPlayerID(ctx context.Context) (v int64, err err if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPlayerID is only allowed on UpdateOne operations") } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPlayerID requires an ID field in the mutation") + if m.oldValue == nil { + return v, errors.New("OldPlayerID requires the old ShopPlayers value in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1015,8 +969,8 @@ func (m *ShopPlayersMutation) OldIsPrimary(ctx context.Context) (v bool, err err if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIsPrimary is only allowed on UpdateOne operations") } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIsPrimary requires an ID field in the mutation") + if m.oldValue == nil { + return v, errors.New("OldIsPrimary requires the old ShopPlayers value in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1064,8 +1018,8 @@ func (m *ShopPlayersMutation) OldJoinedAt(ctx context.Context) (v time.Time, err if !m.op.Is(OpUpdateOne) { return v, errors.New("OldJoinedAt is only allowed on UpdateOne operations") } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldJoinedAt requires an ID field in the mutation") + if m.oldValue == nil { + return v, errors.New("OldJoinedAt requires the old ShopPlayers value in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1100,8 +1054,8 @@ func (m *ShopPlayersMutation) OldLeftAt(ctx context.Context) (v *time.Time, err if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLeftAt is only allowed on UpdateOne operations") } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldLeftAt requires an ID field in the mutation") + if m.oldValue == nil { + return v, errors.New("OldLeftAt requires the old ShopPlayers value in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { diff --git a/app/shop/rpc/internal/models/runtime.go b/app/shop/rpc/internal/models/runtime.go index a067a97..c8c700d 100644 --- a/app/shop/rpc/internal/models/runtime.go +++ b/app/shop/rpc/internal/models/runtime.go @@ -31,11 +31,11 @@ func init() { shopplayersFields := schema.ShopPlayers{}.Fields() _ = shopplayersFields // shopplayersDescIsPrimary is the schema descriptor for is_primary field. - shopplayersDescIsPrimary := shopplayersFields[3].Descriptor() + shopplayersDescIsPrimary := shopplayersFields[2].Descriptor() // shopplayers.DefaultIsPrimary holds the default value on creation for the is_primary field. shopplayers.DefaultIsPrimary = shopplayersDescIsPrimary.Default.(bool) // shopplayersDescJoinedAt is the schema descriptor for joined_at field. - shopplayersDescJoinedAt := shopplayersFields[4].Descriptor() + shopplayersDescJoinedAt := shopplayersFields[3].Descriptor() // shopplayers.DefaultJoinedAt holds the default value on creation for the joined_at field. shopplayers.DefaultJoinedAt = shopplayersDescJoinedAt.Default.(func() time.Time) shopsFields := schema.Shops{}.Fields() diff --git a/app/shop/rpc/internal/models/schema/shopplayers.go b/app/shop/rpc/internal/models/schema/shopplayers.go index af6db49..35d9477 100644 --- a/app/shop/rpc/internal/models/schema/shopplayers.go +++ b/app/shop/rpc/internal/models/schema/shopplayers.go @@ -4,6 +4,7 @@ import ( "time" "entgo.io/ent" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" ) @@ -13,10 +14,15 @@ type ShopPlayers struct { ent.Schema } +func (ShopPlayers) Annotations() []schema.Annotation { + return []schema.Annotation{ + field.ID("shop_id", "player_id"), + } +} + // Fields of the ShopPlayers. func (ShopPlayers) Fields() []ent.Field { return []ent.Field{ - field.Int64("id").Immutable().Unique(), field.Int64("shop_id"), field.Int64("player_id"), field.Bool("is_primary").Optional().Default(false), @@ -28,13 +34,7 @@ func (ShopPlayers) Fields() []ent.Field { // Indexes of the ShopPlayers. func (ShopPlayers) Indexes() []ent.Index { return []ent.Index{ - index.Fields("shop_id", "player_id").Unique(), index.Fields("player_id"), index.Fields("shop_id", "joined_at"), } } - -// Edges of the ShopPlayers. -func (ShopPlayers) Edges() []ent.Edge { - return nil -} diff --git a/app/shop/rpc/internal/models/shopplayers.go b/app/shop/rpc/internal/models/shopplayers.go index 51cee24..04c7516 100644 --- a/app/shop/rpc/internal/models/shopplayers.go +++ b/app/shop/rpc/internal/models/shopplayers.go @@ -15,8 +15,6 @@ import ( // ShopPlayers is the model entity for the ShopPlayers schema. type ShopPlayers struct { config `json:"-"` - // ID of the ent. - ID int64 `json:"id,omitempty"` // ShopID holds the value of the "shop_id" field. ShopID int64 `json:"shop_id,omitempty"` // PlayerID holds the value of the "player_id" field. @@ -37,7 +35,7 @@ func (*ShopPlayers) scanValues(columns []string) ([]any, error) { switch columns[i] { case shopplayers.FieldIsPrimary: values[i] = new(sql.NullBool) - case shopplayers.FieldID, shopplayers.FieldShopID, shopplayers.FieldPlayerID: + case shopplayers.FieldShopID, shopplayers.FieldPlayerID: values[i] = new(sql.NullInt64) case shopplayers.FieldJoinedAt, shopplayers.FieldLeftAt: values[i] = new(sql.NullTime) @@ -56,12 +54,6 @@ func (_m *ShopPlayers) assignValues(columns []string, values []any) error { } for i := range columns { switch columns[i] { - case shopplayers.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - _m.ID = int64(value.Int64) case shopplayers.FieldShopID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field shop_id", values[i]) @@ -128,7 +120,6 @@ func (_m *ShopPlayers) Unwrap() *ShopPlayers { func (_m *ShopPlayers) String() string { var builder strings.Builder builder.WriteString("ShopPlayers(") - builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString("shop_id=") builder.WriteString(fmt.Sprintf("%v", _m.ShopID)) builder.WriteString(", ") diff --git a/app/shop/rpc/internal/models/shopplayers/shopplayers.go b/app/shop/rpc/internal/models/shopplayers/shopplayers.go index 1d7eae6..425b0f5 100644 --- a/app/shop/rpc/internal/models/shopplayers/shopplayers.go +++ b/app/shop/rpc/internal/models/shopplayers/shopplayers.go @@ -11,8 +11,6 @@ import ( const ( // Label holds the string label denoting the shopplayers type in the database. Label = "shop_players" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" // FieldShopID holds the string denoting the shop_id field in the database. FieldShopID = "shop_id" // FieldPlayerID holds the string denoting the player_id field in the database. @@ -29,7 +27,6 @@ const ( // Columns holds all SQL columns for shopplayers fields. var Columns = []string{ - FieldID, FieldShopID, FieldPlayerID, FieldIsPrimary, @@ -57,11 +54,6 @@ var ( // OrderOption defines the ordering options for the ShopPlayers queries. type OrderOption func(*sql.Selector) -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - // ByShopID orders the results by the shop_id field. func ByShopID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldShopID, opts...).ToFunc() diff --git a/app/shop/rpc/internal/models/shopplayers/where.go b/app/shop/rpc/internal/models/shopplayers/where.go index 42c4523..389e55c 100644 --- a/app/shop/rpc/internal/models/shopplayers/where.go +++ b/app/shop/rpc/internal/models/shopplayers/where.go @@ -9,51 +9,6 @@ import ( "entgo.io/ent/dialect/sql" ) -// ID filters vertices based on their ID field. -func ID(id int64) predicate.ShopPlayers { - return predicate.ShopPlayers(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int64) predicate.ShopPlayers { - return predicate.ShopPlayers(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int64) predicate.ShopPlayers { - return predicate.ShopPlayers(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int64) predicate.ShopPlayers { - return predicate.ShopPlayers(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int64) predicate.ShopPlayers { - return predicate.ShopPlayers(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int64) predicate.ShopPlayers { - return predicate.ShopPlayers(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int64) predicate.ShopPlayers { - return predicate.ShopPlayers(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int64) predicate.ShopPlayers { - return predicate.ShopPlayers(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int64) predicate.ShopPlayers { - return predicate.ShopPlayers(sql.FieldLTE(FieldID, id)) -} - // ShopID applies equality check predicate on the "shop_id" field. It's identical to ShopIDEQ. func ShopID(v int64) predicate.ShopPlayers { return predicate.ShopPlayers(sql.FieldEQ(FieldShopID, v)) diff --git a/app/shop/rpc/internal/models/shopplayers_create.go b/app/shop/rpc/internal/models/shopplayers_create.go index d21016f..4dbc7f9 100644 --- a/app/shop/rpc/internal/models/shopplayers_create.go +++ b/app/shop/rpc/internal/models/shopplayers_create.go @@ -74,12 +74,6 @@ func (_c *ShopPlayersCreate) SetNillableLeftAt(v *time.Time) *ShopPlayersCreate return _c } -// SetID sets the "id" field. -func (_c *ShopPlayersCreate) SetID(v int64) *ShopPlayersCreate { - _c.mutation.SetID(v) - return _c -} - // Mutation returns the ShopPlayersMutation object of the builder. func (_c *ShopPlayersCreate) Mutation() *ShopPlayersMutation { return _c.mutation @@ -150,11 +144,6 @@ func (_c *ShopPlayersCreate) sqlSave(ctx context.Context) (*ShopPlayers, error) } return nil, err } - if _spec.ID.Value != _node.ID { - id := _spec.ID.Value.(int64) - _node.ID = int64(id) - } - _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } @@ -162,12 +151,8 @@ func (_c *ShopPlayersCreate) sqlSave(ctx context.Context) (*ShopPlayers, error) func (_c *ShopPlayersCreate) createSpec() (*ShopPlayers, *sqlgraph.CreateSpec) { var ( _node = &ShopPlayers{config: _c.config} - _spec = sqlgraph.NewCreateSpec(shopplayers.Table, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64)) + _spec = sqlgraph.NewCreateSpec(shopplayers.Table, nil) ) - if id, ok := _c.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } if value, ok := _c.mutation.ShopID(); ok { _spec.SetField(shopplayers.FieldShopID, field.TypeInt64, value) _node.ShopID = value @@ -235,11 +220,6 @@ func (_c *ShopPlayersCreateBulk) Save(ctx context.Context) ([]*ShopPlayers, erro if err != nil { return nil, err } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil && nodes[i].ID == 0 { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int64(id) - } mutation.done = true return nodes[i], nil }) diff --git a/app/shop/rpc/internal/models/shopplayers_delete.go b/app/shop/rpc/internal/models/shopplayers_delete.go index 0517b17..1f58e96 100644 --- a/app/shop/rpc/internal/models/shopplayers_delete.go +++ b/app/shop/rpc/internal/models/shopplayers_delete.go @@ -9,7 +9,6 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" ) // ShopPlayersDelete is the builder for deleting a ShopPlayers entity. @@ -40,7 +39,7 @@ func (_d *ShopPlayersDelete) ExecX(ctx context.Context) int { } func (_d *ShopPlayersDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(shopplayers.Table, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64)) + _spec := sqlgraph.NewDeleteSpec(shopplayers.Table, nil) if ps := _d.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/app/shop/rpc/internal/models/shopplayers_query.go b/app/shop/rpc/internal/models/shopplayers_query.go index caf5c4c..456ff4c 100644 --- a/app/shop/rpc/internal/models/shopplayers_query.go +++ b/app/shop/rpc/internal/models/shopplayers_query.go @@ -12,7 +12,6 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" ) // ShopPlayersQuery is the builder for querying ShopPlayers entities. @@ -80,29 +79,6 @@ func (_q *ShopPlayersQuery) FirstX(ctx context.Context) *ShopPlayers { return node } -// FirstID returns the first ShopPlayers ID from the query. -// Returns a *NotFoundError when no ShopPlayers ID was found. -func (_q *ShopPlayersQuery) FirstID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{shopplayers.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (_q *ShopPlayersQuery) FirstIDX(ctx context.Context) int64 { - id, err := _q.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - // Only returns a single ShopPlayers entity found by the query, ensuring it only returns one. // Returns a *NotSingularError when more than one ShopPlayers entity is found. // Returns a *NotFoundError when no ShopPlayers entities are found. @@ -130,34 +106,6 @@ func (_q *ShopPlayersQuery) OnlyX(ctx context.Context) *ShopPlayers { return node } -// OnlyID is like Only, but returns the only ShopPlayers ID in the query. -// Returns a *NotSingularError when more than one ShopPlayers ID is found. -// Returns a *NotFoundError when no entities are found. -func (_q *ShopPlayersQuery) OnlyID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{shopplayers.Label} - default: - err = &NotSingularError{shopplayers.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *ShopPlayersQuery) OnlyIDX(ctx context.Context) int64 { - id, err := _q.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - // All executes the query and returns a list of ShopPlayersSlice. func (_q *ShopPlayersQuery) All(ctx context.Context) ([]*ShopPlayers, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) @@ -177,27 +125,6 @@ func (_q *ShopPlayersQuery) AllX(ctx context.Context) []*ShopPlayers { return nodes } -// IDs executes the query and returns a list of ShopPlayers IDs. -func (_q *ShopPlayersQuery) IDs(ctx context.Context) (ids []int64, err error) { - if _q.ctx.Unique == nil && _q.path != nil { - _q.Unique(true) - } - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(shopplayers.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (_q *ShopPlayersQuery) IDsX(ctx context.Context) []int64 { - ids, err := _q.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - // Count returns the count of the given query. func (_q *ShopPlayersQuery) Count(ctx context.Context) (int, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) @@ -219,7 +146,7 @@ func (_q *ShopPlayersQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (_q *ShopPlayersQuery) Exist(ctx context.Context) (bool, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) - switch _, err := _q.FirstID(ctx); { + switch _, err := _q.First(ctx); { case IsNotFound(err): return false, nil case err != nil: @@ -365,7 +292,7 @@ func (_q *ShopPlayersQuery) sqlCount(ctx context.Context) (int, error) { } func (_q *ShopPlayersQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(shopplayers.Table, shopplayers.Columns, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64)) + _spec := sqlgraph.NewQuerySpec(shopplayers.Table, shopplayers.Columns, nil) _spec.From = _q.sql if unique := _q.ctx.Unique; unique != nil { _spec.Unique = *unique @@ -374,11 +301,8 @@ func (_q *ShopPlayersQuery) querySpec() *sqlgraph.QuerySpec { } if fields := _q.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, shopplayers.FieldID) for i := range fields { - if fields[i] != shopplayers.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } if ps := _q.predicates; len(ps) > 0 { diff --git a/app/shop/rpc/internal/models/shopplayers_update.go b/app/shop/rpc/internal/models/shopplayers_update.go index c2d0af2..42555ea 100644 --- a/app/shop/rpc/internal/models/shopplayers_update.go +++ b/app/shop/rpc/internal/models/shopplayers_update.go @@ -4,7 +4,6 @@ package models import ( "context" - "errors" "fmt" "juwan-backend/app/shop/rpc/internal/models/predicate" "juwan-backend/app/shop/rpc/internal/models/shopplayers" @@ -143,7 +142,7 @@ func (_u *ShopPlayersUpdate) ExecX(ctx context.Context) { } func (_u *ShopPlayersUpdate) sqlSave(ctx context.Context) (_node int, err error) { - _spec := sqlgraph.NewUpdateSpec(shopplayers.Table, shopplayers.Columns, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64)) + _spec := sqlgraph.NewUpdateSpec(shopplayers.Table, shopplayers.Columns) if ps := _u.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -323,22 +322,14 @@ func (_u *ShopPlayersUpdateOne) ExecX(ctx context.Context) { } func (_u *ShopPlayersUpdateOne) sqlSave(ctx context.Context) (_node *ShopPlayers, err error) { - _spec := sqlgraph.NewUpdateSpec(shopplayers.Table, shopplayers.Columns, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "ShopPlayers.id" for update`)} - } - _spec.Node.ID.Value = id + _spec := sqlgraph.NewUpdateSpec(shopplayers.Table, shopplayers.Columns) if fields := _u.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, shopplayers.FieldID) for _, f := range fields { if !shopplayers.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)} } - if f != shopplayers.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } + _spec.Node.Columns = append(_spec.Node.Columns, f) } } if ps := _u.mutation.predicates; len(ps) > 0 { diff --git a/app/shop/rpc/pb/shop.pb.go b/app/shop/rpc/pb/shop.pb.go index ed9a8cc..e1ed03f 100644 --- a/app/shop/rpc/pb/shop.pb.go +++ b/app/shop/rpc/pb/shop.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11 -// protoc v5.29.6 +// protoc v3.19.4 // source: shop.proto package pb @@ -993,7 +993,8 @@ func (*UpdateShopPlayersResp) Descriptor() ([]byte, []int) { type DelShopPlayersReq struct { state protoimpl.MessageState `protogen:"open.v1"` - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + ShopId int64 `protobuf:"varint,1,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,2,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -1028,9 +1029,16 @@ func (*DelShopPlayersReq) Descriptor() ([]byte, []int) { return file_shop_proto_rawDescGZIP(), []int{16} } -func (x *DelShopPlayersReq) GetId() int64 { +func (x *DelShopPlayersReq) GetShopId() int64 { if x != nil { - return x.Id + return x.ShopId + } + return 0 +} + +func (x *DelShopPlayersReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId } return 0 } @@ -1073,7 +1081,8 @@ func (*DelShopPlayersResp) Descriptor() ([]byte, []int) { type GetShopPlayersByIdReq struct { state protoimpl.MessageState `protogen:"open.v1"` - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + ShopId int64 `protobuf:"varint,1,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,2,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -1108,9 +1117,16 @@ func (*GetShopPlayersByIdReq) Descriptor() ([]byte, []int) { return file_shop_proto_rawDescGZIP(), []int{18} } -func (x *GetShopPlayersByIdReq) GetId() int64 { +func (x *GetShopPlayersByIdReq) GetShopId() int64 { if x != nil { - return x.Id + return x.ShopId + } + return 0 +} + +func (x *GetShopPlayersByIdReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId } return 0 } @@ -2346,12 +2362,14 @@ const file_shop_proto_rawDesc = "" + "\tisPrimary\x18\x03 \x01(\bR\tisPrimary\x12\x1a\n" + "\bjoinedAt\x18\x04 \x01(\x03R\bjoinedAt\x12\x16\n" + "\x06leftAt\x18\x05 \x01(\x03R\x06leftAt\"\x17\n" + - "\x15UpdateShopPlayersResp\"#\n" + - "\x11DelShopPlayersReq\x12\x0e\n" + - "\x02id\x18\x01 \x01(\x03R\x02id\"\x14\n" + - "\x12DelShopPlayersResp\"'\n" + - "\x15GetShopPlayersByIdReq\x12\x0e\n" + - "\x02id\x18\x01 \x01(\x03R\x02id\"K\n" + + "\x15UpdateShopPlayersResp\"G\n" + + "\x11DelShopPlayersReq\x12\x16\n" + + "\x06shopId\x18\x01 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x02 \x01(\x03R\bplayerId\"\x14\n" + + "\x12DelShopPlayersResp\"K\n" + + "\x15GetShopPlayersByIdReq\x12\x16\n" + + "\x06shopId\x18\x01 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x02 \x01(\x03R\bplayerId\"K\n" + "\x16GetShopPlayersByIdResp\x121\n" + "\vshopPlayers\x18\x01 \x01(\v2\x0f.pb.ShopPlayersR\vshopPlayers\"\xc6\x01\n" + "\x14SearchShopPlayersReq\x12\x12\n" + diff --git a/app/shop/rpc/pb/shop_grpc.pb.go b/app/shop/rpc/pb/shop_grpc.pb.go index acb049d..d118326 100644 --- a/app/shop/rpc/pb/shop_grpc.pb.go +++ b/app/shop/rpc/pb/shop_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.6.1 -// - protoc v5.29.6 +// - protoc v3.19.4 // source: shop.proto package pb diff --git a/desc/rpc/shop.proto b/desc/rpc/shop.proto index bee7351..d58ee3f 100644 --- a/desc/rpc/shop.proto +++ b/desc/rpc/shop.proto @@ -108,14 +108,16 @@ message UpdateShopPlayersResp { } message DelShopPlayersReq { - int64 id = 1; //id + int64 shopId = 1; //shopId + int64 playerId = 2; //playerId } message DelShopPlayersResp { } message GetShopPlayersByIdReq { - int64 id = 1; //id + int64 shopId = 1; //shopId + int64 playerId = 2; //playerId } message GetShopPlayersByIdResp {