From cd0d62791469e37a7be2315deca96b036d59d8f2 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Fri, 19 May 2023 21:54:46 +0400 Subject: [PATCH] Added mindflow DB handling. --- internal/http/handlers.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/http/handlers.go b/internal/http/handlers.go index 28ce4bc..79e5c5e 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -18,14 +18,17 @@ import ( type Handlers struct { guestbookDB guestbook.Guestbook + mindflowDB mindflow.Mindflow captchaExpire time.Duration guestbookOwner string guestbookPageSize int64 } -func NewHandlers(captchaExpire time.Duration, gbOwner string, gbPageSize int64, db guestbook.Guestbook) *Handlers { +func NewHandlers(captchaExpire time.Duration, gbOwner string, gbPageSize int64, + gdb guestbook.Guestbook, mdb mindflow.Mindflow) *Handlers { return &Handlers{ - guestbookDB: db, + guestbookDB: gdb, + mindflowDB: mdb, captchaExpire: captchaExpire, guestbookOwner: gbOwner, guestbookPageSize: gbPageSize} @@ -49,16 +52,26 @@ func (h *Handlers) Stuff(w http.ResponseWriter, r *http.Request) { } func (h *Handlers) Mindflow(w http.ResponseWriter, r *http.Request) { - posts := []mindflow.Post{ - {Category: mindflow.Category{ID: 1, Name: "Update"}, Date: time.Now(), Title: "LMAO", Body: "Testing!"}, + posts, err := h.mindflowDB.GetAll() + for _, entry := range posts { + entry.Body = strings.ReplaceAll(entry.Body, "\\n", "\n") } + if err != nil { + return + } + web.Mindflow("/ Mindflow", posts, r, w) } func (h *Handlers) MindflowAdmin(w http.ResponseWriter, r *http.Request) { - posts := []mindflow.Post{ - {Category: mindflow.Category{ID: 1, Name: "Update"}, Date: time.Now(), Title: "LMAO", Body: "Testing!"}, + posts, err := h.mindflowDB.GetAll() + for _, entry := range posts { + entry.Body = strings.ReplaceAll(entry.Body, "\\n", "\n") } + if err != nil { + return + } + web.MindflowAdmin("/ Mindflow Administration", posts, r, w) }