From 1dfda26f32857117c3c89e5772e527898807ec14 Mon Sep 17 00:00:00 2001 From: eliaskohout Date: Mon, 20 Jan 2025 20:25:48 +0000 Subject: [PATCH] rm Index.go --- src/internal/app/Index.go | 53 --------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 src/internal/app/Index.go diff --git a/src/internal/app/Index.go b/src/internal/app/Index.go deleted file mode 100644 index 777a074..0000000 --- a/src/internal/app/Index.go +++ /dev/null @@ -1,53 +0,0 @@ -package app - -import ( - "crowsnest/internal/model" - "html/template" - "net/http" - "strconv" -) - -// List the latest articles using the base template. -func (app *App) Index(w http.ResponseWriter, req *http.Request) { - const pageSize = 15 - var limit, offset, pageId uint64 = pageSize, 0, 0 - var err error - - // get page number - if pageId, err = strconv.ParseUint(req.PathValue("id"), 10, 32); err == nil { - pageId-- - offset = pageId * pageSize - } - - // get articles - articleVMs, err := app.articles.AllArticleViewModels(int(limit), int(offset)) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // get count of total articles - totalCount, err := app.articles.CountAll() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - totalCount /= pageSize - - // render template - t := template.Must(template.ParseFiles( - "assets/templates/article.html", - "assets/templates/layout.html", - "assets/templates/components/pagination.html")) - - data := map[string]interface{}{ - "SelectedNavItemArticle": true, - "ArticleVMs": &articleVMs, - "Paginations": model.NewPaginationViewModel(uint(pageId+1), totalCount+1), - } - err = t.ExecuteTemplate(w, "base", data) - if err != nil { - http.Error(w, "Failed to render template", http.StatusInternalServerError) - return - } -}