add bookstore example
This commit is contained in:
38
example/bookstore/api/internal/logic/addlogic.go
Normal file
38
example/bookstore/api/internal/logic/addlogic.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"bookstore/api/internal/svc"
|
||||
"bookstore/api/internal/types"
|
||||
"bookstore/rpc/add/adder"
|
||||
"context"
|
||||
|
||||
"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
|
||||
}
|
||||
38
example/bookstore/api/internal/logic/checklogic.go
Normal file
38
example/bookstore/api/internal/logic/checklogic.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"bookstore/api/internal/svc"
|
||||
"bookstore/api/internal/types"
|
||||
"bookstore/rpc/check/checker"
|
||||
"context"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CheckLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) CheckLogic {
|
||||
return CheckLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CheckLogic) Check(req types.CheckReq) (*types.CheckResp, error) {
|
||||
resp, err := l.svcCtx.Checker.Check(l.ctx, &checker.CheckReq{
|
||||
Book: req.Book,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.CheckResp{
|
||||
Found: resp.Found,
|
||||
Price: resp.Price,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user