1
0

Added Guestbook handler.

This commit is contained in:
Alexander Andreev 2023-02-05 21:11:29 +04:00
parent 5cd70b42bd
commit aa44e678b5
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -1,7 +1,9 @@
package http package http
import ( import (
"math"
"net/http" "net/http"
"strconv"
"strings" "strings"
"time" "time"
@ -15,7 +17,6 @@ import (
type Handlers struct { type Handlers struct {
guestbookDB *gbsqlite.SQLiteDatabase guestbookDB *gbsqlite.SQLiteDatabase
captchaExpire time.Duration captchaExpire time.Duration
databasesPath string
guestbookOwner string guestbookOwner string
guestbookPageSize int64 guestbookPageSize int64
} }
@ -86,6 +87,35 @@ func (h *Handlers) Article(w http.ResponseWriter, r *http.Request) {
web.Article(artcl.Title, artcl.Description, string(artcl.Body), artcl.Date, r.Host, name, r, w) web.Article(artcl.Title, artcl.Description, string(artcl.Body), artcl.Date, r.Host, name, r, w)
} }
func (h *Handlers) Guestbook(w http.ResponseWriter, r *http.Request) {
var page int64
var pageSize int64
pageStr := r.URL.Query().Get("p")
if pageStr != "" {
page, _ = strconv.ParseInt(pageStr, 10, 64)
} else {
page = 1
}
pageSzStr := r.URL.Query().Get("ps")
if pageSzStr != "" {
pageSize, _ = strconv.ParseInt(pageSzStr, 10, 64)
} else {
pageSize = h.guestbookPageSize
}
entries, err := h.guestbookDB.Entries(page, pageSize)
if err != nil {
return
}
entriesCount, _ := h.guestbookDB.Count()
pageCount := int64(math.Ceil(float64(entriesCount) / float64(h.guestbookPageSize)))
web.Guestbook("/ Guestbook", h.guestbookOwner, "", pageCount, entries, r, w)
}
func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) { func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) {
posts := []mindflow.Post{ posts := []mindflow.Post{
{Category: "Kek", Date: time.Now(), Title: "LMAO", Body: "Testing!"}, {Category: "Kek", Date: time.Now(), Title: "LMAO", Body: "Testing!"},