addlogic.go 681 B

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