change layout
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
product "lone-services/rpc/product/pb"
|
||||
"lone-services/services/product/internal/dao"
|
||||
"lone-services/services/product/internal/model"
|
||||
"lone-services/services/product/internal/svc"
|
||||
"strconv"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type NamesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewNamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NamesLogic {
|
||||
return &NamesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *NamesLogic) Names(_ *product.NamesReq) (*product.Response, error) {
|
||||
var info []dao.ProductNames
|
||||
err := model.ProductModel{}.Init().Items(modelbase.Params{
|
||||
Eq: map[string]string{"status": strconv.Itoa(int(dao.ProductStatusNormal))},
|
||||
}, &info)
|
||||
if err != nil {
|
||||
log.Errorf("product names: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
items := make([]*product.NameItem, 0, len(info))
|
||||
for _, row := range info {
|
||||
items = append(items, &product.NameItem{
|
||||
Id: int64(row.Id),
|
||||
Name: row.Name,
|
||||
})
|
||||
}
|
||||
return okResponse(utils.StructToJson(items)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user