feat(消息列表): 添加消息ID字段并实现分页查询
在消息列表数据结构中添加ID字段,用于前端展示 实现分页查询功能,通过offset和limit参数控制返回结果
This commit is contained in:
parent
35257f2c0a
commit
58eac2a6c7
@ -20,6 +20,7 @@ type appMessagePageListRequest struct {
|
||||
}
|
||||
|
||||
type listMessageData struct {
|
||||
ID int32 `json:"id"` // 消息ID
|
||||
SendTime string `json:"send_time"` // 发送时间
|
||||
SenderID string `json:"sender_id"` // 发送人ID
|
||||
SenderName string `json:"sender_name"` // 发送人昵称
|
||||
@ -85,9 +86,13 @@ func (h *handler) AppMessagePageList() core.HandlerFunc {
|
||||
listQueryDB := query.Session(&gorm.Session{})
|
||||
countQueryDB := query.Session(&gorm.Session{})
|
||||
|
||||
// 计算分页偏移量
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
|
||||
resultData, err := listQueryDB.
|
||||
Order(h.readDB.AppMessageLog.SendTime.Desc()).
|
||||
Limit(100).
|
||||
Offset(offset).
|
||||
Limit(req.PageSize).
|
||||
Find()
|
||||
if err != nil {
|
||||
ctx.AbortWithError(core.Error(
|
||||
@ -115,6 +120,7 @@ func (h *handler) AppMessagePageList() core.HandlerFunc {
|
||||
|
||||
for k, v := range resultData {
|
||||
res.List[k] = listMessageData{
|
||||
ID: v.ID,
|
||||
SendTime: timeutil.FriendlyTime(v.SendTime),
|
||||
SenderID: v.SenderID,
|
||||
SenderName: v.SenderName,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user