checklogic.go 750 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. logx.Error(err)
  27. return &types.CheckResp{}, err
  28. }
  29. return &types.CheckResp{
  30. Found: resp.Found,
  31. Price: resp.Price,
  32. }, nil
  33. }