From 60fc1773241195f4988ed8066e019bbc42267085 Mon Sep 17 00:00:00 2001 From: GrailFinder Date: Sun, 2 Jun 2024 15:00:41 +0300 Subject: Enha: add db method to list recs --- internal/handlers/auth.go | 9 +-------- internal/handlers/elements.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'internal/handlers') diff --git a/internal/handlers/auth.go b/internal/handlers/auth.go index e147efc..b470c57 100644 --- a/internal/handlers/auth.go +++ b/internal/handlers/auth.go @@ -49,7 +49,7 @@ func (h *Handlers) HandleSignup(w http.ResponseWriter, r *http.Request) { } if err := h.repo.DBUserScoreCreate(newUser); err != nil { msg := "failed to create user" - h.log.Error(msg, "user", newUser) + h.log.Error(msg, "user", newUser, "error", err) abortWithError(w, msg) return } @@ -98,13 +98,6 @@ func (h *Handlers) HandleLogin(w http.ResponseWriter, r *http.Request) { abortWithError(w, err.Error()) return } - // check password - // hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), 8) - // if err != nil { - // h.log.Warn("failed to gen pass hash", "err", err) - // abortWithError(w, err.Error()) - // return - // } if err := bcrypt.CompareHashAndPassword( []byte(userScore.Password), []byte(password), ); err != nil { diff --git a/internal/handlers/elements.go b/internal/handlers/elements.go index 965281a..7fcd9ce 100644 --- a/internal/handlers/elements.go +++ b/internal/handlers/elements.go @@ -1,6 +1,7 @@ package handlers import ( + "apjournal/internal/models" "html/template" "net/http" ) @@ -24,6 +25,20 @@ func (h *Handlers) ServeHideForm(w http.ResponseWriter, r *http.Request) { } func (h *Handlers) ShowRecommended(w http.ResponseWriter, r *http.Request) { + var username string + // TODO: getusername + // TODO: get recommendations for user + plusA, err := h.repo.DBActionRecommend(username, models.ActionTypePlus) + if err != nil { + abortWithError(w, err.Error()) + return + } + minusA, err := h.repo.DBActionRecommend(username, models.ActionTypeMinus) + if err != nil { + abortWithError(w, err.Error()) + return + } + h.log.Debug("got actions", "plus#", len(plusA), "minus#", len(minusA)) tmpl, err := template.ParseGlob("components/*.html") if err != nil { abortWithError(w, err.Error()) -- cgit v1.2.3