summaryrefslogtreecommitdiff
path: root/internal/handlers/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers/main.go')
-rw-r--r--internal/handlers/main.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/internal/handlers/main.go b/internal/handlers/main.go
index e470b49..3bb194c 100644
--- a/internal/handlers/main.go
+++ b/internal/handlers/main.go
@@ -15,6 +15,8 @@ import (
"github.com/jmoiron/sqlx"
)
+var defUS = models.UserScore{}
+
// Handlers structure
type Handlers struct {
cfg config.Config
@@ -50,21 +52,26 @@ func (h *Handlers) MainPage(w http.ResponseWriter, r *http.Request) {
abortWithError(w, err.Error())
return
}
+ // get recommendations
+ defUS.Recommendations, err = h.fetchRecommendations("", 5)
+ if err != nil {
+ panic(err)
+ }
usernameRaw := r.Context().Value("username")
h.log.Info("got mainpage request", "username", usernameRaw)
if usernameRaw == nil {
- tmpl.ExecuteTemplate(w, "main", nil)
+ tmpl.ExecuteTemplate(w, "main", defUS)
return
}
username := usernameRaw.(string)
if username == "" {
- tmpl.ExecuteTemplate(w, "main", nil)
+ tmpl.ExecuteTemplate(w, "main", defUS)
return
}
userScore, err := h.repo.DBUserScoreGet(username)
if err != nil {
h.log.Warn("got db err", "err", err)
- tmpl.ExecuteTemplate(w, "main", nil)
+ tmpl.ExecuteTemplate(w, "main", defUS)
return
}
userScore.Actions, err = h.repo.DBActionList(username)
@@ -72,6 +79,11 @@ func (h *Handlers) MainPage(w http.ResponseWriter, r *http.Request) {
abortWithError(w, err.Error())
return
}
+ userScore.Recommendations, err = h.fetchRecommendations(username, 5)
+ if err != nil {
+ abortWithError(w, err.Error())
+ return
+ }
tmpl.ExecuteTemplate(w, "main", userScore)
}