productDetailLogic.go 994 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package product
  2. import (
  3. "context"
  4. "perms-system-server/internal/response"
  5. "perms-system-server/internal/svc"
  6. "perms-system-server/internal/types"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. type ProductDetailLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewProductDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductDetailLogic {
  15. return &ProductDetailLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. }
  20. }
  21. func (l *ProductDetailLogic) ProductDetail(req *types.ProductDetailReq) (resp *types.ProductItem, err error) {
  22. product, err := l.svcCtx.SysProductModel.FindOne(l.ctx, req.Id)
  23. if err != nil {
  24. return nil, response.ErrNotFound("产品不存在")
  25. }
  26. return &types.ProductItem{
  27. Id: product.Id,
  28. Code: product.Code,
  29. Name: product.Name,
  30. AppKey: product.AppKey,
  31. Remark: product.Remark,
  32. Status: product.Status,
  33. CreateTime: product.CreateTime,
  34. }, nil
  35. }