summaryrefslogtreecommitdiff
path: root/internal/handlers/helpers.go
diff options
context:
space:
mode:
authorGrailFinder <wohilas@gmail.com>2024-06-05 08:22:36 +0300
committerGrailFinder <wohilas@gmail.com>2024-06-05 08:22:36 +0300
commit01f9a9f5d71450a0c80195058245fdebe88796bd (patch)
treefd50f3fdd0585fd1ff6cf431af613fa01b86e439 /internal/handlers/helpers.go
parent60fc1773241195f4988ed8066e019bbc42267085 (diff)
Feat: recommendations for anon and user
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
+}