checklogic.go 649 B

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