Skip to content

Commit 958347d

Browse files
committed
implement count
1 parent 3d6b966 commit 958347d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

internal/http/server/handlers/v1/feed.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/neatplex/nightel-core/internal/services/container"
77
"github.com/neatplex/nightel-core/internal/utils"
88
"net/http"
9+
"strconv"
910
)
1011

1112
func Feed(ctr *container.Container) echo.HandlerFunc {
@@ -24,7 +25,16 @@ func Feed(ctr *container.Container) echo.HandlerFunc {
2425
}
2526
}
2627

27-
stories, err := ctr.StoryService.Feed(user.ID, lastId)
28+
count := 10
29+
requestCount := ctx.QueryParams().Get("count")
30+
if requestCount != "" {
31+
parsedRequestCount, _ := strconv.Atoi(requestCount)
32+
if parsedRequestCount > 0 && parsedRequestCount < 100 {
33+
count = parsedRequestCount
34+
}
35+
}
36+
37+
stories, err := ctr.StoryService.Feed(user.ID, lastId, count)
2838
if err != nil {
2939
return err
3040
}

internal/services/story/service.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ func (s *Service) Index(userId uint64) ([]*models.Story, error) {
2929
return stories, nil
3030
}
3131

32-
func (s *Service) Feed(userId uint64, lastId uint64) ([]*models.Story, error) {
32+
func (s *Service) Feed(userId uint64, lastId uint64, count int) ([]*models.Story, error) {
3333
var stories []*models.Story
3434
r := s.database.Handler().
35-
Where("id < ? ORDER BY id DESC LIMIT 3", lastId).
35+
Where("id < ? ORDER BY id DESC LIMIT ?", lastId, count).
3636
Preload("Audio").
3737
Preload("Image").
3838
Find(&stories)

0 commit comments

Comments
 (0)