45 lines
982 B
Go
45 lines
982 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
sale "lone-services/rpc/sale/pb"
|
|
"lone-services/services/sale/internal/svc"
|
|
"lone-services/services/sale/validator"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type InfoLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic {
|
|
return &InfoLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *InfoLogic) Info(in *sale.InfoReq) (*sale.Response, error) {
|
|
var req validator.InfoValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
info, err := querySaleInfo(req.Id)
|
|
if err != nil {
|
|
l.Errorf("sale info: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
if info == nil {
|
|
return failResponse(utils.ErrorNotFund), nil
|
|
}
|
|
return okResponse(info), nil
|
|
}
|