feat(agents): align index pagination

This commit is contained in:
2026-06-06 02:47:55 +08:00
parent 0ebaa51cbd
commit d49aafd2c3
4 changed files with 42 additions and 13 deletions
+1 -3
View File
@@ -11,7 +11,6 @@ import (
"github.com/gochat/gochat/internal/repository"
"github.com/gochat/gochat/internal/service"
applogger "github.com/gochat/gochat/pkg/logger"
"github.com/gochat/gochat/pkg/pagination"
"github.com/gochat/gochat/pkg/response"
)
@@ -37,8 +36,7 @@ func (h *AgentHandler) List(c *gin.Context) {
return
}
pg := pagination.Parse(c)
agents, total, err := h.svc.List(c.Request.Context(), accountID, pg.Offset, pg.PerPage)
agents, total, err := h.svc.List(c.Request.Context(), accountID, 0, 0)
if err != nil {
applogger.L().Errorf("List agents for account %d: %v", accountID, err)
handleServiceError(c, err)
@@ -137,6 +137,29 @@ func (s *AgentHandlerTestSuite) TestListOrdersByFullName() {
assert.Equal(s.T(), "charlie", data[2]["name"])
}
func (s *AgentHandlerTestSuite) TestListIgnoresPerPageLikeChatwoot() {
for i := 0; i < 30; i++ {
req := service.CreateAgentRequest{
Email: fmt.Sprintf("full-list-%02d@test.com", i),
Name: fmt.Sprintf("Full List %02d", i),
Role: "agent",
}
w, c := s.makeRequest("POST", "/api/v1/accounts/1/agents", req, s.account.ID, s.user.ID)
s.handler.Create(c)
assert.Equal(s.T(), http.StatusOK, w.Code)
}
w, c := s.makeRequest("GET", "/api/v1/accounts/1/agents?per_page=5", nil, s.account.ID, s.user.ID)
s.handler.List(c)
assert.Equal(s.T(), http.StatusOK, w.Code)
var data []map[string]interface{}
json.Unmarshal(w.Body.Bytes(), &data)
s.Require().Len(data, 30)
assert.Equal(s.T(), "Full List 00", data[0]["name"])
assert.Equal(s.T(), "Full List 29", data[29]["name"])
}
func (s *AgentHandlerTestSuite) TestCreateAgent() {
customRoleID := uint(7)
req := service.CreateAgentRequest{