This is an automated email from the ASF dual-hosted git repository.

kumfo pushed a commit to branch feat/1.4.0/badge
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/feat/1.4.0/badge by this push:
     new b0c76757 feat(badge): badge search with page
b0c76757 is described below

commit b0c76757cc4c85d6cf35180d3fc51b200058f5ee
Author: kumfo <[email protected]>
AuthorDate: Wed Aug 14 10:05:10 2024 +0800

    feat(badge): badge search with page
---
 internal/service/badge/badge_service.go | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/internal/service/badge/badge_service.go 
b/internal/service/badge/badge_service.go
index c9f3797a..acb68cff 100644
--- a/internal/service/badge/badge_service.go
+++ b/internal/service/badge/badge_service.go
@@ -152,6 +152,19 @@ func (b *BadgeService) ListPaged(ctx context.Context, req 
*schema.GetBadgeListPa
                        if err != nil {
                                return
                        }
+                       // paged result
+                       count := len(badges)
+                       total = int64(count)
+                       start := (req.Page - 1) * req.PageSize
+                       end := req.Page * req.PageSize
+                       if start >= count {
+                               start = count
+                               end = count
+                       }
+                       if end > count {
+                               end = count
+                       }
+                       badges = badges[start:end]
                } else {
                        req.Query = 
strings.TrimSpace(strings.TrimLeft(req.Query, "badge:"))
                        id := uid.DeShortID(req.Query)

Reply via email to