feat: 初次启动
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
@@ -7,7 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
"sundynix-micro-go/app/plant/rpc/plant"
|
||||
)
|
||||
|
||||
type GetMyPlantListLogic struct {
|
||||
@@ -22,22 +21,11 @@ func NewGetMyPlantListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
||||
|
||||
func (l *GetMyPlantListLogic) GetMyPlantList(req *types.PlantListReq) (resp interface{}, err error) {
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
var plants []plantModel.SundynixMyPlant
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&plantModel.SundynixMyPlant{}).Where("user_id = ?", userId)
|
||||
if req.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+req.Name+"%")
|
||||
result, err := l.svcCtx.PlantRpc.GetPlantList(l.ctx, &plant.PlantListReq{
|
||||
UserId: userId, Current: int32(req.Current), PageSize: int32(req.PageSize), Name: req.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Offset((current - 1) * pageSize).Limit(pageSize).Order("created_at DESC").Find(&plants).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询植物列表失败")
|
||||
}
|
||||
return map[string]interface{}{"list": plants, "total": total, "current": current, "size": pageSize}, nil
|
||||
return map[string]interface{}{"list": result.List, "total": result.Total}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user