From 1242be7cfec1faa6a880d625307e32a1a91937ac Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 20 May 2022 08:36:52 -0600 Subject: Implement posts index page --- srv/src/api/assets.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'srv/src/api/assets.go') diff --git a/srv/src/api/assets.go b/srv/src/api/assets.go index 7065ff6..c1cd75e 100644 --- a/srv/src/api/assets.go +++ b/srv/src/api/assets.go @@ -50,16 +50,41 @@ func resizeImage(out io.Writer, in io.Reader, maxWidth float64) error { } } +func (a *api) renderPostAssetsIndexHandler() http.Handler { + + tpl := a.mustParseBasedTpl("assets.html") + + return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + + ids, err := a.params.PostAssetStore.List() + + if err != nil { + apiutil.InternalServerError( + rw, r, fmt.Errorf("getting list of asset ids: %w", err), + ) + return + } + + tplPayload := struct { + IDs []string + }{ + IDs: ids, + } + + executeTemplate(rw, r, tpl, tplPayload) + }) +} + func (a *api) getPostAssetHandler() http.Handler { - renderHandler := a.renderPostAssetsIndexHandler() + renderIndexHandler := a.renderPostAssetsIndexHandler() return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { id := filepath.Base(r.URL.Path) if id == "/" { - renderHandler.ServeHTTP(rw, r) + renderIndexHandler.ServeHTTP(rw, r) return } -- cgit v1.2.3