Skip to content

Commit

Permalink
fix(emojis): remove pagination when query emojis list with codes
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenHuy1812 committed Jan 4, 2024
1 parent d7d65ab commit ae91faf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
17 changes: 2 additions & 15 deletions pkg/entities/emojis.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (e *Entity) GetListEmojisByCode(req request.GetListEmojiRequest) ([]*model.
}
}

emojis, _, err := e.repo.Emojis.ListEmojis(emojis.Query{
emojis, total, err := e.repo.Emojis.ListEmojis(emojis.Query{
Codes: listCodeQuery,
})
if err != nil {
Expand Down Expand Up @@ -121,20 +121,7 @@ func (e *Entity) GetListEmojisByCode(req request.GetListEmojiRequest) ([]*model.
}
}

if req.Page >= 0 && req.Size >= 0 {
start := int(req.Page) * int(req.Size)
if start > len(emojiResponse) {
return nil, int64(len(req.ListCode)), nil
}
end := start + int(req.Size)
if end > len(emojiResponse) {
end = len(emojiResponse)
}

emojiResponse = emojiResponse[start:end]
}

return emojiResponse, int64(len(req.ListCode)), nil
return emojiResponse, total, nil
}

func (e *Entity) GetEmojiByCode(code string) (*model.EmojiData, error) {
Expand Down
22 changes: 14 additions & 8 deletions pkg/handler/emojis/emojis.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,18 @@ func (h *Handler) ListEmojis(c *gin.Context) {
return
}

c.JSON(http.StatusOK, gin.H{
"data": emojis,
"pagination": gin.H{
"total": total,
"page": req.Page,
"size": req.Size,
},
})
if req.IsQueryAll {
c.JSON(http.StatusOK, gin.H{
"data": emojis,
"pagination": gin.H{
"total": total,
"page": req.Page,
"size": req.Size,
},
})
return
}

c.JSON(http.StatusOK, gin.H{"data": emojis})

}

0 comments on commit ae91faf

Please sign in to comment.