You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.0 KiB
46 lines
1.0 KiB
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"healthapi/internal/model"
|
|
"healthapi/internal/svc"
|
|
"healthapi/internal/types"
|
|
"healthapi/pkg/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetProductLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductLogic {
|
|
return &GetProductLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetProductLogic) GetProduct(req *types.IdPathReq) (resp *types.Product, err error) {
|
|
var product model.Product
|
|
if err := l.svcCtx.DB.First(&product, req.Id).Error; err != nil {
|
|
return nil, errorx.ErrNotFound
|
|
}
|
|
|
|
return &types.Product{
|
|
ID: uint(product.ID),
|
|
Name: product.Name,
|
|
Category: product.Category,
|
|
Description: product.Description,
|
|
Efficacy: product.Efficacy,
|
|
Suitable: product.Suitable,
|
|
Price: product.Price,
|
|
ImageURL: product.ImageURL,
|
|
MallURL: product.MallURL,
|
|
IsActive: product.IsActive,
|
|
}, nil
|
|
}
|
|
|