Add pagination support to GET /api/v1/habits endpoint

- Create pagination package with Params and Response structs
- Add FindActiveByUserIDWithPagination and CountActiveByUserID methods to HabitRepository interface
- Implement pagination in SQLite repository using LIMIT and OFFSET
- Update GetUserHabitsHandler to support optional pagination parameters
- Modify HTTP endpoint to parse 'page' and 'page_size' query params (default: page=1, page_size=50, max=100)
- Add GetUserHabitsResponse DTO with pagination metadata
- Maintain backward compatibility - endpoint works with and without pagination params
- Add comprehensive tests for pagination logic in repository, handler, and pagination package
- Update all mock repositories to implement new pagination methods
This commit is contained in:
2025-12-01 23:53:00 +01:00
parent f780c69806
commit 38e640c617
21 changed files with 774 additions and 41 deletions
@@ -1,6 +1,7 @@
package commands
import (
"apocapoc-api/internal/shared/pagination"
"context"
"testing"
@@ -229,3 +230,11 @@ func TestCreateHabitHandler_NegativeHabit(t *testing.T) {
t.Error("Expected habit ID to be returned")
}
}
func (m *mockHabitRepo) FindActiveByUserIDWithPagination(ctx context.Context, userID string, params pagination.Params) ([]*entities.Habit, error) {
return nil, nil
}
func (m *mockHabitRepo) CountActiveByUserID(ctx context.Context, userID string) (int, error) {
return 0, nil
}