From 93a8843e2e3391459fd333aef9e5c7617608c2b3 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 18 May 2024 15:55:59 +0200 Subject: Remove most rendering related querying from go http handlers --- src/http/drafts.go | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) (limited to 'src/http/drafts.go') diff --git a/src/http/drafts.go b/src/http/drafts.go index b0550ce..8f17eec 100644 --- a/src/http/drafts.go +++ b/src/http/drafts.go @@ -5,50 +5,12 @@ import ( "net/http" "dev.mediocregopher.com/mediocre-blog.git/src/http/apiutil" - "dev.mediocregopher.com/mediocre-blog.git/src/post" ) func (a *api) manageDraftPostsHandler() http.Handler { - tpl := a.mustParseBasedTpl("draft-posts-manage.html") - const pageCount = 20 - return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - - page, err := apiutil.StrToInt(r.FormValue("p"), 0) - if err != nil { - apiutil.BadRequest( - rw, r, fmt.Errorf("invalid page number: %w", err), - ) - return - } - - posts, hasMore, err := a.params.PostDraftStore.Get(page, pageCount) - if err != nil { - apiutil.InternalServerError( - rw, r, fmt.Errorf("fetching page %d of posts: %w", page, err), - ) - return - } - - tplPayload := struct { - Posts []post.Post - PrevPage, NextPage int - }{ - Posts: posts, - PrevPage: -1, - NextPage: -1, - } - - if page > 0 { - tplPayload.PrevPage = page - 1 - } - - if hasMore { - tplPayload.NextPage = page + 1 - } - - a.executeTemplate(rw, r, tpl, tplPayload) + a.executeTemplate(rw, r, tpl, nil) }) } -- cgit v1.2.3