修改分页返回数据结构体

This commit is contained in:
dushixiang
2021-03-21 16:44:33 +08:00
parent 999cf52e0c
commit 1e7b3d3c0e
15 changed files with 28 additions and 22 deletions

View File

@ -16,7 +16,7 @@ func NewCommandRepository(db *gorm.DB) *CommandRepository {
return commandRepository
}
func (r CommandRepository) Find(pageIndex, pageSize int, name, content, order, field string, account model.User) (o []model.CommandVo, total int64, err error) {
func (r CommandRepository) Find(pageIndex, pageSize int, name, content, order, field string, account model.User) (o []model.CommandForPage, total int64, err error) {
db := r.DB.Table("commands").Select("commands.id,commands.name,commands.content,commands.owner,commands.created, users.nickname as owner_name,COUNT(resource_sharers.user_id) as sharer_count").Joins("left join users on commands.owner = users.id").Joins("left join resource_sharers on commands.id = resource_sharers.resource_id").Group("commands.id")
dbCounter := r.DB.Table("commands").Select("DISTINCT commands.id").Joins("left join resource_sharers on commands.id = resource_sharers.resource_id").Group("commands.id")
@ -55,7 +55,7 @@ func (r CommandRepository) Find(pageIndex, pageSize int, name, content, order, f
err = db.Order("commands." + field + " " + order).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error
if o == nil {
o = make([]model.CommandVo, 0)
o = make([]model.CommandForPage, 0)
}
return
}