add sort by start_time when query event

This commit is contained in:
凡羊羊 2019-08-23 22:20:35 +08:00
parent 9c652698ab
commit dcb66556cc

View File

@ -135,12 +135,12 @@ func (c *EventDaoImpl) GetEventsByTarget(target, targetID string, offset, limit
db = db.Where("target=?", strings.TrimSpace(target))
}
if strings.TrimSpace(targetID) != "" {
db = db.Where("target_id=?", targetID)
db = db.Where("target_id=?", strings.TrimSpace(targetID))
}
if err := db.Order("start_time DESC").Find(&result).Count(&total).Error; err != nil {
if err := db.Find(&result).Count(&total).Error; err != nil {
return nil, 0, err
}
if err := db.Offset(offset).Limit(limit).Find(&result).Error; err != nil {
if err := db.Offset(offset).Limit(limit).Order("start_time DESC").Find(&result).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return result, 0, nil
}