65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
|
|
|
"juwan-backend/app/game/rpc/internal/svc"
|
|
"juwan-backend/app/game/rpc/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AddGamesLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewAddGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGamesLogic {
|
|
return &AddGamesLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// -----------------------games-----------------------
|
|
func (l *AddGamesLogic) AddGames(in *pb.AddGamesReq) (*pb.AddGamesResp, error) {
|
|
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
|
if err != nil {
|
|
logx.Errorf("AddGamesLogic.addGames err:%v", err)
|
|
return nil, errors.New("create game id failed")
|
|
}
|
|
_, err = l.svcCtx.GameModelRW.Games.Create().
|
|
SetID(idResp.Id).
|
|
SetName(in.Name).
|
|
SetIcon(in.Icon).
|
|
SetCategory(in.Category).
|
|
SetSortOrder(0).
|
|
Save(l.ctx)
|
|
if err != nil {
|
|
logx.Errorf("AddGamesLogic.addGames err:%v", err)
|
|
return nil, errors.New("add game failed")
|
|
}
|
|
|
|
return &pb.AddGamesResp{}, nil
|
|
}
|
|
|
|
/*
|
|
|
|
type AddGamesReq struct {
|
|
state protoimpl.MessageState `protogen:"open.v1"`
|
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` //name
|
|
Icon string `protobuf:"bytes,2,opt,name=icon,proto3" json:"icon,omitempty"` //icon
|
|
Category string `protobuf:"bytes,3,opt,name=category,proto3" json:"category,omitempty"` //category
|
|
SortOrder int64 `protobuf:"varint,4,opt,name=sortOrder,proto3" json:"sortOrder,omitempty"` //sortOrder
|
|
IsActive bool `protobuf:"varint,5,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive
|
|
CreatedAt int64 `protobuf:"varint,6,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
|
UpdatedAt int64 `protobuf:"varint,7,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
|
unknownFields protoimpl.UnknownFields
|
|
sizeCache protoimpl.SizeCache
|
|
}
|
|
*/
|