You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
667 B
Go
40 lines
667 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
add "bookstore/rpc/add/internal/pb"
|
|
"bookstore/rpc/add/internal/svc"
|
|
"bookstore/rpc/model"
|
|
|
|
"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
|
|
}
|