48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"errors"
|
|
"fusenapi/model/gmodel"
|
|
"fusenapi/utils/basic"
|
|
"gorm.io/gorm"
|
|
"net/http"
|
|
|
|
"context"
|
|
|
|
"fusenapi/server/product-templatev2/internal/svc"
|
|
"fusenapi/server/product-templatev2/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type UpdateTemplateLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewUpdateTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateTemplateLogic {
|
|
return &UpdateTemplateLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UpdateTemplateLogic) UpdateTemplate(req *types.UpdateTemplateReq, r *http.Request) (resp *basic.Response) {
|
|
authKey := r.Header.Get("Auth-Key")
|
|
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
|
_, err := genentModel.Find(l.ctx, authKey)
|
|
if err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
|
}
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
|
}
|
|
if req.ModelId <= 0 {
|
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param modelId is required")
|
|
}
|
|
return resp.SetStatus(basic.CodeOK)
|
|
}
|