summaryrefslogtreecommitdiff
path: root/internal/handlers/helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers/helpers.go')
-rw-r--r--internal/handlers/helpers.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/handlers/helpers.go b/internal/handlers/helpers.go
new file mode 100644
index 0000000..bc705af
--- /dev/null
+++ b/internal/handlers/helpers.go
@@ -0,0 +1,36 @@
+package handlers
+
+import "apjournal/internal/models"
+
+func (h *Handlers) fetchRecommendations(
+ username string, limit int,
+) ([]models.Action, error) {
+ actionsRes := []models.Action{}
+ acts, err := h.repo.DBActionRecommend(username)
+ if err != nil {
+ return nil, err
+ }
+ plusCounter := 0
+ minusCounter := 0
+ for _, act := range acts {
+ if act.Type == models.ActionTypePlus {
+ if plusCounter >= limit {
+ continue
+ }
+ actionsRes = append(actionsRes, act)
+ plusCounter++
+ continue
+ }
+ if minusCounter >= limit {
+ continue
+ }
+ actionsRes = append(actionsRes, act)
+ minusCounter++
+ if len(actionsRes) > limit*2 {
+ break
+ }
+ }
+ h.log.Debug("actions rec debug", "db_acts#", len(acts),
+ "res_acts#", len(actionsRes))
+ return actionsRes, nil
+}