checklogic.go 717 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package logic
  2. import (
  3. "context"
  4. "bookstore/api/internal/svc"
  5. "bookstore/api/internal/types"
  6. "bookstore/rpc/check/checker"
  7. "github.com/tal-tech/go-zero/core/logx"
  8. )
  9. type CheckLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) CheckLogic {
  15. return CheckLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. }
  20. }
  21. func (l *CheckLogic) Check(req types.CheckReq) (*types.CheckResp, error) {
  22. resp, err := l.svcCtx.Checker.Check(l.ctx, &checker.CheckReq{
  23. Book: req.Book,
  24. })
  25. if err != nil {
  26. return nil, err
  27. }
  28. return &types.CheckResp{
  29. Found: resp.Found,
  30. Price: resp.Price,
  31. }, nil
  32. }