add bookstore example
This commit is contained in:
38
example/bookstore/rpc/add/internal/logic/addlogic.go
Executable file
38
example/bookstore/rpc/add/internal/logic/addlogic.go
Executable file
@@ -0,0 +1,38 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"bookstore/rpc/add/internal/svc"
|
||||
add "bookstore/rpc/add/pb"
|
||||
"bookstore/rpc/model"
|
||||
"context"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
|
||||
return &AddLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AddLogic) Add(in *add.AddReq) (*add.AddResp, error) {
|
||||
_, err := l.svcCtx.Model.Insert(model.Book{
|
||||
Book: in.Book,
|
||||
Price: in.Price,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &add.AddResp{
|
||||
Ok: true,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user