fix: api descript
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/game/rpc/internal/svc"
|
||||
"juwan-backend/app/game/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateGamesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateGamesLogic {
|
||||
return &UpdateGamesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateGamesLogic) UpdateGames(in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
|
||||
update := l.svcCtx.GameModelRW.Games.UpdateOneID(in.Id)
|
||||
updated := false
|
||||
|
||||
if in.NameOpt != nil {
|
||||
update.SetNillableName(in.NameOpt)
|
||||
updated = true
|
||||
} else if in.Name != "" {
|
||||
update.SetName(in.Name)
|
||||
updated = true
|
||||
}
|
||||
|
||||
if in.IconOpt != nil {
|
||||
update.SetNillableIcon(in.IconOpt)
|
||||
updated = true
|
||||
} else if in.Icon != "" {
|
||||
update.SetIcon(in.Icon)
|
||||
updated = true
|
||||
}
|
||||
|
||||
if in.CategoryOpt != nil {
|
||||
update.SetNillableCategory(in.CategoryOpt)
|
||||
updated = true
|
||||
} else if in.Category != "" {
|
||||
update.SetCategory(in.Category)
|
||||
updated = true
|
||||
}
|
||||
|
||||
if in.SortOrderOpt != nil {
|
||||
sortOrder := int(*in.SortOrderOpt)
|
||||
update.SetNillableSortOrder(&sortOrder)
|
||||
updated = true
|
||||
} else if in.SortOrder != 0 {
|
||||
sortOrder := int(in.SortOrder)
|
||||
update.SetSortOrder(sortOrder)
|
||||
updated = true
|
||||
}
|
||||
|
||||
if in.IsActiveOpt != nil {
|
||||
update.SetNillableIsActive(in.IsActiveOpt)
|
||||
updated = true
|
||||
} else if in.IsActive {
|
||||
update.SetIsActive(true)
|
||||
updated = true
|
||||
}
|
||||
|
||||
if !updated {
|
||||
return nil, errors.New("no fields to update")
|
||||
}
|
||||
|
||||
update.SetUpdatedAt(time.Now())
|
||||
if err := update.Exec(l.ctx); err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("UpdateGamesLogic err: %v", err)
|
||||
return nil, errors.New("update games failed")
|
||||
}
|
||||
|
||||
return &pb.UpdateGamesResp{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user