Skip to content

Commit

Permalink
fix: fix message data is not fully loaded when searching (close #81)
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed May 12, 2023
1 parent 5a6f834 commit 024fc97
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions model/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ func GetMessageStatusByLink(link string) (int, error) {
}

func GetMessagesByUserId(userId int, startIdx int, num int) (messages []*Message, err error) {
err = DB.Where("user_id = ?", userId).Order("id desc").Limit(num).Offset(startIdx).Find(&messages).Error
err = DB.Select([]string{"id", "title", "channel", "timestamp", "status"}).
Where("user_id = ?", userId).Order("id desc").Limit(num).Offset(startIdx).Find(&messages).Error
return messages, err
}

func SearchMessages(keyword string) (messages []*Message, err error) {
err = DB.Select([]string{"id", "title", "description", "content"}).Where("id = ? or title LIKE ? or description LIKE ? or content LIKE ?", keyword, keyword+"%", keyword+"%", keyword+"%").Find(&messages).Error
err = DB.Select([]string{"id", "title", "channel", "timestamp", "status"}).
Where("id = ? or title LIKE ? or description LIKE ? or content LIKE ?", keyword, keyword+"%", keyword+"%", keyword+"%").
Order("id desc").
Find(&messages).Error
return messages, err
}

Expand Down

0 comments on commit 024fc97

Please sign in to comment.