40 lines
890 B
Go
40 lines
890 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"muyu-apiserver/rpc/system/internal/svc"
|
|
"muyu-apiserver/rpc/system/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
type UpdateConfigLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewUpdateConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateConfigLogic {
|
|
return &UpdateConfigLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *UpdateConfigLogic) UpdateConfig(in *pb.UpdateConfigReq) (*pb.Empty, error) {
|
|
if in.ConfigKey == "" {
|
|
return nil, status.Error(codes.InvalidArgument, "config_key is required")
|
|
}
|
|
|
|
err := l.svcCtx.ConfigModel.UpdateByKey(l.ctx, in.ConfigKey, in.ConfigValue)
|
|
if err != nil {
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
}
|
|
|
|
return &pb.Empty{}, nil
|
|
}
|