123456789101112131415161718192021222324252627282930313233343536373839 |
- package logic
- import (
- "context"
- "bookstore/api/internal/svc"
- "bookstore/api/internal/types"
- "bookstore/rpc/add/adder"
- "github.com/tal-tech/go-zero/core/logx"
- )
- type AddLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) AddLogic {
- return AddLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func (l *AddLogic) Add(req types.AddReq) (*types.AddResp, error) {
- resp, err := l.svcCtx.Adder.Add(l.ctx, &adder.AddReq{
- Book: req.Book,
- Price: req.Price,
- })
- if err != nil {
- return nil, err
- }
- return &types.AddResp{
- Ok: resp.Ok,
- }, nil
- }
|