summaryrefslogtreecommitdiff
path: root/internal/handlers/elements.go
blob: 7fcd9ce831f31ee6f317b71811d06b3dde014677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package handlers

import (
	"apjournal/internal/models"
	"html/template"
	"net/http"
)

func (h *Handlers) ServeShowForm(w http.ResponseWriter, r *http.Request) {
	tmpl, err := template.ParseGlob("components/*.html")
	if err != nil {
		abortWithError(w, err.Error())
		return
	}
	tmpl.ExecuteTemplate(w, "actionform", nil)
}

func (h *Handlers) ServeHideForm(w http.ResponseWriter, r *http.Request) {
	tmpl, err := template.ParseGlob("components/*.html")
	if err != nil {
		abortWithError(w, err.Error())
		return
	}
	tmpl.ExecuteTemplate(w, "showformbtn", nil)
}

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())
		return
	}
	tmpl.ExecuteTemplate(w, "showformbtn", nil)
}

func (h *Handlers) HideRecommended(w http.ResponseWriter, r *http.Request) {
	tmpl, err := template.ParseGlob("components/*.html")
	if err != nil {
		abortWithError(w, err.Error())
		return
	}
	tmpl.ExecuteTemplate(w, "showformbtn", nil)
}